Skip to content

Commit 68b1d18

Browse files
committed
feat: return release informations from publish hook
1 parent afa90f9 commit 68b1d18

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async function publish(pluginConfig, context) {
2424
await verifyGitHub(pluginConfig, context);
2525
verified = true;
2626
}
27-
await publishGitHub(pluginConfig, context);
27+
return publishGitHub(pluginConfig, context);
2828
}
2929

3030
module.exports = {verifyConditions, publish};

lib/publish.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ module.exports = async (pluginConfig, {options: {branch, repositoryUrl}, nextRel
2020
debug('release name: %o', gitTag);
2121
debug('release branch: %o', branch);
2222

23-
const {data: {html_url: htmlUrl, upload_url: uploadUrl}} = await github.repos.createRelease(release);
24-
logger.log('Published GitHub release: %s', htmlUrl);
23+
const {data: {html_url: url, upload_url: uploadUrl}} = await github.repos.createRelease(release);
24+
logger.log('Published GitHub release: %s', url);
2525

2626
if (assets && assets.length > 0) {
2727
const globbedAssets = await globAssets(assets);
@@ -64,4 +64,6 @@ module.exports = async (pluginConfig, {options: {branch, repositoryUrl}, nextRel
6464
logger.log('Published file %s', downloadUrl);
6565
});
6666
}
67+
68+
return {url, name: 'GitHub release'};
6769
};

test/integration.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ test.serial('Publish a release with an array of assets', async t => {
147147
.post(`${uploadUri}?name=${escape('upload_other.txt')}&label=${escape('Other File')}`)
148148
.reply(200, {browser_download_url: otherAssetUrl});
149149

150-
await t.context.m.publish({assets}, {nextRelease, options, logger: t.context.logger});
150+
const result = await t.context.m.publish({assets}, {nextRelease, options, logger: t.context.logger});
151151

152+
t.is(result.url, releaseUrl);
152153
t.deepEqual(t.context.log.args[0], ['Verify GitHub authentication']);
153154
t.deepEqual(t.context.log.args[1], ['Published GitHub release: %s', releaseUrl]);
154155
t.deepEqual(t.context.log.args[2], ['Published file %s', assetUrl]);

test/publish.test.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ test.serial('Publish a release', async t => {
5454
})
5555
.reply(200, {upload_url: uploadUrl, html_url: releaseUrl});
5656

57-
await publish(pluginConfig, {options, nextRelease, logger: t.context.logger});
57+
const result = await publish(pluginConfig, {options, nextRelease, logger: t.context.logger});
5858

59+
t.is(result.url, releaseUrl);
5960
t.deepEqual(t.context.log.args[0], ['Published GitHub release: %s', releaseUrl]);
6061
t.true(github.isDone());
6162
});
@@ -91,8 +92,9 @@ test.serial('Publish a release with one asset', async t => {
9192
.post(`${uploadUri}?name=${escape('.dotfile')}&label=${escape('A dotfile with no ext')}`)
9293
.reply(200, {browser_download_url: assetUrl});
9394

94-
await publish(pluginConfig, {options, nextRelease, logger: t.context.logger});
95+
const result = await publish(pluginConfig, {options, nextRelease, logger: t.context.logger});
9596

97+
t.is(result.url, releaseUrl);
9698
t.deepEqual(t.context.log.args[0], ['Published GitHub release: %s', releaseUrl]);
9799
t.deepEqual(t.context.log.args[1], ['Published file %s', assetUrl]);
98100
t.true(github.isDone());
@@ -139,8 +141,9 @@ test.serial('Publish a release with one asset and custom github url', async t =>
139141
.post(`${uploadUri}?name=${escape('upload.txt')}&label=${escape('A text file')}`)
140142
.reply(200, {browser_download_url: assetUrl});
141143

142-
await publish(pluginConfig, {options, nextRelease, logger: t.context.logger});
144+
const result = await publish(pluginConfig, {options, nextRelease, logger: t.context.logger});
143145

146+
t.is(result.url, releaseUrl);
144147
t.deepEqual(t.context.log.args[0], ['Published GitHub release: %s', releaseUrl]);
145148
t.deepEqual(t.context.log.args[1], ['Published file %s', assetUrl]);
146149
t.true(github.isDone());
@@ -169,8 +172,9 @@ test.serial('Publish a release with an array of missing assets', async t => {
169172
})
170173
.reply(200, {upload_url: uploadUrl, html_url: releaseUrl});
171174

172-
await publish(pluginConfig, {options, nextRelease, logger: t.context.logger});
175+
const result = await publish(pluginConfig, {options, nextRelease, logger: t.context.logger});
173176

177+
t.is(result.url, releaseUrl);
174178
t.deepEqual(t.context.log.args[0], ['Published GitHub release: %s', releaseUrl]);
175179
t.deepEqual(t.context.error.args[0], [
176180
'The asset %s cannot be read, and will be ignored.',

0 commit comments

Comments
 (0)