Skip to content

Commit 3d540ca

Browse files
committed
✨ feat: add github config
1 parent 38248eb commit 3d540ca

File tree

7 files changed

+144
-9
lines changed

7 files changed

+144
-9
lines changed

packages/release-config/src/createConfig.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { Options as SemRelOptions, PluginSpec } from 'semantic-release';
33
import type { Options } from './type';
44
import commitAnalyzer from './plugins/commitAnalyzer';
55
import git from './plugins/git';
6+
import github from './plugins/github';
67
import npm from './plugins/npm';
78

89
export type { ReleaseRule, Options } from './type';
@@ -15,6 +16,36 @@ export const createConfig = (options?: Options): SemRelOptions => {
1516
enableGithub: true,
1617
...options,
1718
};
19+
// npm config
20+
const { npmPublish, pkgRoot, tarballDir } = opts;
21+
const npmConfig = npm({ npmPublish, pkgRoot, tarballDir });
22+
23+
// github config
24+
const {
25+
githubUrl,
26+
proxy,
27+
releasedLabels,
28+
failTitle,
29+
githubApiPathPrefix,
30+
labels,
31+
failComment,
32+
assignees,
33+
addReleases,
34+
githubAssets,
35+
} = opts;
36+
const githubConfig = github({
37+
githubUrl,
38+
proxy,
39+
releasedLabels,
40+
failTitle,
41+
githubApiPathPrefix,
42+
labels,
43+
failComment,
44+
assignees,
45+
addReleases,
46+
githubAssets,
47+
});
48+
1849
const plugins: PluginSpec[] = [
1950
/* 负责解析 commit */
2051
commitAnalyzer(opts.releaseRules),
@@ -34,9 +65,9 @@ export const createConfig = (options?: Options): SemRelOptions => {
3465
},
3566
],
3667
/* 自动更新版本号 如果没有 private ,会作为 npm 模块进行发布 */
37-
opts.enableNPM ? npm(options) : '',
68+
opts.enableNPM ? npmConfig : '',
3869
/* 将生成结果发布到 Github */
39-
opts.enableGithub ? '@semantic-release/github' : '',
70+
opts.enableGithub ? githubConfig : '',
4071
/* 推送代码回到 Git */
4172
git(options),
4273
];

packages/release-config/src/plugins/git.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('git', () => {
1414
});
1515

