Skip to content

[WIP] git-node: prompt and conditionally auto push #299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions lib/landing_session.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const path = require('path');
const readline = require('readline');

const {
runAsync, runSync, forceRunAsync
Expand All @@ -9,6 +10,21 @@ const Session = require('./session');

const isWindows = process.platform === 'win32';

function asyncQuestion(prid) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can refactor this a bit into a cli.promptForInput that returns the answer for later use

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So waiting for #300

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

return new Promise((resolve) => {
const q = `If you would you like to push upstream now, please type ${prid}`;
rl.question(q, (answer) => {
resolve(answer === String(prid));
rl.close();
});
});
}

class LandingSession extends Session {
constructor(cli, req, dir, prid, config) {
super(dir, prid, config);
Expand Down Expand Up @@ -205,7 +221,7 @@ class LandingSession extends Session {
cli.log('A git rebase/am is in progress.' +
' Please complete it before running git node land --final');
return;
};
}

const notYetPushed = this.getNotYetPushedCommits();
const notYetPushedVerbose = this.getNotYetPushedCommits(true);
Expand All @@ -227,10 +243,20 @@ class LandingSession extends Session {
willBeLanded = `${head}...${willBeLanded}`;
}

cli.log('To finish landing:');
cli.log(`1. Run \`git push ${upstream} ${branch}\``);
const url = `https://github.com/${owner}/${repo}/pull/${prid}`;
cli.log(`2. Post in ${url}: \`Landed in ${willBeLanded}\``);
const pushCommandArgs = ['push', upstream, branch];
const prUrl = `https://github.com/${owner}/${repo}/pull/${prid}`;
const landComment = `Post in ${prUrl}: \`Landed in ${willBeLanded}\``;
const autoLand = await asyncQuestion(prid);
if (autoLand) {
await runAsync('git', pushCommandArgs, { ignoreFailure: false });
cli.log('Last step to finish landing:');
// TODO auto-comment
cli.log(landComment);
} else {
cli.log('To finish landing:');
cli.log(`1. Run \`git ${pushCommandArgs.join(' ')}\``);
cli.log(`2. ${landComment}`);
}

const shouldClean = await cli.prompt('Clean up generated temporary files?');
if (shouldClean) {
Expand Down