Skip to content

Commit

Permalink
Attempt at auto-PR
Browse files Browse the repository at this point in the history
  • Loading branch information
mayel committed Nov 13, 2024
1 parent 5ea2029 commit ac4ef3b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 39 deletions.
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
71 changes: 43 additions & 28 deletions git-publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
22 changes: 11 additions & 11 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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='':
Expand Down Expand Up @@ -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 ####

Expand Down

0 comments on commit ac4ef3b

Please sign in to comment.