Skip to content

Commit 121cf32

Browse files
committed
fix: use project ID for API calls if available
1 parent bc32806 commit 121cf32

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

lib/fail.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default async (pluginConfig, context) => {
2525
assignee,
2626
retryLimit,
2727
} = resolveConfig(pluginConfig, context);
28-
const { encodedProjectPath, projectApiUrl } = getProjectContext(context, gitlabUrl, gitlabApiUrl, repositoryUrl);
28+
const { projectId, projectApiUrl } = getProjectContext(context, gitlabUrl, gitlabApiUrl, repositoryUrl);
2929

3030
const apiOptions = {
3131
headers: { "PRIVATE-TOKEN": gitlabToken },
@@ -67,7 +67,7 @@ Using 'false' for 'failComment' or 'failTitle' is deprecated and will be removed
6767
const { id, web_url } = existingIssue;
6868
logger.log("Commented on issue #%d: %s.", id, web_url);
6969
} else {
70-
const newIssue = { id: encodedProjectPath, description, labels, title: failTitle, assignee_id: assignee };
70+
const newIssue = { id: projectId, description, labels, title: failTitle, assignee_id: assignee };
7171
debug("create issue: %O", newIssue);
7272

7373
/* eslint camelcase: off */

lib/get-project-context.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import urlJoin from "url-join";
22

33
import getProjectPath from "./get-project-path.js";
4+
import getProjectId from "./get-project-id.js";
45

56
export default (context, gitlabUrl, gitlabApiUrl, repositoryUrl) => {
7+
const projectId = getProjectId(context);
68
const projectPath = getProjectPath(context, gitlabUrl, repositoryUrl);
7-
const encodedProjectPath = encodeURIComponent(projectPath);
8-
const projectApiUrl = urlJoin(gitlabApiUrl, `/projects/${encodedProjectPath}`);
9+
const projectApiUrl = urlJoin(gitlabApiUrl, `/projects/${projectId ?? encodeURIComponent(projectPath)}`);
910
return {
11+
projectId,
1012
projectPath,
11-
encodedProjectPath,
1213
projectApiUrl,
1314
};
1415
};

lib/get-project-id.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default ({ envCi: { service } = {}, env: { CI_PROJECT_ID } }) =>
2+
service === "gitlab" && CI_PROJECT_ID
3+
? CI_PROJECT_ID
4+
: null;

0 commit comments

Comments
 (0)