From 990e696a72dfd2129259e857cc463db385433f72 Mon Sep 17 00:00:00 2001 From: pixelass Date: Wed, 21 Feb 2024 15:17:24 +0100 Subject: [PATCH 1/5] chore: set pr title --- .github/workflows/set-pr-title.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .github/workflows/set-pr-title.yml diff --git a/.github/workflows/set-pr-title.yml b/.github/workflows/set-pr-title.yml new file mode 100644 index 000000000..e69de29bb From 39ec6b43a27c66ab876620d4e625cda53823c807 Mon Sep 17 00:00:00 2001 From: pixelass Date: Wed, 21 Feb 2024 15:17:45 +0100 Subject: [PATCH 2/5] chore: add workflow logic --- .github/workflows/set-pr-title.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/.github/workflows/set-pr-title.yml b/.github/workflows/set-pr-title.yml index e69de29bb..78ceb7c74 100644 --- a/.github/workflows/set-pr-title.yml +++ b/.github/workflows/set-pr-title.yml @@ -0,0 +1,23 @@ +name: Set PR Title to First Commit Message + +on: + pull_request: + types: [opened, synchronize] + +jobs: + set-pr-title: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Get first commit message + run: echo "FIRST_COMMIT_MESSAGE=$(git log --format=%B -n 1 $(git rev-list --max-parents=0 HEAD))" >> $GITHUB_ENV + + - name: Update PR title + run: | + gh pr edit "$PR_NUMBER" --title "$FIRST_COMMIT_MESSAGE" + env: + FIRST_COMMIT_MESSAGE: ${{ env.FIRST_COMMIT_MESSAGE }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_NUMBER: ${{ github.event.pull_request.number }} From 8281b4c53c9448cb7ae0d864ded367f976d22a8d Mon Sep 17 00:00:00 2001 From: pixelass Date: Wed, 21 Feb 2024 15:19:36 +0100 Subject: [PATCH 3/5] chore: adjust workflow --- .github/workflows/set-pr-title.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/set-pr-title.yml b/.github/workflows/set-pr-title.yml index 78ceb7c74..0970f8400 100644 --- a/.github/workflows/set-pr-title.yml +++ b/.github/workflows/set-pr-title.yml @@ -19,5 +19,4 @@ jobs: gh pr edit "$PR_NUMBER" --title "$FIRST_COMMIT_MESSAGE" env: FIRST_COMMIT_MESSAGE: ${{ env.FIRST_COMMIT_MESSAGE }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} PR_NUMBER: ${{ github.event.pull_request.number }} From 42407f5d6f565c10d62a11575f4f141f6979f899 Mon Sep 17 00:00:00 2001 From: pixelass Date: Wed, 21 Feb 2024 15:31:41 +0100 Subject: [PATCH 4/5] chore: adjust workflow --- .github/workflows/set-pr-title.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/set-pr-title.yml b/.github/workflows/set-pr-title.yml index 0970f8400..2732135a0 100644 --- a/.github/workflows/set-pr-title.yml +++ b/.github/workflows/set-pr-title.yml @@ -19,4 +19,5 @@ jobs: gh pr edit "$PR_NUMBER" --title "$FIRST_COMMIT_MESSAGE" env: FIRST_COMMIT_MESSAGE: ${{ env.FIRST_COMMIT_MESSAGE }} + GITHUB_TOKEN: ${{ secrets.PIXELASS_PAT_BLIBLA }} PR_NUMBER: ${{ github.event.pull_request.number }} From 17ac9f61787975dc81b0f2d6b6a06eca0156cca0 Mon Sep 17 00:00:00 2001 From: pixelass Date: Wed, 21 Feb 2024 15:35:02 +0100 Subject: [PATCH 5/5] chore: adjust workflow --- .github/workflows/set-pr-title.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/set-pr-title.yml b/.github/workflows/set-pr-title.yml index 2732135a0..6e9b5b05a 100644 --- a/.github/workflows/set-pr-title.yml +++ b/.github/workflows/set-pr-title.yml @@ -10,13 +10,20 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v2 + with: + # Fetches the entire commit history so that we can access the first commit + fetch-depth: 0 - name: Get first commit message - run: echo "FIRST_COMMIT_MESSAGE=$(git log --format=%B -n 1 $(git rev-list --max-parents=0 HEAD))" >> $GITHUB_ENV + run: | + # Get the SHA of the first commit in the PR + FIRST_COMMIT_SHA=$(git log --reverse --format="%H" "${{ github.event.pull_request.base.sha }}..HEAD" | head -n 1) + # Get the message of the first commit in the PR + FIRST_COMMIT_MESSAGE=$(git log -n 1 --format=%B "$FIRST_COMMIT_SHA") + echo "FIRST_COMMIT_MESSAGE=$FIRST_COMMIT_MESSAGE" >> $GITHUB_ENV - name: Update PR title - run: | - gh pr edit "$PR_NUMBER" --title "$FIRST_COMMIT_MESSAGE" + run: gh pr edit "$PR_NUMBER" --title "$FIRST_COMMIT_MESSAGE" env: FIRST_COMMIT_MESSAGE: ${{ env.FIRST_COMMIT_MESSAGE }} GITHUB_TOKEN: ${{ secrets.PIXELASS_PAT_BLIBLA }}