From 0bbba7bd1ef2acb6bec8cfac0ca3809bd308d0ac Mon Sep 17 00:00:00 2001 From: yoonhyejin <0327jane@gmail.com> Date: Wed, 25 Sep 2024 18:32:15 +0900 Subject: [PATCH] fix: fix action --- .github/workflows/contributor-card.yml | 52 ++++++++++++++------------ 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/.github/workflows/contributor-card.yml b/.github/workflows/contributor-card.yml index e658008..3582717 100644 --- a/.github/workflows/contributor-card.yml +++ b/.github/workflows/contributor-card.yml @@ -2,33 +2,39 @@ name: PR Merge Comment on: pull_request: - types: [opened] - push: + types: [opened, synchronize] # Triggers for any pull request event + push: # Triggers for any push to any branch jobs: post-pr-opened-comment: runs-on: ubuntu-latest steps: - - name: Checkout repository - uses: actions/checkout@v3 + - name: Checkout repository + uses: actions/checkout@v3 - - name: Get and Format Username - run: | - formatted_username=$(echo "${{ github.event.pull_request.user.login }}" | tr '[:upper:]' '[:lower:]' | sed 's/ /-/g') - echo "FORMATTED_USERNAME=$formatted_username" >> $GITHUB_ENV + - name: Get and Format Username (PR only) + if: github.event_name == 'pull_request' # Only runs for pull requests + run: | + formatted_username=$(echo "${{ github.event.pull_request.user.login }}" | tr '[:upper:]' '[:lower:]' | sed 's/ /-/g') + echo "FORMATTED_USERNAME=$formatted_username" >> $GITHUB_ENV - - name: Create Comment - uses: actions/github-script@v6 - with: - script: | - const prUser = process.env.FORMATTED_USERNAME; - const url = `https://datahub-contributor-cards.vercel.app/${prUser}`; - const body = `![Image](downloaded_image.png)\n\n@${prUser} Thank you for opening a pull request!\nVisit your page here: [${url}](${url})`; - - // Create a comment on the PR - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.payload.pull_request.number, - body: body - }); + - name: Create Comment (PR only) + if: github.event_name == 'pull_request' # Only runs for pull requests + uses: actions/github-script@v6 + with: + script: | + if (context.payload.pull_request) { + const prUser = process.env.FORMATTED_USERNAME; + const url = `https://datahub-contributor-cards.vercel.app/${prUser}`; + const body = `![Image](downloaded_image.png)\n\n@${prUser} Thank you for opening a pull request!\nVisit your page here: [${url}](${url})`; + + // Create a comment on the PR + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + body: body + }); + } else { + console.log('Not a pull request event.'); + } \ No newline at end of file