Skip to content

Commit a1d8d9f

Browse files
committed
refactor: rename repo ID to project path for clarity
1 parent be27afe commit a1d8d9f

File tree

12 files changed

+191
-191
lines changed

12 files changed

+191
-191
lines changed

lib/definitions/errors.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@ Your configuration for the \`labels\` option is \`${stringify(labels)}\`.`,
4141
}),
4242
EINVALIDGITLABURL: () => ({
4343
message: 'The git repository URL is not a valid GitLab URL.',
44-
details: `The **semantic-release** \`repositoryUrl\` option must a valid GitLab URL with the format \`<GitLab_URL>/<repoId>.git\`.
44+
details: `The **semantic-release** \`repositoryUrl\` option must a valid GitLab URL with the format \`<GitLab_URL>/<projectPath>.git\`.
4545
4646
By default the \`repositoryUrl\` option is retrieved from the \`repository\` property of your \`package.json\` or the [git origin url](https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes) of the repository cloned by your CI environment.`,
4747
}),
48-
EINVALIDGLTOKEN: ({repoId}) => ({
48+
EINVALIDGLTOKEN: ({projectPath}) => ({
4949
message: 'Invalid GitLab token.',
5050
details: `The [GitLab token](${linkify(
5151
'README.md#gitlab-authentication'
52-
)}) configured in the \`GL_TOKEN\` or \`GITLAB_TOKEN\` environment variable must be a valid [personal access token](https://docs.gitlab.com/ce/user/profile/personal_access_tokens.html) allowing to push to the repository ${repoId}.
52+
)}) configured in the \`GL_TOKEN\` or \`GITLAB_TOKEN\` environment variable must be a valid [personal access token](https://docs.gitlab.com/ce/user/profile/personal_access_tokens.html) allowing to push to the repository ${projectPath}.
5353
5454
Please make sure to set the \`GL_TOKEN\` or \`GITLAB_TOKEN\` environment variable in your CI with the exact value of the GitLab personal token.`,
5555
}),
56-
EMISSINGREPO: ({repoId}) => ({
57-
message: `The repository ${repoId} doesn't exist.`,
56+
EMISSINGREPO: ({projectPath}) => ({
57+
message: `The repository ${projectPath} doesn't exist.`,
5858
details: `The **semantic-release** \`repositoryUrl\` option must refer to your GitLab repository. The repository must be accessible with the [GitLab API](https://docs.gitlab.com/ce/api/README.html).
5959
6060
By default the \`repositoryUrl\` option is retrieved from the \`repository\` property of your \`package.json\` or the [git origin url](https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes) of the repository cloned by your CI environment.
@@ -63,21 +63,21 @@ If you are using [GitLab Enterprise Edition](https://about.gitlab.com/gitlab-ee)
6363
'README.md#options'
6464
)}).`,
6565
}),
66-
EGLNOPUSHPERMISSION: ({repoId}) => ({
67-
message: `The GitLab token doesn't allow to push on the repository ${repoId}.`,
66+
EGLNOPUSHPERMISSION: ({projectPath}) => ({
67+
message: `The GitLab token doesn't allow to push on the repository ${projectPath}.`,
6868
details: `The user associated with the [GitLab token](${linkify(
6969
'README.md#gitlab-authentication'
70-
)}) configured in the \`GL_TOKEN\` or \`GITLAB_TOKEN\` environment variable must allows to push to the repository ${repoId}.
70+
)}) configured in the \`GL_TOKEN\` or \`GITLAB_TOKEN\` environment variable must allows to push to the repository ${projectPath}.
7171
72-
Please make sure the GitLab user associated with the token has the [permission to push](https://docs.gitlab.com/ee/user/permissions.html#project-members-permissions) to the repository ${repoId}.`,
72+
Please make sure the GitLab user associated with the token has the [permission to push](https://docs.gitlab.com/ee/user/permissions.html#project-members-permissions) to the repository ${projectPath}.`,
7373
}),
74-
EGLNOPULLPERMISSION: ({repoId}) => ({
75-
message: `The GitLab token doesn't allow to pull from the repository ${repoId}.`,
74+
EGLNOPULLPERMISSION: ({projectPath}) => ({
75+
message: `The GitLab token doesn't allow to pull from the repository ${projectPath}.`,
7676
details: `The user associated with the [GitLab token](${linkify(
7777
'README.md#gitlab-authentication'
78-
)}) configured in the \`GL_TOKEN\` or \`GITLAB_TOKEN\` environment variable must allow pull from the repository ${repoId}.
78+
)}) configured in the \`GL_TOKEN\` or \`GITLAB_TOKEN\` environment variable must allow pull from the repository ${projectPath}.
7979
80-
Please make sure the GitLab user associated with the token has the [permission to push](https://docs.gitlab.com/ee/user/permissions.html#project-members-permissions) to the repository ${repoId}.`,
80+
Please make sure the GitLab user associated with the token has the [permission to push](https://docs.gitlab.com/ee/user/permissions.html#project-members-permissions) to the repository ${projectPath}.`,
8181
}),
8282
ENOGLTOKEN: ({repositoryUrl}) => ({
8383
message: 'No GitLab token specified.',

lib/fail.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import got from "got";
44
import _debug from "debug";
55
const debug = _debug("semantic-release:gitlab");
66
import resolveConfig from "./resolve-config.js";
7-
import getRepoId from "./get-repo-id.js";
7+
import getProjectPath from "./get-project-path.js";
88
import getFailComment from "./get-fail-comment.js";
99

1010
export default async (pluginConfig, context) => {
@@ -25,8 +25,8 @@ export default async (pluginConfig, context) => {
2525
assignee,
2626
retryLimit,
2727
} = resolveConfig(pluginConfig, context);
28-
const repoId = getRepoId(context, gitlabUrl, repositoryUrl);
29-
const encodedRepoId = encodeURIComponent(repoId);
28+
const projectPath = getProjectPath(context, gitlabUrl, repositoryUrl);
29+
const encodedProjectPath = encodeURIComponent(projectPath);
3030
const apiOptions = {
3131
headers: { "PRIVATE-TOKEN": gitlabToken },
3232
retry: { limit: retryLimit },
@@ -42,7 +42,7 @@ Using 'false' for 'failComment' or 'failTitle' is deprecated and will be removed
4242
const encodedFailTitle = encodeURIComponent(failTitle);
4343
const description = failComment ? template(failComment)({ branch, errors }) : getFailComment(branch, errors);
4444

45-
const issuesEndpoint = urlJoin(gitlabApiUrl, `/projects/${encodedRepoId}/issues`);
45+
const issuesEndpoint = urlJoin(gitlabApiUrl, `/projects/${encodedProjectPath}/issues`);
4646
const openFailTitleIssueEndpoint = urlJoin(issuesEndpoint, `?state=opened&search=${encodedFailTitle}`);
4747

4848
const openFailTitleIssues = await got(openFailTitleIssueEndpoint, { ...apiOptions }).json();
@@ -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: encodedRepoId, description, labels, title: failTitle, assignee_id: assignee };
70+
const newIssue = { id: encodedProjectPath, description, labels, title: failTitle, assignee_id: assignee };
7171
debug("create issue: %O", newIssue);
7272

7373
/* eslint camelcase: off */
File renamed without changes.

lib/publish.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import got from "got";
99
import _debug from "debug";
1010
const debug = _debug("semantic-release:gitlab");
1111
import resolveConfig from "./resolve-config.js";
12-
import getRepoId from "./get-repo-id.js";
12+
import getProjectPath from "./get-project-path.js";
1313
import getAssets from "./glob-assets.js";
1414
import { RELEASE_NAME } from "./definitions/constants.js";
1515

@@ -27,8 +27,8 @@ export default async (pluginConfig, context) => {
2727
context
2828
);
2929
const assetsList = [];
30-
const repoId = getRepoId(context, gitlabUrl, repositoryUrl);
31-
const encodedRepoId = encodeURIComponent(repoId);
30+
const projectPath = getProjectPath(context, gitlabUrl, repositoryUrl);
31+
const encodedProjectPath = encodeURIComponent(projectPath);
3232
const encodedGitTag = encodeURIComponent(gitTag);
3333
const encodedVersion = encodeURIComponent(version);
3434
const apiOptions = {
@@ -52,7 +52,7 @@ export default async (pluginConfig, context) => {
5252
retry: { limit: retryLimit },
5353
};
5454

55-
debug("repoId: %o", repoId);
55+
debug("projectPath: %o", projectPath);
5656
debug("release name: %o", gitTag);
5757
debug("release ref: %o", gitHead);
5858
debug("milestones: %o", milestones);
@@ -115,7 +115,7 @@ export default async (pluginConfig, context) => {
115115
// https://docs.gitlab.com/ee/user/packages/generic_packages/#publish-a-package-file
116116
uploadEndpoint = urlJoin(
117117
gitlabApiUrl,
118-
`/projects/${encodedRepoId}/packages/generic/release/${encodedVersion}/${encodedLabel}?${
118+
`/projects/${encodedProjectPath}/packages/generic/release/${encodedVersion}/${encodedLabel}?${
119119
status ? `status=${status}&` : ""
120120
}select=package_file`
121121
);
@@ -132,15 +132,15 @@ export default async (pluginConfig, context) => {
132132
// https://docs.gitlab.com/ee/user/packages/generic_packages/#download-package-file
133133
const url = urlJoin(
134134
gitlabApiUrl,
135-
`/projects/${encodedRepoId}/packages/generic/release/${encodedVersion}/${encodedLabel}`
135+
`/projects/${encodedProjectPath}/packages/generic/release/${encodedVersion}/${encodedLabel}`
136136
);
137137

138138
assetsList.push({ label, alt: "release", url, type: "package", filepath });
139139

140140
logger.log("Uploaded file: %s (%s)", url, response.file.url);
141141
} else {
142142
// Handle normal assets
143-
uploadEndpoint = urlJoin(gitlabApiUrl, `/projects/${encodedRepoId}/uploads`);
143+
uploadEndpoint = urlJoin(gitlabApiUrl, `/projects/${encodedProjectPath}/uploads`);
144144

145145
debug("POST-ing the file %s to %s", file, uploadEndpoint);
146146

@@ -167,7 +167,7 @@ export default async (pluginConfig, context) => {
167167

168168
debug("Create a release for git tag %o with commit %o", gitTag, gitHead);
169169

170-
const createReleaseEndpoint = urlJoin(gitlabApiUrl, `/projects/${encodedRepoId}/releases`);
170+
const createReleaseEndpoint = urlJoin(gitlabApiUrl, `/projects/${encodedProjectPath}/releases`);
171171

172172
const json = {
173173
/* eslint-disable camelcase */
@@ -178,7 +178,7 @@ export default async (pluginConfig, context) => {
178178
links: assetsList.map(({ label, alt, url, type, filepath, rawUrl }) => {
179179
return {
180180
name: label || alt,
181-
url: rawUrl || (isUrlScheme(url) ? url : urlJoin(gitlabUrl, repoId, url)),
181+
url: rawUrl || (isUrlScheme(url) ? url : urlJoin(gitlabUrl, projectPath, url)),
182182
link_type: type,
183183
filepath,
184184
};
@@ -202,7 +202,7 @@ export default async (pluginConfig, context) => {
202202

203203
logger.log("Published GitLab release: %s", gitTag);
204204

205-
const releaseUrl = urlJoin(gitlabUrl, repoId, `/-/releases/${encodedGitTag}`);
205+
const releaseUrl = urlJoin(gitlabUrl, projectPath, `/-/releases/${encodedGitTag}`);
206206

207207
return { name: RELEASE_NAME, url: releaseUrl };
208208
};

lib/success.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import got from "got";
44
import _debug from "debug";
55
const debug = _debug("semantic-release:gitlab");
66
import resolveConfig from "./resolve-config.js";
7-
import getRepoId from "./get-repo-id.js";
7+
import getProjectPath from "./get-project-path.js";
88
import getSuccessComment from "./get-success-comment.js";
99

1010
export default async (pluginConfig, context) => {
@@ -17,8 +17,8 @@ export default async (pluginConfig, context) => {
1717
} = context;
1818
const { gitlabToken, gitlabUrl, gitlabApiUrl, successComment, successCommentCondition, proxy, retryLimit } =
1919
resolveConfig(pluginConfig, context);
20-
const repoId = getRepoId(context, gitlabUrl, repositoryUrl);
21-
const encodedRepoId = encodeURIComponent(repoId);
20+
const projectPath = getProjectPath(context, gitlabUrl, repositoryUrl);
21+
const encodedProjectPath = encodeURIComponent(projectPath);
2222
const apiOptions = {
2323
headers: { "PRIVATE-TOKEN": gitlabToken },
2424
retry: { limit: retryLimit },
@@ -79,7 +79,7 @@ Using 'false' for 'successComment' is deprecated and will be removed in a future
7979
const getRelatedMergeRequests = async (commitHash) => {
8080
const relatedMergeRequestsEndpoint = urlJoin(
8181
gitlabApiUrl,
82-
`/projects/${encodedRepoId}/repository/commits/${commitHash}/merge_requests`
82+
`/projects/${encodedProjectPath}/repository/commits/${commitHash}/merge_requests`
8383
);
8484
debug("Getting MRs from %s", relatedMergeRequestsEndpoint);
8585
const relatedMergeRequests = await got

lib/verify.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import _debug from "debug";
55
const debug = _debug("semantic-release:gitlab");
66
import AggregateError from "aggregate-error";
77
import resolveConfig from "./resolve-config.js";
8-
import getRepoId from "./get-repo-id.js";
8+
import getProjectPath from "./get-project-path.js";
99
import getError from "./get-error.js";
1010

1111
const isNonEmptyString = (value) => isString(value) && value.trim();
@@ -32,10 +32,10 @@ export default async (pluginConfig, context) => {
3232
logger,
3333
} = context;
3434
const { gitlabToken, gitlabUrl, gitlabApiUrl, proxy, ...options } = resolveConfig(pluginConfig, context);
35-
const repoId = getRepoId(context, gitlabUrl, repositoryUrl);
35+
const projectPath = getProjectPath(context, gitlabUrl, repositoryUrl);
3636

3737
debug("apiUrl: %o", gitlabApiUrl);
38-
debug("repoId: %o", repoId);
38+
debug("projectPath: %o", projectPath);
3939

4040
const isValid = (option, value) => {
4141
const validator = VALIDATORS[option];
@@ -46,15 +46,15 @@ export default async (pluginConfig, context) => {
4646
.filter(([option, value]) => !isValid(option, value))
4747
.map(([option, value]) => getError(`EINVALID${option.toUpperCase()}`, { [option]: value }));
4848

49-
if (!repoId) {
49+
if (!projectPath) {
5050
errors.push(getError("EINVALIDGITLABURL"));
5151
}
5252

5353
if (!gitlabToken) {
5454
errors.push(getError("ENOGLTOKEN", { repositoryUrl }));
5555
}
5656

57-
if (gitlabToken && repoId) {
57+
if (gitlabToken && projectPath) {
5858
let projectAccess;
5959
let groupAccess;
6060

@@ -64,7 +64,7 @@ export default async (pluginConfig, context) => {
6464
({
6565
permissions: { project_access: projectAccess, group_access: groupAccess },
6666
} = await got
67-
.get(urlJoin(gitlabApiUrl, `/projects/${encodeURIComponent(repoId)}`), {
67+
.get(urlJoin(gitlabApiUrl, `/projects/${encodeURIComponent(projectPath)}`), {
6868
headers: { "PRIVATE-TOKEN": gitlabToken },
6969
...proxy,
7070
})
@@ -73,17 +73,17 @@ export default async (pluginConfig, context) => {
7373
context.options.dryRun &&
7474
!((projectAccess && projectAccess.access_level >= 10) || (groupAccess && groupAccess.access_level >= 10))
7575
) {
76-
errors.push(getError("EGLNOPULLPERMISSION", { repoId }));
76+
errors.push(getError("EGLNOPULLPERMISSION", { projectPath }));
7777
} else if (
7878
!((projectAccess && projectAccess.access_level >= 30) || (groupAccess && groupAccess.access_level >= 30))
7979
) {
80-
errors.push(getError("EGLNOPUSHPERMISSION", { repoId }));
80+
errors.push(getError("EGLNOPUSHPERMISSION", { projectPath }));
8181
}
8282
} catch (error) {
8383
if (error.response && error.response.statusCode === 401) {
84-
errors.push(getError("EINVALIDGLTOKEN", { repoId }));
84+
errors.push(getError("EINVALIDGLTOKEN", { projectPath }));
8585
} else if (error.response && error.response.statusCode === 404) {
86-
errors.push(getError("EMISSINGREPO", { repoId }));
86+
errors.push(getError("EMISSINGREPO", { projectPath }));
8787
} else {
8888
throw error;
8989
}

test/fail.test.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ test.serial("Post new issue if none exists yet", async (t) => {
2626
const branch = { name: "main" };
2727
const options = { repositoryUrl: `https://gitlab.com/${owner}/${repo}.git` };
2828
const errors = [{ message: "An error occured" }];
29-
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
29+
const encodedProjectPath = encodeURIComponent(`${owner}/${repo}`);
3030
const encodedFailTitle = encodeURIComponent("The automated release is failing 🚨");
3131
const gitlab = authenticate(env)
32-
.get(`/projects/${encodedRepoId}/issues?state=opened&&search=${encodedFailTitle}`)
32+
.get(`/projects/${encodedProjectPath}/issues?state=opened&&search=${encodedFailTitle}`)
3333
.reply(200, [
3434
{
3535
id: 2,
@@ -39,7 +39,7 @@ test.serial("Post new issue if none exists yet", async (t) => {
3939
title: "API should implemented authentication",
4040
},
4141
])
42-
.post(`/projects/${encodedRepoId}/issues`, {
42+
.post(`/projects/${encodedProjectPath}/issues`, {
4343
id: "test_user%2Ftest_repo",
4444
description: `## :rotating_light: The automated release from the \`main\` branch failed. :rotating_light:
4545
@@ -92,10 +92,10 @@ test.serial("Post comments to existing issue", async (t) => {
9292
const branch = { name: "main" };
9393
const options = { repositoryUrl: `https://gitlab.com/${owner}/${repo}.git` };
9494
const errors = [{ message: "An error occured" }];
95-
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
95+
const encodedProjectPath = encodeURIComponent(`${owner}/${repo}`);
9696
const encodedFailTitle = encodeURIComponent("The automated release is failing 🚨");
9797
const gitlab = authenticate(env)
98-
.get(`/projects/${encodedRepoId}/issues?state=opened&search=${encodedFailTitle}`)
98+
.get(`/projects/${encodedProjectPath}/issues?state=opened&search=${encodedFailTitle}`)
9999
.reply(200, [
100100
{
101101
id: 1,
@@ -160,10 +160,10 @@ test.serial("Post comments to existing issue with custom template", async (t) =>
160160
const branch = { name: "main" };
161161
const options = { repositoryUrl: `https://gitlab.com/${owner}/${repo}.git` };
162162
const errors = [{ message: "An error occured" }];
163-
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
163+
const encodedProjectPath = encodeURIComponent(`${owner}/${repo}`);
164164
const encodedFailTitle = encodeURIComponent("Semantic Release Failure");
165165
const gitlab = authenticate(env)
166-
.get(`/projects/${encodedRepoId}/issues?state=opened&search=${encodedFailTitle}`)
166+
.get(`/projects/${encodedProjectPath}/issues?state=opened&search=${encodedFailTitle}`)
167167
.reply(200, [
168168
{
169169
id: 1,
@@ -252,10 +252,10 @@ test.serial("Does not post comments when failCommentCondition disables it", asyn
252252
const branch = { name: "main" };
253253
const options = { repositoryUrl: `https://gitlab.com/${owner}/${repo}.git` };
254254
const errors = [{ message: "An error occured" }];
255-
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
255+
const encodedProjectPath = encodeURIComponent(`${owner}/${repo}`);
256256
const encodedFailTitle = encodeURIComponent("The automated release is failing 🚨");
257257
const gitlab = authenticate(env)
258-
.get(`/projects/${encodedRepoId}/issues?state=opened&&search=${encodedFailTitle}`)
258+
.get(`/projects/${encodedProjectPath}/issues?state=opened&&search=${encodedFailTitle}`)
259259
.reply(200, [
260260
{
261261
id: 2,
@@ -279,10 +279,10 @@ test.serial("Does not post comments on existing issues when failCommentCondition
279279
const branch = { name: "main" };
280280
const options = { repositoryUrl: `https://gitlab.com/${owner}/${repo}.git` };
281281
const errors = [{ message: "An error occured" }];
282-
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
282+
const encodedProjectPath = encodeURIComponent(`${owner}/${repo}`);
283283
const encodedFailTitle = encodeURIComponent("The automated release is failing 🚨");
284284
const gitlab = authenticate(env)
285-
.get(`/projects/${encodedRepoId}/issues?state=opened&&search=${encodedFailTitle}`)
285+
.get(`/projects/${encodedProjectPath}/issues?state=opened&&search=${encodedFailTitle}`)
286286
.reply(200, [
287287
{
288288
id: 1,
@@ -316,10 +316,10 @@ test.serial("Post new issue if none exists yet with disabled comment on existing
316316
const branch = { name: "main" };
317317
const options = { repositoryUrl: `https://gitlab.com/${owner}/${repo}.git` };
318318
const errors = [{ message: "An error occured" }];
319-
const encodedRepoId = encodeURIComponent(`${owner}/${repo}`);
319+
const encodedProjectPath = encodeURIComponent(`${owner}/${repo}`);
320320
const encodedFailTitle = encodeURIComponent("The automated release is failing 🚨");
321321
const gitlab = authenticate(env)
322-
.get(`/projects/${encodedRepoId}/issues?state=opened&&search=${encodedFailTitle}`)
322+
.get(`/projects/${encodedProjectPath}/issues?state=opened&&search=${encodedFailTitle}`)
323323
.reply(200, [
324324
{
325325
id: 2,
@@ -329,7 +329,7 @@ test.serial("Post new issue if none exists yet with disabled comment on existing
329329
title: "API should implemented authentication",
330330
},
331331
])
332-
.post(`/projects/${encodedRepoId}/issues`, {
332+
.post(`/projects/${encodedProjectPath}/issues`, {
333333
id: "test_user%2Ftest_repo",
334334
description: `Error: Release for branch main failed with error: An error occured`,
335335
labels: "semantic-release",

0 commit comments

Comments
 (0)