Skip to content

Commit 72283df

Browse files
committed
Merge remote-tracking branch 'upstream/master' into use-channel-as-generic-package-name
2 parents 67a6f6e + 062f0fa commit 72283df

21 files changed

+4522
-3523
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ jobs:
1818
name: release
1919
runs-on: ubuntu-latest
2020
steps:
21-
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
22-
- uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3
21+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
22+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
2323
with:
2424
cache: npm
2525
node-version: lts/*

.github/workflows/test.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@ jobs:
1313
strategy:
1414
matrix:
1515
node-version:
16-
- 18.0.0
17-
- 19
16+
- 20.8.1 # minimum supported Node version
17+
- 20
18+
- 21
19+
- 22
1820
os:
1921
- ubuntu-latest
2022
- macos-latest
2123
- windows-latest
2224
runs-on: "${{ matrix.os }}"
2325
steps:
24-
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
26+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2527
- name: "Use Node.js ${{ matrix.node-version }}"
26-
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3
28+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
2729
with:
2830
node-version: "${{ matrix.node-version }}"
2931
cache: npm
@@ -35,9 +37,9 @@ jobs:
3537
runs-on: ubuntu-latest
3638
needs: test_matrix
3739
steps:
38-
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
40+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3941
- name: "Use Node.js ${{ matrix.node-version }}"
40-
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3
42+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
4143
with:
4244
node-version: "${{ matrix.node-version }}"
4345
cache: npm

README.md

Lines changed: 61 additions & 14 deletions
Large diffs are not rendered by default.

lib/definitions/errors.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {inspect} from 'util';
2-
import pkg from '../../package.json' assert {type: 'json'};
2+
import { createRequire } from "node:module";
3+
const require = createRequire(import.meta.url);
34

5+
const pkg = require("../../package.json");
46
const [homepage] = pkg.homepage.split('#');
57
const linkify = (file) => `${homepage}/blob/master/${file}`;
68
const stringify = (object) => inspect(object, {breakLength: Number.POSITIVE_INFINITY, depth: 2, maxArrayLength: 5});
@@ -39,20 +41,20 @@ Your configuration for the \`labels\` option is \`${stringify(labels)}\`.`,
3941
}),
4042
EINVALIDGITLABURL: () => ({
4143
message: 'The git repository URL is not a valid GitLab URL.',
42-
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\`.
4345
4446
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.`,
4547
}),
46-
EINVALIDGLTOKEN: ({repoId}) => ({
48+
EINVALIDGLTOKEN: ({projectPath}) => ({
4749
message: 'Invalid GitLab token.',
4850
details: `The [GitLab token](${linkify(
4951
'README.md#gitlab-authentication'
50-
)}) 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}.
5153
5254
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.`,
5355
}),
54-
EMISSINGREPO: ({repoId}) => ({
55-
message: `The repository ${repoId} doesn't exist.`,
56+
EMISSINGREPO: ({projectPath}) => ({
57+
message: `The repository ${projectPath} doesn't exist.`,
5658
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).
5759
5860
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.
@@ -61,21 +63,21 @@ If you are using [GitLab Enterprise Edition](https://about.gitlab.com/gitlab-ee)
6163
'README.md#options'
6264
)}).`,
6365
}),
64-
EGLNOPUSHPERMISSION: ({repoId}) => ({
65-
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}.`,
6668
details: `The user associated with the [GitLab token](${linkify(
6769
'README.md#gitlab-authentication'
68-
)}) 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}.
6971
70-
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}.`,
7173
}),
72-
EGLNOPULLPERMISSION: ({repoId}) => ({
73-
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}.`,
7476
details: `The user associated with the [GitLab token](${linkify(
7577
'README.md#gitlab-authentication'
76-
)}) 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}.
7779
78-
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}.`,
7981
}),
8082
ENOGLTOKEN: ({repositoryUrl}) => ({
8183
message: 'No GitLab token specified.',

lib/fail.js

Lines changed: 57 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ 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";
87
import getFailComment from "./get-fail-comment.js";
8+
import getProjectContext from "./get-project-context.js";
99

1010
export default async (pluginConfig, context) => {
1111
const {
@@ -14,50 +14,77 @@ export default async (pluginConfig, context) => {
1414
errors,
1515
logger,
1616
} = context;
17-
const { gitlabToken, gitlabUrl, gitlabApiUrl, failComment, failTitle, labels, assignee } = resolveConfig(
18-
pluginConfig,
19-
context
20-
);
21-
const repoId = getRepoId(context, gitlabUrl, repositoryUrl);
22-
const encodedRepoId = encodeURIComponent(repoId);
23-
const apiOptions = { headers: { "PRIVATE-TOKEN": gitlabToken } };
17+
const {
18+
gitlabToken,
19+
gitlabUrl,
20+
gitlabApiUrl,
21+
failComment,
22+
failTitle,
23+
failCommentCondition,
24+
labels,
25+
assignee,
26+
retryLimit,
27+
retryStatusCodes,
28+
} = resolveConfig(pluginConfig, context);
29+
const { encodedProjectPath, projectApiUrl } = getProjectContext(context, gitlabUrl, gitlabApiUrl, repositoryUrl);
30+
31+
const apiOptions = {
32+
headers: { "PRIVATE-TOKEN": gitlabToken },
33+
retry: {
34+
limit: retryLimit,
35+
statusCodes: retryStatusCodes,
36+
},
37+
};
2438

2539
if (failComment === false || failTitle === false) {
2640
logger.log("Skip issue creation.");
41+
logger.error(`Failure reporting should be disabled via 'failCommentCondition'.
42+
Using 'false' for 'failComment' or 'failTitle' is deprecated and will be removed in a future major version.`);
43+
} else if (failCommentCondition === false) {
44+
logger.log("Skip issue creation.");
2745
} else {
2846
const encodedFailTitle = encodeURIComponent(failTitle);
2947
const description = failComment ? template(failComment)({ branch, errors }) : getFailComment(branch, errors);
3048

31-
const issuesEndpoint = urlJoin(gitlabApiUrl, `/projects/${encodedRepoId}/issues`);
49+
const issuesEndpoint = urlJoin(projectApiUrl, `issues`);
3250
const openFailTitleIssueEndpoint = urlJoin(issuesEndpoint, `?state=opened&search=${encodedFailTitle}`);
3351

3452
const openFailTitleIssues = await got(openFailTitleIssueEndpoint, { ...apiOptions }).json();
3553
const existingIssue = openFailTitleIssues.find((openFailTitleIssue) => openFailTitleIssue.title === failTitle);
3654

37-
if (existingIssue) {
38-
debug("comment on issue: %O", existingIssue);
55+
const canCommentOnOrCreateIssue = failCommentCondition
56+
? template(failCommentCondition)({ ...context, issue: existingIssue })
57+
: true;
58+
if (canCommentOnOrCreateIssue) {
59+
if (existingIssue) {
60+
debug("comment on issue: %O", existingIssue);
61+
62+
const issueNotesEndpoint = urlJoin(
63+
gitlabApiUrl,
64+
`/projects/${existingIssue.project_id}/issues/${existingIssue.iid}/notes`
65+
);
66+
await got.post(issueNotesEndpoint, {
67+
...apiOptions,
68+
json: { body: description },
69+
});
3970

40-
const issueNotesEndpoint = urlJoin(
41-
gitlabApiUrl,
42-
`/projects/${existingIssue.project_id}/issues/${existingIssue.iid}/notes`
43-
);
44-
await got.post(issueNotesEndpoint, {
45-
...apiOptions,
46-
json: { body: description },
47-
});
71+
const { id, web_url } = existingIssue;
72+
logger.log("Commented on issue #%d: %s.", id, web_url);
73+
} else {
74+
const newIssue = { id: encodedProjectPath, description, labels, title: failTitle, assignee_id: assignee };
75+
debug("create issue: %O", newIssue);
4876

49-
const { id, web_url } = existingIssue;
50-
logger.log("Commented on issue #%d: %s.", id, web_url);
77+
/* eslint camelcase: off */
78+
const { id, web_url } = await got
79+
.post(issuesEndpoint, {
80+
...apiOptions,
81+
json: newIssue,
82+
})
83+
.json();
84+
logger.log("Created issue #%d: %s.", id, web_url);
85+
}
5186
} else {
52-
const newIssue = { id: encodedRepoId, description, labels, title: failTitle, assignee_id: assignee };
53-
debug("create issue: %O", newIssue);
54-
55-
/* eslint camelcase: off */
56-
const { id, web_url } = await got.post(issuesEndpoint, {
57-
...apiOptions,
58-
json: newIssue,
59-
});
60-
logger.log("Created issue #%d: %s.", id, web_url);
87+
logger.log("Skip commenting on or creating an issue.");
6188
}
6289
}
6390
};

