Skip to content

Commit 3dd2907

Browse files
committed
feat: parse issue referenced with full URL
1 parent 5714da6 commit 3dd2907

File tree

3 files changed

+71
-4
lines changed

3 files changed

+71
-4
lines changed

lib/success.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const {isUndefined, uniqBy, template, flatten} = require('lodash');
22
const parseGithubUrl = require('parse-github-url');
33
const pFilter = require('p-filter');
44
const AggregateError = require('aggregate-error');
5-
const issueParser = require('issue-parser')('github');
5+
const issueParser = require('issue-parser');
66
const debug = require('debug')('semantic-release:github');
77
const resolveConfig = require('./resolve-config');
88
const getClient = require('./get-client');
@@ -17,6 +17,7 @@ module.exports = async (
1717
const {githubToken, githubUrl, githubApiPathPrefix, proxy, successComment, failTitle} = resolveConfig(pluginConfig);
1818
const {name: repo, owner} = parseGithubUrl(repositoryUrl);
1919
const github = getClient({githubToken, githubUrl, githubApiPathPrefix, proxy});
20+
const parser = issueParser('github', githubUrl ? {hosts: [githubUrl]} : {});
2021
const releaseInfos = releases.filter(release => Boolean(release.name));
2122
const shas = commits.map(commit => commit.hash);
2223
const treeShas = commits.map(commit => commit.tree.long);
@@ -37,7 +38,7 @@ module.exports = async (
3738
const issues = [...prs.map(pr => pr.body), ...commits.map(commit => commit.message)].reduce((issues, message) => {
3839
return message
3940
? issues.concat(
40-
issueParser(message)
41+
parser(message)
4142
.actions.filter(action => isUndefined(action.slug) || action.slug === `${owner}/${repo}`)
4243
.map(action => ({number: parseInt(action.issue, 10)}))
4344
)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"globby": "^8.0.0",
2626
"http-proxy-agent": "^2.1.0",
2727
"https-proxy-agent": "^2.2.1",
28-
"issue-parser": "^2.0.0",
28+
"issue-parser": "^2.2.0",
2929
"lodash": "^4.17.4",
3030
"mime": "^2.0.3",
3131
"p-filter": "^1.0.0",

test/success.test.js

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ test.serial('Add comment to PRs associated with release commits and issues close
5656
const commits = [
5757
{hash: '123', message: 'Commit 1 message\n\n Fix #1', tree: {long: 'aaa'}},
5858
{hash: '456', message: 'Commit 2 message', tree: {long: 'ccc'}},
59-
{hash: '789', message: 'Commit 3 message Closes #4', tree: {long: 'ccc'}},
59+
{hash: '789', message: `Commit 3 message Closes https://github.com/${owner}/${repo}/issues/4`, tree: {long: 'ccc'}},
6060
];
6161
const nextRelease = {version: '1.0.0'};
6262
const releases = [{name: 'GitHub release', url: 'https://github.com/release'}];
@@ -99,6 +99,72 @@ test.serial('Add comment to PRs associated with release commits and issues close
9999
t.true(github.isDone());
100100
});
101101

102+
test.serial(
103+
'Add comment to PRs associated with release commits and issues closed by PR/commits comments with custom URL',
104+
async t => {
105+
const owner = 'test_user';
106+
const repo = 'test_repo';
107+
process.env.GH_URL = 'https://custom-url.com';
108+
process.env.GH_TOKEN = 'github_token';
109+
process.env.GH_PREFIX = 'prefix';
110+
const failTitle = 'The automated release is failing 🚨';
111+
const pluginConfig = {failTitle};
112+
const prs = [
113+
{number: 1, pull_request: {}, state: 'closed'},
114+
{number: 2, pull_request: {}, body: 'Fixes #3', state: 'closed'},
115+
];
116+
const options = {branch: 'master', repositoryUrl: `https://custom-url.com/${owner}/${repo}.git`};
117+
const commits = [
118+
{hash: '123', message: 'Commit 1 message\n\n Fix #1', tree: {long: 'aaa'}},
119+
{hash: '456', message: 'Commit 2 message', tree: {long: 'ccc'}},
120+
{
121+
hash: '789',
122+
message: `Commit 3 message Closes https://custom-url.com/${owner}/${repo}/issues/4`,
123+
tree: {long: 'ccc'},
124+
},
125+
];
126+
const nextRelease = {version: '1.0.0'};
127+
const releases = [{name: 'GitHub release', url: 'https://custom-url.com/release'}];
128+
const github = authenticate()
129+
.get(
130+
`/search/issues?q=${escape(`repo:${owner}/${repo}`)}+${escape('type:pr')}+${escape('is:merged')}+${commits
131+
.map(commit => commit.hash)
132+
.join('+')}`
133+
)
134+
.reply(200, {items: prs})
135+
.get(`/repos/${owner}/${repo}/pulls/1/commits`)
136+
.reply(200, [{sha: commits[0].hash}])
137+
.get(`/repos/${owner}/${repo}/pulls/2/commits`)
138+
.reply(200, [{sha: commits[1].hash}])
139+
.post(`/repos/${owner}/${repo}/issues/1/comments`, {body: /This PR is included/})
140+
.reply(200, {html_url: 'https://custom-url.com/successcomment-1'})
141+
.post(`/repos/${owner}/${repo}/issues/2/comments`, {body: /This PR is included/})
142+
.reply(200, {html_url: 'https://custom-url.com/successcomment-2'})
143+
.get(`/repos/${owner}/${repo}/issues/3`)
144+
.reply(200, {state: 'closed'})
145+
.post(`/repos/${owner}/${repo}/issues/3/comments`, {body: /This issue has been resolved/})
146+
.reply(200, {html_url: 'https://custom-url.com/successcomment-3'})
147+
.get(`/repos/${owner}/${repo}/issues/4`)
148+
.reply(200, {state: 'closed'})
149+
.post(`/repos/${owner}/${repo}/issues/4/comments`, {body: /This issue has been resolved/})
150+
.reply(200, {html_url: 'https://custom-url.com/successcomment-4'})
151+
.get(
152+
`/search/issues?q=${escape('in:title')}+${escape(`repo:${owner}/${repo}`)}+${escape('type:issue')}+${escape(
153+
'state:open'
154+
)}+${escape(failTitle)}`
155+
)
156+
.reply(200, {items: []});
157+
158+
await success(pluginConfig, {options, commits, nextRelease, releases, logger: t.context.logger});
159+
160+
t.true(t.context.log.calledWith('Added comment to issue #%d: %s', 1, 'https://custom-url.com/successcomment-1'));
161+
t.true(t.context.log.calledWith('Added comment to issue #%d: %s', 2, 'https://custom-url.com/successcomment-2'));
162+
t.true(t.context.log.calledWith('Added comment to issue #%d: %s', 3, 'https://custom-url.com/successcomment-3'));
163+
t.true(t.context.log.calledWith('Added comment to issue #%d: %s', 4, 'https://custom-url.com/successcomment-4'));
164+
t.true(github.isDone());
165+
}
166+
);
167+
102168
test.serial('Make multiple search queries if necessary', async t => {
103169
const owner = 'test_user';
104170
const repo = 'test_repo';

0 commit comments

Comments
 (0)