From d753a45961b6d2becc1fdd65a7373c705a992802 Mon Sep 17 00:00:00 2001 From: andrewstech Date: Wed, 14 Aug 2024 14:38:19 +0100 Subject: [PATCH] Create helper.yml --- .github/workflows/helper.yml | 48 ++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/helper.yml diff --git a/.github/workflows/helper.yml b/.github/workflows/helper.yml new file mode 100644 index 00000000..884d056b --- /dev/null +++ b/.github/workflows/helper.yml @@ -0,0 +1,48 @@ +name: Post Merged.md on PR Close + +on: + pull_request: + types: + - closed + +jobs: + post-merged-md: + runs-on: ubuntu-latest + + steps: + # Check if the PR was merged + - id: create_token + uses: tibdex/github-app-token@v2 + with: + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.PRIVATE_KEY }} + + - name: Check if PR was merged + id: pr-merge-check + uses: actions/github-script@v6 + with: + script: | + return context.payload.pull_request.merged + + # Fetch merged.md content if PR was merged + - name: Fetch merged.md content + if: steps.pr-merge-check.outputs.result == 'true' + run: | + curl -o merged.md https://raw.githubusercontent.com/open-domains/.github/main/merged.md + + # Post the content of merged.md as a comment using the custom token + - name: Post comment on PR + if: steps.pr-merge-check.outputs.result == 'true' + uses: actions/github-script@v6 + env: + GITHUB_TOKEN: ${{ steps.create_token.outputs.token }} + with: + script: | + const fs = require('fs'); + const content = fs.readFileSync('merged.md', 'utf8'); + github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: content + });