Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Autosquash #24

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
.idea
*.iml
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 10 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 malicious commands
if [[ $(jq -r ".comment.body" "$GITHUB_EVENT_PATH" | grep -Fq "/rebase --autosquash") -eq 0 ]]; then
git rebase --interactive --autosquash origin/$BASE_BRANCH
Copy link

@grepsedawk grepsedawk Oct 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to use the interactive flag here, that will pop open an editor and expect "user input"
Edit: nevermind re-read

else
git rebase origin/$BASE_BRANCH
fi

# push back
git push --force-with-lease fork fork/$HEAD_BRANCH:$HEAD_BRANCH