Skip to content

Commit

Permalink
feat: verify Releaser status
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Mar 1, 2020
1 parent 8863adc commit 75c2879
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
21 changes: 17 additions & 4 deletions components/git/release.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
'use strict';

const semver = require('semver');
const yargs = require('yargs');

const auth = require('../../lib/auth');
const CLI = require('../../lib/cli');
const Release = require('../../lib/release');
const Request = require('../../lib/request');
const TeamInfo = require('../../lib/team_info');
const { runPromise } = require('../../lib/run');
const yargs = require('yargs');

const PREPARE = 'prepare';
const PROMOTE = 'promote';

const RELEASERS = 'releasers';

const releaseOptions = {
prepare: {
describe: 'Prepare a new release with the given version number',
Expand Down Expand Up @@ -69,8 +74,16 @@ module.exports = {
async function main(state, argv, cli, req, dir) {
const release = new Release(state, argv, cli, req, dir);

// TODO(codebytere): check if this command is being run by
// someone on the Releasers team in GitHub before proceeding.
cli.startSpinner('Verifying Releaser status');
const credentials = await auth({ github: true });
const request = new Request(credentials);
const info = new TeamInfo(cli, request, 'nodejs', RELEASERS);
const releasers = await info.getMembers();
if (!releasers.some(r => r.login === release.username)) {
cli.stopSpinner(`${release.username} is not a Releaser; aborting release`);
return;
}
cli.stopSpinner('Verified Releaser status');

if (state === PREPARE) {
if (release.warnForWrongBranch()) return;
Expand All @@ -91,7 +104,7 @@ async function main(state, argv, cli, req, dir) {
if (!proceed) {
const seeDiff = await cli.prompt(
'Do you want to see the branch diff?', true);
if (seeDiff) console.log(raw);
if (seeDiff) cli.log(raw);
return;
}

Expand Down
14 changes: 5 additions & 9 deletions lib/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ class Release {
// it to their liking.
const created = await this.createReleaseCommit();
if (!created) {
const lastCommitSha = runSync('git', ['rev-parse', '--short', 'HEAD']);
cli.warn(`Please manually edit commit ${lastCommitSha} by running ` +
'`git commit --amend` before proceeding.');

await cli.prompt(
'Type y when you have finished editing the release commit:',
false);
Expand Down Expand Up @@ -346,15 +350,7 @@ class Release {

cli.log(`${messageTitle}\n\n${messageBody.join('')}`);
const useMessage = await cli.prompt('Continue with this commit message?');
if (useMessage) {
return true;
} else {
const lastCommit = runSync('git', ['rev-parse', '--short', 'HEAD']);
cli.warn(`Please manually edit commit ${lastCommit} by running ` +
'`git commit --amend` before proceeding.');
}

return false;
return useMessage;
}

checkBranchDiff(onlyNotableChanges = false) {
Expand Down

0 comments on commit 75c2879

Please sign in to comment.