From e60488c980879bbf624dd355cc2380f12fa03621 Mon Sep 17 00:00:00 2001 From: fedor Date: Sun, 17 Nov 2019 22:10:18 -0500 Subject: [PATCH 1/5] Support rebase --autosquash --- .gitignore | 3 ++- entrypoint.sh | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 723ef36..29b636a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.idea \ No newline at end of file +.idea +*.iml \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh index a3afb4a..0301c7c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -50,7 +50,7 @@ BASE_REPO=$(echo "$pr_resp" | jq -r .base.repo.full_name) BASE_BRANCH=$(echo "$pr_resp" | jq -r .base.ref) USER_LOGIN=$(jq -r ".comment.user.login" "$GITHUB_EVENT_PATH") - + if [[ "$USER_LOGIN" == "null" ]]; then USER_LOGIN=$(jq -r ".pull_request.user.login" "$GITHUB_EVENT_PATH") fi @@ -97,7 +97,13 @@ git fetch fork $HEAD_BRANCH # do the rebase git checkout -b fork/$HEAD_BRANCH fork/$HEAD_BRANCH -git rebase origin/$BASE_BRANCH + +# Do an exact check instead of `rebase *` so it's not possible to inject malisios commands +if [[ $(jq -r ".comment.body" "$GITHUB_EVENT_PATH" | grep -Fq "/rebase --autosquash") -eq 0 ]]; then + git rebase --autosquash origin/$BASE_BRANCH +else + git rebase origin/$BASE_BRANCH +fi # push back git push --force-with-lease fork fork/$HEAD_BRANCH:$HEAD_BRANCH From 46c232561eb92325e4ed6c88020431c01391c6ee Mon Sep 17 00:00:00 2001 From: fedor Date: Sun, 17 Nov 2019 22:22:55 -0500 Subject: [PATCH 2/5] Update docs --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2667b7f..c78d78f 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,15 @@ [![Build Status](https://api.cirrus-ci.com/github/cirrus-actions/rebase.svg)](https://cirrus-ci.com/github/cirrus-actions/rebase) [![](https://images.microbadger.com/badges/version/cirrusactions/rebase.svg)](https://microbadger.com/images/cirrusactions/rebase) [![](https://images.microbadger.com/badges/image/cirrusactions/rebase.svg)](https://microbadger.com/images/cirrusactions/rebase) -After installation simply comment `/rebase` to trigger the action: +After [installation](#installation) simply comment `/rebase` to trigger the action: ![rebase-action](https://user-images.githubusercontent.com/989066/51547853-14a57b00-1e35-11e9-841d-33114f0f0bd5.gif) +# Supported Comments + +* `/rebase` - to perform the default rebase. +* `/rebase --autosquash` - to perform a rebase with `--autosquash` argument. + # Installation To configure the action simply add the following lines to your `.github/workflows/rebase.yml` workflow file: From 1b6e7110e24d57dd6c61637083e76a29430d92e5 Mon Sep 17 00:00:00 2001 From: fedor Date: Sun, 17 Nov 2019 22:24:11 -0500 Subject: [PATCH 3/5] reformat --- entrypoint.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 0301c7c..7b91d18 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -16,8 +16,8 @@ fi echo "Collecting information about PR #$PR_NUMBER of $GITHUB_REPOSITORY..." if [[ -z "$GITHUB_TOKEN" ]]; then - echo "Set the GITHUB_TOKEN env variable." - exit 1 + echo "Set the GITHUB_TOKEN env variable." + exit 1 fi URI=https://api.github.com @@ -100,7 +100,7 @@ git checkout -b fork/$HEAD_BRANCH fork/$HEAD_BRANCH # Do an exact check instead of `rebase *` so it's not possible to inject malisios commands if [[ $(jq -r ".comment.body" "$GITHUB_EVENT_PATH" | grep -Fq "/rebase --autosquash") -eq 0 ]]; then - git rebase --autosquash origin/$BASE_BRANCH + git rebase --autosquash origin/$BASE_BRANCH else git rebase origin/$BASE_BRANCH fi From 0edb3c742164297e6c79b09448e72afde51f7316 Mon Sep 17 00:00:00 2001 From: Fedor Korotkov Date: Tue, 10 Dec 2019 15:00:38 -0500 Subject: [PATCH 4/5] Fixed typo Co-Authored-By: John R Barker --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 7b91d18..7e045be 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -98,7 +98,7 @@ git fetch fork $HEAD_BRANCH # do the rebase git checkout -b fork/$HEAD_BRANCH fork/$HEAD_BRANCH -# Do an exact check instead of `rebase *` so it's not possible to inject malisios commands +# Do an exact check instead of `rebase *` so it's not possible to inject malicious commands if [[ $(jq -r ".comment.body" "$GITHUB_EVENT_PATH" | grep -Fq "/rebase --autosquash") -eq 0 ]]; then git rebase --autosquash origin/$BASE_BRANCH else From 92698737864c38c29b2adcad98b5687aed189d72 Mon Sep 17 00:00:00 2001 From: Fedor Korotkov Date: Tue, 6 Jul 2021 09:10:02 -0400 Subject: [PATCH 5/5] --interactive --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 7e045be..bff70a9 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -100,7 +100,7 @@ git checkout -b fork/$HEAD_BRANCH fork/$HEAD_BRANCH # Do an exact check instead of `rebase *` so it's not possible to inject malicious commands if [[ $(jq -r ".comment.body" "$GITHUB_EVENT_PATH" | grep -Fq "/rebase --autosquash") -eq 0 ]]; then - git rebase --autosquash origin/$BASE_BRANCH + git rebase --interactive --autosquash origin/$BASE_BRANCH else git rebase origin/$BASE_BRANCH fi