From ac4ef3b13101a3024848cb88616a2b397b8f3953 Mon Sep 17 00:00:00 2001 From: Mayel de Borniol Date: Wed, 13 Nov 2024 13:26:48 +0000 Subject: [PATCH] Attempt at auto-PR --- .tool-versions | 1 + git-publish.sh | 71 ++++++++++++++++++++++++++++++-------------------- justfile | 22 ++++++++-------- 3 files changed, 55 insertions(+), 39 deletions(-) diff --git a/.tool-versions b/.tool-versions index 2d1234b401..1da94573c7 100644 --- a/.tool-versions +++ b/.tool-versions @@ -5,6 +5,7 @@ elixir 1.17.3-otp-27 # erlang 25.3.2.8 # elixir 1.13.4-otp-25 just 1.35.0 +gh 2.61.0 yarn 1.22.22 nodejs 22.9.0 # chromedriver latest diff --git a/git-publish.sh b/git-publish.sh index d0443f4ea3..9126047454 100755 --- a/git-publish.sh +++ b/git-publish.sh @@ -2,20 +2,44 @@ DIR="${1:-$PWD}" function maybe_rebase { - if [[ $1 == 'pull' ]] - then + if [[ $1 == 'pull' ]]; then git pull --rebase || fail "Please resolve conflicts before continuing." fi - if [[ $1 == 'rebase' ]] - then - rebase + if [[ $1 == 'rebase' ]]; then + # if rebasing we assume that jungle already fetched, so we try to directly rebase + git rebase || fail "Please resolve conflicts before continuing." fi } -function rebase { - # if rebasing we assume that jungle already fetched, so we try to directly rebase - git rebase || fail "Please resolve conflicts before continuing." +function commit { + if [[ $1 == 'pr' ]]; then + echo "Here are the changes you made:" + git diff HEAD + branch_and_commit + else + git commit --verbose --all + fi +} + +function branch_and_commit { + read -p "Enter a description of these changes for the commit and related PR (leave empty to skip these changes for now) and press enter:" comment + if [[ -n "$comment" ]]; then + name=${comment// /_} + sanitized_name=${name//[^a-zA-Z0-9\-_]/} + (git checkout -b "PR-${sanitized_name}" || branch_and_commit) && git commit --all -m "$comment" && gh pr create --fill + else + fail "No comment entered, skipping these changes..." + fi +} + +function post_commit { + # merge/rebase local changes + maybe_rebase $1 + + if [[ $2 != 'only' ]]; then + git push && echo "Published changes!" + fi } function fail { @@ -30,34 +54,25 @@ cd $DIR git config core.fileMode false -# add all changes (including untracked files) -git add --all . set +e # Grep succeeds with nonzero exit codes to show results. -if LC_ALL=en_GB git status | grep -q -E 'Changes|modified|ahead' -then - set -e - - # if there are changes, commit them (needed before being able to rebase) - git diff-index --quiet HEAD || git commit --verbose --all || echo Skipped... +if [ -z "$(git status --porcelain)" ]; then + # there are no changes - # if [[ $2 == 'pull' ]] - # then - # git fetch - # fi + set -e + echo "No local changes to push" - # merge/rebase local changes maybe_rebase $2 - if [[ $3 != 'only' ]] - then - git push && echo "Published changes!" - fi - else + # there are changes set -e - echo "No local changes to push" - maybe_rebase $2 + # add all changes (including untracked files) + git add --all . + + # if there are changes, commit them (needed before being able to rebase) + (commit $3 && post_commit $2 $3) || echo "Skipped..." + fi diff --git a/justfile b/justfile index b2645543e7..fe883bc2ab 100644 --- a/justfile +++ b/justfile @@ -314,10 +314,10 @@ update-deps: _pre-update-deps just mix-remote updates update-repo: _pre-contrib-hooks - @chmod +x git-publish.sh && ./git-publish.sh . pull || git pull + just git-publish . pull || git pull update-repo-pull: - @chmod +x git-publish.sh && ./git-publish.sh . pull only + just git-publish . pull only # Update to the latest Bonfire extensions in ./deps update-deps-bonfire: @@ -350,20 +350,20 @@ update-dep-simple dep: # Pull the latest commits from all forks @update-forks: - (just git-fetch-all && just update-forks-all rebase) || (echo "Fetch all clones with Jungle not available, will fetch one by one instead." && just update-forks-all pull) + (just git-fetch-all && just update-forks-all rebase pr) || (echo "Fetch all clones with Jungle not available, will fetch one by one instead." && just update-forks-all pull pr) -update-forks-all cmd='pull': +update-forks-all cmd='pull' extra='pr': just update-fork-path $EXT_PATH $cmd just update-fork-path $EXTRA_FORKS_PATH $cmd # Pull the latest commits from all forks -update-fork dep cmd='pull' mindepth='0' maxdepth='0': - -just update-fork-path $EXT_PATH/$dep $cmd $mindepth $maxdepth - -just update-fork-path $EXTRA_FORKS_PATH/$dep $cmd $mindepth $maxdepth +update-fork dep cmd='pull' extra='pr' mindepth='0' maxdepth='0': + -just update-fork-path $EXT_PATH/{{dep}} {{cmd}} {{extra}} {{mindepth}} {{maxdepth}} + -just update-fork-path $EXTRA_FORKS_PATH/{{dep}} {{cmd}} {{extra}} {{mindepth}} {{maxdepth}} -update-fork-path path cmd='pull' mindepth='0' maxdepth='1': +update-fork-path path cmd='pull' extra='pr' mindepth='0' maxdepth='1': @chmod +x git-publish.sh - find $path -mindepth $mindepth -maxdepth $maxdepth -type d -exec ./git-publish.sh {} $cmd \; + find {{path}} -mindepth {{mindepth}} -maxdepth {{maxdepth}} -type d -exec ./git-publish.sh {} {{cmd}} {{extra}} \; # Fetch locked versions of deps (Elixir and JS), including ones also cloned locally @deps-fetch *args='': @@ -551,9 +551,9 @@ deps-git-fix: @git-conflicts: find $EXT_PATH -mindepth 1 -maxdepth 1 -type d -exec echo add {} \; -exec git -C '{}' diff --name-only --diff-filter=U \; -@git-publish: +@git-publish dir='.' cmd='pull' extra='pr': chmod +x git-publish.sh - ./git-publish.sh + ./git-publish.sh {{dir}} {{cmd}} {{extra}} #### TESTING RELATED COMMANDS ####