Skip to content

Commit a54e596

Browse files
authoredNov 17, 2020
feat: set target_commitish when creating a GitHub release (#305)
Closes #304
1 parent ba68d3b commit a54e596

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed
 

‎lib/publish.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@ module.exports = async (pluginConfig, context) => {
2121
const {githubToken, githubUrl, githubApiPathPrefix, proxy, assets} = resolveConfig(pluginConfig, context);
2222
const {owner, repo} = parseGithubUrl(repositoryUrl);
2323
const github = getClient({githubToken, githubUrl, githubApiPathPrefix, proxy});
24-
const release = {owner, repo, tag_name: gitTag, name, body: notes, prerelease: isPrerelease(branch)};
24+
const release = {
25+
owner,
26+
repo,
27+
tag_name: gitTag,
28+
target_commitish: branch.name,
29+
name,
30+
body: notes,
31+
prerelease: isPrerelease(branch),
32+
};
2533

2634
debug('release object: %O', release);
2735

‎test/publish.test.js

+32-10
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ test.serial('Publish a release', async (t) => {
3939
const releaseId = 1;
4040
const uploadUri = `/api/uploads/repos/${owner}/${repo}/releases/${releaseId}/assets`;
4141
const uploadUrl = `https://github.com${uploadUri}{?name,label}`;
42+
const branch = 'test_branch';
4243

4344
const github = authenticate(env)
4445
.post(`/repos/${owner}/${repo}/releases`, {
4546
tag_name: nextRelease.gitTag,
47+
target_commitish: branch,
4648
name: nextRelease.name,
4749
body: nextRelease.notes,
4850
prerelease: false,
@@ -53,7 +55,7 @@ test.serial('Publish a release', async (t) => {
5355
cwd,
5456
env,
5557
options,
56-
branch: {type: 'release', main: true},
58+
branch: {name: branch, type: 'release', main: true},
5759
nextRelease,
5860
logger: t.context.logger,
5961
});
@@ -74,10 +76,12 @@ test.serial('Publish a release on a channel', async (t) => {
7476
const releaseId = 1;
7577
const uploadUri = `/api/uploads/repos/${owner}/${repo}/releases/${releaseId}/assets`;
7678
const uploadUrl = `https://github.com${uploadUri}{?name,label}`;
79+
const branch = 'test_branch';
7780

7881
const github = authenticate(env)
7982
.post(`/repos/${owner}/${repo}/releases`, {
8083
tag_name: nextRelease.gitTag,
84+
target_commitish: branch,
8185
name: nextRelease.name,
8286
body: nextRelease.notes,
8387
prerelease: true,
@@ -88,7 +92,7 @@ test.serial('Publish a release on a channel', async (t) => {
8892
cwd,
8993
env,
9094
options,
91-
branch: {type: 'release', channel: 'next', main: false},
95+
branch: {name: branch, type: 'release', channel: 'next', main: false},
9296
nextRelease,
9397
logger: t.context.logger,
9498
});
@@ -109,10 +113,12 @@ test.serial('Publish a prerelease', async (t) => {
109113
const releaseId = 1;
110114
const uploadUri = `/api/uploads/repos/${owner}/${repo}/releases/${releaseId}/assets`;
111115
const uploadUrl = `https://github.com${uploadUri}{?name,label}`;
116+
const branch = 'test_branch';
112117

113118
const github = authenticate(env)
114119
.post(`/repos/${owner}/${repo}/releases`, {
115120
tag_name: nextRelease.gitTag,
121+
target_commitish: branch,
116122
name: nextRelease.name,
117123
body: nextRelease.notes,
118124
prerelease: true,
@@ -123,7 +129,7 @@ test.serial('Publish a prerelease', async (t) => {
123129
cwd,
124130
env,
125131
options,
126-
branch: {type: 'prerelease', channel: 'beta'},
132+
branch: {name: branch, type: 'prerelease', channel: 'beta'},
127133
nextRelease,
128134
logger: t.context.logger,
129135
});
@@ -144,10 +150,12 @@ test.serial('Publish a maintenance release', async (t) => {
144150
const releaseId = 1;
145151
const uploadUri = `/api/uploads/repos/${owner}/${repo}/releases/${releaseId}/assets`;
146152
const uploadUrl = `https://github.com${uploadUri}{?name,label}`;
153+
const branch = 'test_branch';
147154

148155
const github = authenticate(env)
149156
.post(`/repos/${owner}/${repo}/releases`, {
150157
tag_name: nextRelease.gitTag,
158+
target_commitish: branch,
151159
name: nextRelease.name,
152160
body: nextRelease.notes,
153161
prerelease: false,
@@ -158,7 +166,7 @@ test.serial('Publish a maintenance release', async (t) => {
158166
cwd,
159167
env,
160168
options,
161-
branch: {type: 'maintenance', channel: '1.x', main: false},
169+
branch: {name: 'test_branch', type: 'maintenance', channel: '1.x', main: false},
162170
nextRelease,
163171
logger: t.context.logger,
164172
});
@@ -179,10 +187,12 @@ test.serial('Publish a release, retrying 4 times', async (t) => {
179187
const releaseId = 1;
180188
const uploadUri = `/api/uploads/repos/${owner}/${repo}/releases/${releaseId}/assets`;
181189
const uploadUrl = `https://github.com${uploadUri}{?name,label}`;
190+
const branch = 'test_branch';
182191

183192
const github = authenticate(env)
184193
.post(`/repos/${owner}/${repo}/releases`, {
185194
tag_name: nextRelease.gitTag,
195+
target_commitish: branch,
186196
name: nextRelease.gitTag,
187197
body: nextRelease.notes,
188198
prerelease: false,
@@ -191,6 +201,7 @@ test.serial('Publish a release, retrying 4 times', async (t) => {
191201
.reply(404)
192202
.post(`/repos/${owner}/${repo}/releases`, {
193203
tag_name: nextRelease.gitTag,
204+
target_commitish: branch,
194205
name: nextRelease.name,
195206
body: nextRelease.notes,
196207
prerelease: false,
@@ -201,7 +212,7 @@ test.serial('Publish a release, retrying 4 times', async (t) => {
201212
cwd,
202213
env,
203214
options,
204-
branch: {type: 'release', main: true},
215+
branch: {name: branch, type: 'release', main: true},
205216
nextRelease,
206217
logger: t.context.logger,
207218
});
@@ -226,10 +237,12 @@ test.serial('Publish a release with one asset', async (t) => {
226237
const releaseId = 1;
227238
const uploadUri = `/api/uploads/repos/${owner}/${repo}/releases/${releaseId}/assets`;
228239
const uploadUrl = `https://github.com${uploadUri}{?name,label}`;
240+
const branch = 'test_branch';
229241

230242
const github = authenticate(env)
231243
.post(`/repos/${owner}/${repo}/releases`, {
232244
tag_name: nextRelease.gitTag,
245+
target_commitish: branch,
233246
name: nextRelease.name,
234247
body: nextRelease.notes,
235248
draft: true,
@@ -250,7 +263,7 @@ test.serial('Publish a release with one asset', async (t) => {
250263
cwd,
251264
env,
252265
options,
253-
branch: {type: 'release', main: true},
266+
branch: {name: branch, type: 'release', main: true},
254267
nextRelease,
255268
logger: t.context.logger,
256269
});
@@ -277,10 +290,12 @@ test.serial('Publish a release with one asset and custom github url', async (t)
277290
const releaseId = 1;
278291
const uploadUri = `/api/uploads/repos/${owner}/${repo}/releases/${releaseId}/assets`;
279292
const uploadUrl = `${env.GH_URL}${uploadUri}{?name,label}`;
293+
const branch = 'test_branch';
280294

281295
const github = authenticate(env, {})
282296
.post(`/repos/${owner}/${repo}/releases`, {
283297
tag_name: nextRelease.gitTag,
298+
target_commitish: branch,
284299
name: nextRelease.name,
285300
body: nextRelease.notes,
286301
draft: true,
@@ -301,7 +316,7 @@ test.serial('Publish a release with one asset and custom github url', async (t)
301316
cwd,
302317
env,
303318
options,
304-
branch: {type: 'release', main: true},
319+
branch: {name: branch, type: 'release', main: true},
305320
nextRelease,
306321
logger: t.context.logger,
307322
});
@@ -326,10 +341,12 @@ test.serial('Publish a release with an array of missing assets', async (t) => {
326341
const releaseId = 1;
327342
const uploadUri = `/api/uploads/repos/${owner}/${repo}/releases/${releaseId}/assets`;
328343
const uploadUrl = `https://github.com${uploadUri}{?name,label}`;
344+
const branch = 'test_branch';
329345

330346
const github = authenticate(env)
331347
.post(`/repos/${owner}/${repo}/releases`, {
332348
tag_name: nextRelease.gitTag,
349+
target_commitish: branch,
333350
name: nextRelease.name,
334351
body: nextRelease.notes,
335352
draft: true,
@@ -343,7 +360,7 @@ test.serial('Publish a release with an array of missing assets', async (t) => {
343360
cwd,
344361
env,
345362
options,
346-
branch: {type: 'release', main: true},
363+
branch: {name: branch, type: 'release', main: true},
347364
nextRelease,
348365
logger: t.context.logger,
349366
});
@@ -362,17 +379,20 @@ test.serial('Throw error without retries for 400 error', async (t) => {
362379
const pluginConfig = {};
363380
const nextRelease = {gitTag: 'v1.0.0', name: 'v1.0.0', notes: 'Test release note body'};
364381
const options = {repositoryUrl: `https://github.com/${owner}/${repo}.git`};
382+
const branch = 'test_branch';
365383

366384
const github = authenticate(env)
367385
.post(`/repos/${owner}/${repo}/releases`, {
368386
tag_name: nextRelease.gitTag,
387+
target_commitish: branch,
369388
name: nextRelease.name,
370389
body: nextRelease.notes,
371390
prerelease: false,
372391
})
373392
.reply(404)
374393
.post(`/repos/${owner}/${repo}/releases`, {
375394
tag_name: nextRelease.gitTag,
395+
target_commitish: branch,
376396
name: nextRelease.gitTag,
377397
body: nextRelease.notes,
378398
prerelease: false,
@@ -384,7 +404,7 @@ test.serial('Throw error without retries for 400 error', async (t) => {
384404
cwd,
385405
env,
386406
options,
387-
branch: {type: 'release', main: true},
407+
branch: {name: branch, type: 'release', main: true},
388408
nextRelease,
389409
logger: t.context.logger,
390410
})
@@ -411,10 +431,12 @@ test.serial(
411431
const releaseId = 1;
412432
const uploadUri = `/api/uploads/repos/${owner}/${repo}/releases/${releaseId}/assets`;
413433
const uploadUrl = `https://github.com${uploadUri}{?name,label}`;
434+
const branch = 'test_branch';
414435

415436
const github = authenticate(env)
416437
.post(`/repos/${owner}/${repo}/releases`, {
417438
tag_name: nextRelease.gitTag,
439+
target_commitish: branch,
418440
name: nextRelease.name,
419441
body: nextRelease.notes,
420442
prerelease: false,
@@ -425,7 +447,7 @@ test.serial(
425447
cwd,
426448
env,
427449
options,
428-
branch: {type: 'release', main: true},
450+
branch: {name: branch, type: 'release', main: true},
429451
nextRelease,
430452
logger: t.context.logger,
431453
});

0 commit comments

Comments
 (0)
Please sign in to comment.