Last active
January 5, 2023 07:24
-
-
Save ad2ien/a335f9d405bce05ec6f6ad324afdd675 to your computer and use it in GitHub Desktop.
Create a PR adding a file in several projects
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
#! /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 |
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
#!/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!" |
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
#! /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 |
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
#! /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