Skip to content

Instantly share code, notes, and snippets.

View amitsingh-007's full-sized avatar
:octocat:
Working from home

Amit Singh amitsingh-007

:octocat:
Working from home
View GitHub Profile
@amitsingh-007
amitsingh-007 / getCommand.js
Created July 4, 2020 06:56
Construct the command to be executed
const minimist = require("minimist");
const chalk = require("chalk");
const log = console.log;
const error = chalk.bold.red;
const debug = chalk.bold.green;
const info = chalk.rgb(215, 135, 95);
/* argv has all the user arguements
* Visit https://github.com/substack/minimist
@amitsingh-007
amitsingh-007 / fetchBaseBranch.js
Created July 4, 2020 06:45
Fetching base branch on CI as well as on local machine
/*
* Need to add refs and then fetch, as Jenkins does not allow to fetch other barnches
*/
async function fetchBaseBranch(baseBranch) {
try {
console.log("Fetching ${baseBranch} from remote");
const addBaseRefs = `git config --add remote.origin.fetch +refs/heads/${baseBranch}:refs/remotes/origin/${baseBranch}`;
const fetchBase = `git fetch --no-tags origin +refs/heads/${baseBranch}:refs/remotes/origin/${baseBranch}`;
const command = `${addBaseRefs} && ${fetchBase}`;
await exec(command);
@amitsingh-007
amitsingh-007 / getBaseBranchName.js
Created July 4, 2020 06:34
Get base branch name of current pull request raised
/*
* Only works if github cli is installed and logged in
*/
function getPRDetails() {
exec("gh pr view").then(
stdout => {
const response = stdout.toString();
const prDetails = response.match(/into (\S+) from (\S+)/i);
const [, baseBranch, targetBranch] = prDetails;
console.log("Base branch: ", baseBranch);