Created
July 4, 2020 06:34
-
-
Save amitsingh-007/11d082db693cb65ddaaa56e73e9fa7eb to your computer and use it in GitHub Desktop.
Get base branch name of current pull request raised
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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); | |
console.log("Target branch: ", targetBranch); | |
}, | |
err => { | |
console.log("Failed to fetch PR details. Install Github CLI in order to get base branch / No open PR for this branch"); | |
} | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could you help with how you're using the exec command with .then?
I tried using a promise and shelljs exec (also child_process exec) but the command
gh pr view
gives different output when I ran it on terminal vs in the script.