Skip to content

Commit

Permalink
feat: add notification for prepare (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eunjae Lee authored Aug 20, 2019
1 parent f923e52 commit c0388cb
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 2 deletions.
20 changes: 20 additions & 0 deletions packages/shipjs-lib/src/lib/config/defaultConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,26 @@ export default {
default: {
username: 'Ship.js',
},
prepared: ({ appName, version, pullRequestUrl }) => ({
pretext: `:writing_hand: The release for *${appName}@${version}* is prepared!`,
fields: [
{
title: 'Branch',
value: 'master',
short: true,
},
{
title: 'Version',
value: version,
short: true,
},
{
title: 'Pull-Request',
value: pullRequestUrl,
short: false,
},
],
}),
releaseStart: ({
appName,
version,
Expand Down
7 changes: 5 additions & 2 deletions packages/shipjs/src/flow/prepare.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { loadConfig } from 'shipjs-lib'; // eslint-disable-line import/no-unresolved
import { getAppName, loadConfig } from 'shipjs-lib'; // eslint-disable-line import/no-unresolved

import printHelp from '../step/prepare/printHelp';
import printDryRunBanner from '../step/printDryRunBanner';
Expand All @@ -16,6 +16,7 @@ import installDependencies from '../step/prepare/installDependencies';
import updateChangelog from '../step/prepare/updateChangelog';
import commitChanges from '../step/prepare/commitChanges';
import createPullRequest from '../step/prepare/createPullRequest';
import notifyPrepared from '../step/prepare/notifyPrepared';
import finished from '../step/finished';

async function prepare({
Expand Down Expand Up @@ -57,7 +58,7 @@ async function prepare({
installDependencies({ config, dir, dryRun });
updateChangelog({ config, firstRelease, releaseCount, dir, dryRun });
await commitChanges({ nextVersion, dir, config, dryRun });
createPullRequest({
const { pullRequestUrl } = createPullRequest({
baseBranch,
stagingBranch,
currentVersion,
Expand All @@ -67,6 +68,8 @@ async function prepare({
dir,
dryRun,
});
const appName = getAppName(dir);
notifyPrepared({ config, appName, version: nextVersion, pullRequestUrl });
finished();
}

Expand Down
3 changes: 3 additions & 0 deletions packages/shipjs/src/step/prepare/createPullRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,12 @@ export default ({
.filter(Boolean)
.join(' ');
run(createPullRequestCommand, dir, dryRun);
const pullRequestUrl = `${repoURL}/pulls`;
print(' |');
message.split('\n').forEach(line => print(` | ${line}`));
print(' |');
print('');

return { pullRequestUrl };
}
);
12 changes: 12 additions & 0 deletions packages/shipjs/src/step/prepare/notifyPrepared.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { notifyPrepared } from '../../util/slack';
import runStep from '../runStep';

export default async ({ config, appName, version, pullRequestUrl }) =>
await runStep({ title: 'Notifying notifyPrepared to Slack' }, async () => {
await notifyPrepared({
config,
appName,
version,
pullRequestUrl,
});
});
23 changes: 23 additions & 0 deletions packages/shipjs/src/util/slack.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@ async function sendSlackMessage({ config, sendArguments }) {
}

// https://api.slack.com/docs/messages/builder
export async function notifyPrepared({
config,
appName,
version,
pullRequestUrl,
}) {
const { slack = {} } = config;
const { prepared } = slack;
if (!prepared) {
return;
}

const sendArguments =
typeof prepared === 'string'
? prepared
: prepared({ appName, version, pullRequestUrl });

await sendSlackMessage({
config,
sendArguments,
});
}

export async function notifyReleaseStart({
config,
appName,
Expand Down

0 comments on commit c0388cb

Please sign in to comment.