-
Notifications
You must be signed in to change notification settings - Fork 144
Expand file tree
/
Copy pathadd-channel.js
More file actions
55 lines (42 loc) · 1.61 KB
/
add-channel.js
File metadata and controls
55 lines (42 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import debugFactory from 'debug';
import {RELEASE_NAME} from './definitions/constants.js';
import parseGithubUrl from './parse-github-url.js';
import resolveConfig from './resolve-config.js';
import getClient from './get-client.js';
import isPrerelease from './is-prerelease.js';
const debug = debugFactory('semantic-release:github');
export default async function addChannel(pluginConfig, context) {
const {
options: {repositoryUrl},
branch,
nextRelease: {name, gitTag, notes},
logger,
} = context;
const {githubToken, githubUrl, githubApiPathPrefix, proxy} = resolveConfig(pluginConfig, context);
const {owner, repo} = parseGithubUrl(repositoryUrl);
const github = getClient({githubToken, githubUrl, githubApiPathPrefix, proxy});
let releaseId;
const release = {owner, repo, name, prerelease: isPrerelease(branch), tag_name: gitTag};
debug('release object: %O', release);
try {
({
data: {id: releaseId},
} = await github.repos.getReleaseByTag({owner, repo, tag: gitTag}));
} catch (error) {
if (error.status === 404) {
logger.log('There is no release for tag %s, creating a new one', gitTag);
const {
data: {html_url: url},
} = await github.repos.createRelease({...release, body: notes});
logger.log('Published GitHub release: %s', url);
return {url, name: RELEASE_NAME};
}
throw error;
}
debug('release release_id: %o', releaseId);
const {
data: {html_url: url},
} = await github.repos.updateRelease({...release, release_id: releaseId});
logger.log('Updated GitHub release: %s', url);
return {url, name: RELEASE_NAME};
}