Skip to content

Commit

Permalink
fix(fail): use encoded repo id to avoid error 404 (#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasSchubert committed Apr 28, 2022
1 parent b4b8e71 commit 83f3d32
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/fail.js
Expand Up @@ -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();
Expand Down
11 changes: 7 additions & 4 deletions test/fail.test.js
Expand Up @@ -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,
Expand All @@ -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:
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 83f3d32

Please sign in to comment.