lib/get-project-context.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import escapeStringRegexp from "escape-string-regexp";
2+
import parseUrl from "parse-url";
3+
import urlJoin from "url-join";
4+
5+
export default (
6+
{ envCi: { service } = {}, env: { CI_PROJECT_ID, CI_PROJECT_PATH } },
7+
gitlabUrl,
8+
gitlabApiUrl,
9+
repositoryUrl
10+
) => {
11+
const projectId = service === "gitlab" && CI_PROJECT_ID ? CI_PROJECT_ID : null;
12+
const projectPath =
13+
service === "gitlab" && CI_PROJECT_PATH
14+
? CI_PROJECT_PATH
15+
: parseUrl(repositoryUrl)
16+
.pathname.replace(new RegExp(`^${escapeStringRegexp(parseUrl(gitlabUrl).pathname)}`), "")
17+
.replace(/^\//, "")
18+
.replace(/\/$/, "")
19+
.replace(/\.git$/, "");
20+
const encodedProjectPath = encodeURIComponent(projectPath);
21+
const projectApiUrl = urlJoin(gitlabApiUrl, `/projects/${projectId ?? encodedProjectPath}`);
22+
return {
23+
projectPath,
24+
encodedProjectPath,
25+
projectApiUrl,
26+
};
27+
};

lib/get-repo-id.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

lib/glob-assets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from "path";
22
import { isPlainObject, castArray, uniqWith, uniq } from "lodash-es";
33
import dirGlob from "dir-glob";
4-
import globby from "globby";
4+
import { globby } from "globby";
55
import _debug from "debug";
66
const debug = _debug("semantic-release:gitlab");
77

0 commit comments

Comments
 (0)