diff --git a/.github/workflows/add-contributor-on-merge.yml b/.github/workflows/add-contributor-on-merge.yml index 0dcea3c..4a97680 100644 --- a/.github/workflows/add-contributor-on-merge.yml +++ b/.github/workflows/add-contributor-on-merge.yml @@ -4,14 +4,16 @@ on: pull_request: types: - closed + push: + branches: + - main permissions: contents: write - jobs: add-contributor: - if: github.event.pull_request.merged == true + if: github.event_name == 'push' || github.event.pull_request.merged == true runs-on: ubuntu-latest steps: - name: Checkout repo @@ -23,9 +25,15 @@ jobs: node-version: 20 - name: Get PR author username + if: github.event_name == 'pull_request' id: get_author run: echo "username=${{ github.event.pull_request.user.login }}" >> $GITHUB_OUTPUT + - name: Get committer username (for push) + if: github.event_name == 'push' + id: get_author + run: echo "username=${{ github.actor }}" >> $GITHUB_OUTPUT + - name: Add contributor to README env: CONTRIBUTOR_USERNAME: ${{ steps.get_author.outputs.username }} @@ -36,4 +44,4 @@ jobs: uses: stefanzweifel/git-auto-commit-action@v5 with: commit_message: "chore: add ${{ steps.get_author.outputs.username }} to Contributors in README" - branch: ${{ github.event.pull_request.base.ref }} + branch: main