Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fail): use encoded repo id to avoid error 404 #371

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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