1616
it('add new assets rules', () => {
17-
expect(git({ assets: ['file.json'] })).toEqual([
17+
expect(git({ gitAssets: ['file.json'] })).toEqual([
1818
'@semantic-release/git',
1919
{
2020
assets: ['CHANGELOG.md', 'package.json', 'file.json'],

packages/release-config/src/plugins/git.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ const git = (options: GitPluginOpts = {}): PluginSpec => {
1010
'@semantic-release/git',
1111
{
1212
assets:
13-
typeof options.assets === 'boolean'
13+
typeof options.gitAssets === 'boolean'
1414
? false
1515
: [
1616
// 这里的 assets 配置的是要重新 push 回去的东西
1717
// 如果不列的话会将全部内容都合并到 release 中
1818
'CHANGELOG.md',
1919
'package.json',
2020
]
21-
.concat(options.assets)
21+
.concat(options.gitAssets)
2222
.filter((a) => a),
2323
message: options.message
2424
? options.message
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import github from './github';
2+
3+
describe('github', () => {
4+
it('default', () => {
5+
expect(github()).toEqual('@semantic-release/github');
6+
});
7+
8+
it('add release assets', () => {
9+
expect(github({ githubAssets: ['release'] })).toEqual([
10+
'@semantic-release/github',
11+
{
12+
assets: ['release'],
13+
},
14+
]);
15+
});
16+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { PluginSpec } from 'semantic-release';
2+
import type { GithubPluginOpts } from '../type';
3+
4+
/**
5+
* github
6+
* @param options
7+
*/
8+
const github = (options: GithubPluginOpts = {}): PluginSpec => {
9+
const noOpts =
10+
options &&
11+
Object.values(options).filter((i) => typeof i !== 'undefined').length === 0;
12+
13+
if (!options || noOpts) return '@semantic-release/github';
14+
15+
const { githubAssets, ...config } = options;
16+
return [
17+
'@semantic-release/github',
18+
{
19+
assets: githubAssets,
20+
...config,
21+
},
22+
];
23+
};
24+
25+
export default github;

packages/release-config/src/plugins/npm.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const npm = (options?: NPMPluginOpts): PluginSpec => {
1010
typeof options.tarballDir === 'undefined')
1111
)
1212
return '@semantic-release/npm';
13-
const { npmPublish, pkgRoot, tarballDir } = options;
14-
return ['@semantic-release/npm', { npmPublish, pkgRoot, tarballDir }];
13+
14+
return ['@semantic-release/npm', options];
1515
};
1616

1717
export default npm;

packages/release-config/src/type.ts

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ export interface ReleaseRule {
66
release: Release['type'];
77
}
88

9-
export interface Options extends GitPluginOpts, NPMPluginOpts {
9+
export interface Options
10+
extends GitPluginOpts,
11+
NPMPluginOpts,
12+
GithubPluginOpts {
1013
releaseRules?: ReleaseRule[];
1114
changelogTitle?: string;
1215
changelogFile?: string;
@@ -33,7 +36,67 @@ export interface GitPluginOpts {
3336
* Set to `false` to disable adding files to the release commit. See [assets](#assets).
3437
* @default ['CHANGELOG.md', 'package.json']
3538
*/
36-
assets?: string[] | false;
39+
gitAssets?: string[] | false;
40+
}
41+
42+
export interface GithubPluginOpts {
43+
/**
44+
* The GitHub Enterprise endpoint.
45+
* @default `GH_URL` or `GITHUB_URL` environment variable.
46+
*/
47+
githubUrl?: string;
48+
/**
49+
* The GitHub Enterprise API prefix.
50+
* @default `GH_PREFIX` or `GITHUB_PREFIX` environment variable.
51+
*/
52+
githubApiPathPrefix?: string;
53+
/**
54+
* An array of files to upload to the release. See [assets](#assets).
55+
* @default -
56+
*/
57+
githubAssets?: string[];
58+
/**
59+
* The proxy to use to access the GitHub API. See [proxy](#proxy).
60+
* @default `HTTP_PROXY` environment variable.
61+
*/
62+
proxy?: string;
63+
/**
64+
* The comment to add to each issue and pull request resolved by the release. Set to `false` to disable commenting on issues and pull requests. See [successComment](#successcomment).
65+
* @default `:tada: This issue has been resolved in version ${nextRelease.version} :tada:\n\nThe release is available on [GitHub release](<github_release_url>)`
66+
*/
67+
successComment?: string;
68+
/**
69+
* The content of the issue created when a release fails. Set to `false` to disable opening an issue when a release fails. See [failComment](#failcomment).
70+
* Friendly message with links to **semantic-release** documentation and support, with the list of errors that caused the release to fail.
71+
*/
72+
failComment?: string;
73+
/**
74+
* The title of the issue created when a release fails. Set to `false` to disable opening an issue when a release fails.
75+
* @default `The automated release is failing 🚨`
76+
*/
77+
failTitle?: string;
78+
/**
79+
* The [labels](https://help.github.com/articles/about-labels) to add to the issue created when a release fails. Set to `false` to not add any label.
80+
* @default `['semantic-release']`
81+
*/
82+
labels?: string[];
83+
84+
/**
85+
* The [assignees](https://help.github.com/articles/assigning-issues-and-pull-requests-to-other-github-users) to add to the issue created when a release fails.
86+
*
87+
*/
88+
assignees?: string[];
89+
/**
90+
The [labels](https://help.github.com/articles/about-labels) to add to each issue and pull request resolved by the release. Set to `false` to not add any label. See [releasedLabels](#releasedlabels).
91+
* @default `['released<%= nextRelease.channel ? \` on @\${nextRelease.channel}\` : "" %>']-
92+
*/
93+
releasedLabels?: string[];
94+
95+
/**
96+
Will add release links to the GitHub Release. Can be `false`, `"bottom"` or `"top"`. See [addReleases](#addReleases).
97+
* @default `false`
98+
*/
99+
addReleases?: boolean;
37100
}
38101

39102
export interface NPMPluginOpts {

0 commit comments

Comments
 (0)