Automate The Creation And Merge Of Pull Requests With gh cli & PowerShell

The aim of this playbook🏁 is to create a snippet for scripting that creates and merges a pull request in the feature branches GitHub workflow. I am using this for things like post-outage configuration amendments where I need to update lots of repositories at once, script-wise. This helps to remove any interactive process, utilizing git & gh cli

I am leaving out the cloning and navigation part for multi-repo manipulations. This is focused primarily on automating the merge of a single-repo.

1. instructions

  • pull possible changes
  • checkout a new branch
  • do the work
  • stage -> commit -> push
  • create and merge the PR
if ("master" -ne ((git branch) -replace "\* ", "")) {git checkout master}
git pull origin
git checkout -b "JIRA-ID/foo_description"

# MAIN CODE CHANGING SOMETHING IN THE REPO

git add "foobar.json"
git commit -m "<ops> config change within foobar.json"
git push -u origin
gh pr create --fill
gh pr merge --merge --delete-branch
  • -u sets origin as a default remote repo
  • --fill helps not to prompt for title/body and just use commit info
  • --merge selects a merge commit, instead of rebase/squash options
  • optional --delete-branch Delete the local and remote branch after merge

2. sources

--

--

Infrastructure Support Engineer/Technical Writer (snowplow.io) with a passion for Python/writing documentation. More about me: https://pavol.kutaj.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Pavol Kutaj

Infrastructure Support Engineer/Technical Writer (snowplow.io) with a passion for Python/writing documentation. More about me: https://pavol.kutaj.com