From 83f3d32bf0d2a8791b5e468f48e94a13de61b18b Mon Sep 17 00:00:00 2001 From: JonasSchubert Date: Thu, 28 Apr 2022 20:27:12 +0200 Subject: [PATCH] fix(fail): use encoded repo id to avoid error 404 (#371) --- lib/fail.js | 2 +- test/fail.test.js | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/fail.js b/lib/fail.js index 38b00fd3..613892f4 100644 --- a/lib/fail.js +++ b/lib/fail.js @@ -27,7 +27,7 @@ module.exports = async (pluginConfig, context) => { const encodedFailTitle = encodeURIComponent(failTitle); const description = failComment ? template(failComment)({branch, errors}) : getFailComment(branch, errors); - const issuesEndpoint = urlJoin(gitlabApiUrl, `/projects/${repoId}/issues`); + const issuesEndpoint = urlJoin(gitlabApiUrl, `/projects/${encodedRepoId}/issues`); const openFailTitleIssueEndpoint = urlJoin(issuesEndpoint, `?state=opened&search=${encodedFailTitle}`); const openFailTitleIssues = await got(openFailTitleIssueEndpoint, {...apiOptions}).json(); diff --git a/test/fail.test.js b/test/fail.test.js index f634e88d..05f91079 100644 --- a/test/fail.test.js +++ b/test/fail.test.js @@ -26,9 +26,10 @@ test.serial('Post new issue if none exists yet', async t => { const branch = {name: 'main'}; const options = {repositoryUrl: `https://gitlab.com/${owner}/${repo}.git`}; const errors = [{message: 'An error occured'}]; + const encodedRepoId = encodeURIComponent(`${owner}/${repo}`); const encodedFailTitle = encodeURIComponent('The automated release is failing 🚨'); const gitlab = authenticate(env) - .get(`/projects/${owner}/${repo}/issues?state=opened&&search=${encodedFailTitle}`) + .get(`/projects/${encodedRepoId}/issues?state=opened&&search=${encodedFailTitle}`) .reply(200, [ { id: 2, @@ -38,7 +39,7 @@ test.serial('Post new issue if none exists yet', async t => { title: 'API should implemented authentication', }, ]) - .post(`/projects/${owner}/${repo}/issues`, { + .post(`/projects/${encodedRepoId}/issues`, { id: 'test_user%2Ftest_repo', description: `## :rotating_light: The automated release from the \`main\` branch failed. :rotating_light: @@ -86,9 +87,10 @@ test.serial('Post comments to existing issue', async t => { const branch = {name: 'main'}; const options = {repositoryUrl: `https://gitlab.com/${owner}/${repo}.git`}; const errors = [{message: 'An error occured'}]; + const encodedRepoId = encodeURIComponent(`${owner}/${repo}`); const encodedFailTitle = encodeURIComponent('The automated release is failing 🚨'); const gitlab = authenticate(env) - .get(`/projects/${owner}/${repo}/issues?state=opened&search=${encodedFailTitle}`) + .get(`/projects/${encodedRepoId}/issues?state=opened&search=${encodedFailTitle}`) .reply(200, [ { id: 1, @@ -153,9 +155,10 @@ test.serial('Post comments to existing issue with custom template', async t => { const branch = {name: 'main'}; const options = {repositoryUrl: `https://gitlab.com/${owner}/${repo}.git`}; const errors = [{message: 'An error occured'}]; + const encodedRepoId = encodeURIComponent(`${owner}/${repo}`); const encodedFailTitle = encodeURIComponent('Semantic Release Failure'); const gitlab = authenticate(env) - .get(`/projects/${owner}/${repo}/issues?state=opened&search=${encodedFailTitle}`) + .get(`/projects/${encodedRepoId}/issues?state=opened&search=${encodedFailTitle}`) .reply(200, [ { id: 1,