release-it 17.9.0 → 17.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/plugin/gitlab/GitLab.js +29 -16
- package/package.json +1 -1
- package/test/gitlab.js +3 -3
- package/test/stub/gitlab.js +12 -3
- package/test/tasks.js +1 -1
|
@@ -165,6 +165,7 @@ class GitLab extends Release {
|
|
|
165
165
|
const url = `${baseUrl}/${endpoint}${options.searchParams ? `?${new URLSearchParams(options.searchParams)}` : ''}`;
|
|
166
166
|
const headers = {
|
|
167
167
|
'user-agent': 'webpro/release-it',
|
|
168
|
+
'Content-Type': typeof options.json !== 'undefined' ? 'application/json' : 'text/plain',
|
|
168
169
|
[tokenHeader]: this.token
|
|
169
170
|
};
|
|
170
171
|
const requestOptions = {
|
|
@@ -173,18 +174,29 @@ class GitLab extends Release {
|
|
|
173
174
|
...this.certificateAuthorityOption
|
|
174
175
|
};
|
|
175
176
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
177
|
+
try {
|
|
178
|
+
const response = await fetch(
|
|
179
|
+
url,
|
|
180
|
+
options.json || options.body
|
|
181
|
+
? {
|
|
182
|
+
...requestOptions,
|
|
183
|
+
body: options.json ? JSON.stringify(options.json) : options.body
|
|
184
|
+
}
|
|
185
|
+
: requestOptions
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
if (!response.ok) {
|
|
189
|
+
const body = await response.json();
|
|
190
|
+
throw new Error(body.error);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const body = await response.json();
|
|
194
|
+
this.debug(body);
|
|
195
|
+
return body;
|
|
196
|
+
} catch (err) {
|
|
197
|
+
this.debug(err);
|
|
198
|
+
throw err;
|
|
199
|
+
}
|
|
188
200
|
}
|
|
189
201
|
|
|
190
202
|
async createRelease() {
|
|
@@ -195,7 +207,7 @@ class GitLab extends Release {
|
|
|
195
207
|
const name = format(releaseName, this.config.getContext());
|
|
196
208
|
const tagMessage = format(tagAnnotation, this.config.getContext());
|
|
197
209
|
const description = releaseNotes || '-';
|
|
198
|
-
const releaseUrl = `${origin}/${repo.repository}/-/releases`;
|
|
210
|
+
const releaseUrl = `${origin}/${repo.repository}/-/releases/${tagName}`;
|
|
199
211
|
const releaseMilestones = this.getReleaseMilestones();
|
|
200
212
|
|
|
201
213
|
this.log.exec(`gitlab releases#createRelease "${name}" (${tagName})`, { isDryRun });
|
|
@@ -227,10 +239,11 @@ class GitLab extends Release {
|
|
|
227
239
|
}
|
|
228
240
|
|
|
229
241
|
try {
|
|
230
|
-
await this.request(endpoint, options);
|
|
242
|
+
const body = await this.request(endpoint, options);
|
|
243
|
+
const releaseUrlSelf = body._links?.self ?? releaseUrl;
|
|
231
244
|
this.log.verbose('gitlab releases#createRelease: done');
|
|
232
|
-
this.setContext({ isReleased: true, releaseUrl });
|
|
233
|
-
this.config.setContext({ isReleased: true, releaseUrl });
|
|
245
|
+
this.setContext({ isReleased: true, releaseUrl: releaseUrlSelf });
|
|
246
|
+
this.config.setContext({ isReleased: true, releaseUrl: releaseUrlSelf });
|
|
234
247
|
return true;
|
|
235
248
|
} catch (err) {
|
|
236
249
|
this.debug(err);
|
package/package.json
CHANGED
package/test/gitlab.js
CHANGED
|
@@ -114,7 +114,7 @@ test.serial('should upload assets and release', async t => {
|
|
|
114
114
|
t.is(gitlab.assets[0].url, `${pushRepo}/uploads/7e8bec1fe27cc46a4bc6a91b9e82a07c/file-v2.0.1.txt`);
|
|
115
115
|
const { isReleased, releaseUrl } = gitlab.getContext();
|
|
116
116
|
t.true(isReleased);
|
|
117
|
-
t.is(releaseUrl, `${pushRepo}/-/releases`);
|
|
117
|
+
t.is(releaseUrl, `${pushRepo}/-/releases/2.0.1`);
|
|
118
118
|
});
|
|
119
119
|
|
|
120
120
|
test.serial('should upload assets with ID-based URLs too', async t => {
|
|
@@ -211,7 +211,7 @@ test.serial('should release to sub-grouped repo', async t => {
|
|
|
211
211
|
|
|
212
212
|
const { isReleased, releaseUrl } = gitlab.getContext();
|
|
213
213
|
t.true(isReleased);
|
|
214
|
-
t.
|
|
214
|
+
t.regex(releaseUrl, /https:\/\/gitlab.com\/group\/sub-group\/repo\/-\/releases\//);
|
|
215
215
|
});
|
|
216
216
|
|
|
217
217
|
test.serial('should throw for unauthenticated user', async t => {
|
|
@@ -265,7 +265,7 @@ test('should not make requests in dry run', async t => {
|
|
|
265
265
|
t.is(gitlab.log.exec.args[2][0], 'gitlab releases#uploadAssets');
|
|
266
266
|
t.is(gitlab.log.exec.args[3][0], 'gitlab releases#createRelease "R" (1.0.1)');
|
|
267
267
|
t.true(isReleased);
|
|
268
|
-
t.is(releaseUrl, `${pushRepo}/-/releases`);
|
|
268
|
+
t.is(releaseUrl, `${pushRepo}/-/releases/1.0.1`);
|
|
269
269
|
});
|
|
270
270
|
|
|
271
271
|
test('should skip checks', async t => {
|
package/test/stub/gitlab.js
CHANGED
|
@@ -12,7 +12,13 @@ export let interceptCollaborator = (
|
|
|
12
12
|
.reply(200, { id: userId, username: owner, access_level: 30 });
|
|
13
13
|
|
|
14
14
|
export let interceptPublish = ({ host = 'https://gitlab.com', owner = 'user', project = 'repo', body } = {}, options) =>
|
|
15
|
-
nock(host, options)
|
|
15
|
+
nock(host, options)
|
|
16
|
+
.post(`/api/v4/projects/${owner}%2F${project}/releases`, body)
|
|
17
|
+
.reply(200, {
|
|
18
|
+
_links: {
|
|
19
|
+
self: `https://gitlab.com/${owner}/${project}/-/releases/${body?.tag_name ?? '1.0.0'}`
|
|
20
|
+
}
|
|
21
|
+
});
|
|
16
22
|
|
|
17
23
|
export let interceptMilestones = (
|
|
18
24
|
{ host = 'https://gitlab.com', owner = 'user', project = 'repo', query = {}, milestones = [] } = {},
|
|
@@ -34,12 +40,15 @@ export let interceptAsset = ({ host = 'https://gitlab.com', owner = 'user', proj
|
|
|
34
40
|
nock(host)
|
|
35
41
|
.post(`/api/v4/projects/${owner}%2F${project}/uploads`)
|
|
36
42
|
.query(true)
|
|
37
|
-
.reply(200,
|
|
43
|
+
.reply(200, (_, requestBody) => {
|
|
38
44
|
const [, name] = requestBody.match(/filename="([^"]+)/);
|
|
39
45
|
return {
|
|
40
46
|
alt: name,
|
|
41
47
|
url: `/uploads/7e8bec1fe27cc46a4bc6a91b9e82a07c/${name}`,
|
|
42
48
|
full_path: `/-/project/1234/uploads/7e8bec1fe27cc46a4bc6a91b9e82a07c/${name}`,
|
|
43
|
-
markdown: `[${name}](/uploads/7e8bec1fe27cc46a4bc6a91b9e82a07c/${name})
|
|
49
|
+
markdown: `[${name}](/uploads/7e8bec1fe27cc46a4bc6a91b9e82a07c/${name})`,
|
|
50
|
+
_links: {
|
|
51
|
+
self: `https://gitlab.com/${owner}/${project}/-/releases/${name}`
|
|
52
|
+
}
|
|
44
53
|
};
|
|
45
54
|
});
|
package/test/tasks.js
CHANGED
|
@@ -339,7 +339,7 @@ test.serial('should release all the things (pre-release, github, gitlab)', async
|
|
|
339
339
|
t.true(log.obtrusive.firstCall.args[0].endsWith(`release ${pkgName} (1.0.0...1.1.0-alpha.0)`));
|
|
340
340
|
t.true(log.log.firstCall.args[0].endsWith(`https://www.npmjs.com/package/${pkgName}`));
|
|
341
341
|
t.true(log.log.secondCall.args[0].endsWith(`https://github.com/${owner}/${project}/releases/tag/v1.1.0-alpha.0`));
|
|
342
|
-
t.true(log.log.thirdCall.args[0].endsWith(`${project}/-/releases`));
|
|
342
|
+
t.true(log.log.thirdCall.args[0].endsWith(`${project}/-/releases/v1.1.0-alpha.0`));
|
|
343
343
|
t.regex(log.log.lastCall.args[0], /Done \(in [0-9]+s\.\)/);
|
|
344
344
|
|
|
345
345
|
exec.restore();
|