Skip to content

Commit 62646a0

Browse files
committed
Use GH CLI, check for existing trailers and clean up code
Use GH CLI in place of manual CURL calls, add check for existing trailers and clean up code logic: - Use GH CLI to fetch and parse PR information - Use `action/checkout` to checkout the PR branch and add `token` input to properly handle checkout access permissions - Add step to check if trailers exist and avoid re-adding existing trailers. Add inputs to control if the action will only check for the existence of required trailers and, optionally, fail if the trailers do not exist. Add output with the check result, updated by the addition of the trailers. - Improve user parsing by stripping '[bot]' from fetched app/bot logins and searching in both user-info keys and names for bot users - Clean up steps, variable names and use `GITHUB_OUTPUT` instead of `GITHUB_ENV` Signed-off-by: Kostis Papazafeiropoulos <papazof@gmail.com>
1 parent 19ab918 commit 62646a0

4 files changed

Lines changed: 302 additions & 206 deletions

File tree

README.md

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
This action parses the PR branch and PR info and adds git trailers
2-
to persist PR metadata history in the commit messages.
1+
# git-trailers
32

4-
Example usage:
3+
This action parses information for a pull request and adds git trailers to
4+
persist PR metadata history in the commit messages.
55

6-
Create a workflow file for an action to be triggered on PR approval.
6+
## Example usage
7+
8+
Create a workflow to run the action on PR approval.
79

810
eg:
9-
`.github/workflows/pr-approve.yml`:
11+
`.github/workflows/pr-approval.yml`:
1012

11-
```
13+
```yaml
1214
name: Add Git trailers for PRs
1315

1416
on:
@@ -17,24 +19,15 @@ on:
1719

1820
jobs:
1921
git-trailers:
20-
runs-on: [self-hosted]
2122
if: github.event.review.state == 'approved'
22-
23+
runs-on: ubuntu-latest
24+
permissions:
25+
contents: write
2326
steps:
24-
- name: Cleanup previous jobs
25-
run: |
26-
echo "Cleaning up previous runs"
27-
sudo rm -rf ${{ github.workspace }}/*
28-
sudo rm -rf ${{ github.workspace }}/.??*
29-
30-
- name: Checkout Repository
31-
uses: actions/checkout@v2
32-
with:
33-
fetch-depth: 0
34-
35-
- name: Do git-trailers
36-
uses: nubificus/git-trailers@v1
27+
- name: Add git trailers
28+
uses: nubificus/git-trailers@feat_gh_checkout_rebase
3729
```
3830
39-
Upon approval, the action would overwrite current commits against `main` (or `master`)
40-
adding trailers for reviewers, approvers and the PR#.
31+
Upon approval, the action will edit the PR commit messages adding trailers for
32+
the PR number, reviewers and approvers and update the PR (by force-pushing the
33+
final branch).

0 commit comments

Comments
 (0)