Skip to content

Instantly share code, notes, and snippets.

@ad2ien
Last active January 5, 2023 07:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ad2ien/a335f9d405bce05ec6f6ad324afdd675 to your computer and use it in GitHub Desktop.
Save ad2ien/a335f9d405bce05ec6f6ad324afdd675 to your computer and use it in GitHub Desktop.
Create a PR adding a file in several projects
#! /bin/bash
set -eu
FILE_TO_ADD='xxx.xx'
TARGET='file/path/xxx.xx'
BRANCH='chore/add-feature'
COMMIT='chore: do stuff'
PR_TITLE='Yet an other PR'
PR_BODY='pr-body.md'
REPOS='HEAPS OF SPACE SEPARATED REPO'
# Or if you fancy :
# REPOS=$(gh repo list ${ORGA} --visibility public --source --limit 100 --no-archived --json name --template '{{range .}}{{ .name }} {{end}}')
ORG='org'
WORKDIR='workdir'
rm -rf $WORKDIR
mkdir $WORKDIR
(
cd $WORKDIR
for repo in $REPOS; do
git clone "git@github.com:${ORG}/${repo}.git"
(
cd $repo
git checkout -b $BRANCH
cp ../../$FILE_TO_ADD $TARGET
git add $TARGET
git commit -m "$COMMIT"
git push -u origin $BRANCH
gh pr create \
--base main \
--title "$PR_TITLE" \
--body-file ../../$PR_BODY \
--assignee "@me" \
--reviewer "XXX,YYY"
)
done
)
# Then for merging:
# for repo in $REPOS; do
# gh pr merge --repo $ORG/$repo --merge -d $BRANCH
# done
#!/bin/zsh
set -eu
# - make sure gh, github cli is logged in
# - create a file PR-body.md with the description of your PR
WORKDIR='workdir'
PR_BODY=PR-body.md
REVIEWERS="xxx,yyy"
BRANCH_NAME="docs/fix-badges"
ORG=
REPOS=($(gh repo list ${ORG} --source --limit 150 --source --no-archived --json name --template '{{range .}}{{ .name }} {{end}}'))
echo "πŸ› οΈ Start fixing worflow badges..."
rm -rf $WORKDIR
mkdir $WORKDIR
cd $WORKDIR
for repo in $REPOS; do
echo "πŸ–οΈ Processing ${repo}"
git clone "git@github.com:${ORG}/${repo}" --depth 1
(
cd $repo
if [ ! -f "README.md" ]; then
echo "README.md doesn't exist ⏭️"
continue
fi
if [ -n "$(git ls-remote --heads git@github.com:${ORG}/${repo}.git ${BRANCH_NAME})" ]; then
echo "branch already exist for this repo ⏭️"
continue
fi
sed -i 's/https:\/\/img.shields.io\/github\/workflow\/status\//https:\/\/img.shields.io\/github\/actions\/workflow\/status\//g' README.md
sed -i 's/\/Lint?/\/lint.yml?branch=main\&/g' README.md
sed -i 's/\/Test?/\/test.yml?branch=main\&/g' README.md
sed -i 's/\/Build?/\/build.yml?branch=main\&/g' README.md
sed -i 's/\/Publish?/\/publish.yml?branch=main\&/g' README.md
if [ -z $(git diff README.md) ]; then
echo "No diff in README ⏭️"
continue
else
echo "Create the PR..."
git checkout -b ${BRANCH_NAME}
git add README.md
git commit -m "docs: fix github workflow badges πŸ€–"
git push -u origin ${BRANCH_NAME}
gh pr create \
--base main \
--head ${BRANCH_NAME} \
--title "docs: fix github workflow badges πŸ€–" \
--body-file ../../$PR_BODY \
--assignee "@me" \
--reviewer "${REVIEWERS}"
echo "πŸš€ PR created"
fi
)
done
echo "🏁 Finished!"
#! /bin/bash
set -eu
BRANCH=''
ORG='okp4'
USER=ad2ien
REPOS=$(gh repo list ${ORG} --source --limit 150 --no-archived --json name --template '{{range .}}{{ .name }} {{end}}')
echo $REPOS
for repo in $REPOS; do
echo $repo
state=$(gh pr view $BRANCH --repo $ORG/$repo --json state | jq ".state")
if [[ $state == "" ]]; then
echo " -> no PR"
continue
fi
result=$(gh pr view $BRANCH --repo $ORG/$repo --json reviews | jq ".reviews[] | select(.author.login==\"$USER\") | .state")
if [[ $result == *"APPROVED"* ]]; then
echo " -> Already approved"
else
gh pr review $BRANCH -a -b "LGTM! πŸ‘¨β€πŸ­ _(it may be a scripted message)_" --repo $ORG/$repo
fi
done
#! /bin/bash
set -eu
BRANCH=
ORG=
REPOS=$(gh repo list ${ORG} --source --limit 150 --no-archived --json name --template '{{range .}}{{ .name }} {{end}}')
echo "βš™οΈ start merging PR..."
for repo in $REPOS; do
echo "πŸ–οΈ Processing ${repo}"
state=$(gh pr view $BRANCH --repo $ORG/$repo --json state | jq ".state")
if [[ $state == "" ]]; then
echo "PR not found ⏭️"
continue
elif [[ $state == *"MERGED"* ]]; then
echo "PR already merged ⏭️"
continue
fi
result=$(gh pr view $BRANCH --repo $ORG/$repo --json reviewDecision | jq ".reviewDecision")
if [[ $result == *"APPROVED"* ]]; then
echo "πŸš€ Let's merge.."
gh pr merge $BRANCH --repo $ORG/$repo --merge --delete-branch
else
echo "πŸ™… Not ready : $result"
fi
done
echo "🏁 Finished!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment