|
1 | 1 | name: pr-first-response
|
2 | 2 |
|
3 | 3 | on:
|
4 |
| - pull_request: |
| 4 | + pull_request_target: |
5 | 5 | types: [opened]
|
6 | 6 |
|
7 |
| -jobs: |
| 7 | +jobs: |
8 | 8 | send-response:
|
9 | 9 | runs-on: ubuntu-latest
|
| 10 | + permissions: |
| 11 | + issues: write |
| 12 | + pull-requests: write |
10 | 13 | steps:
|
11 |
| - - name: Fetch random comment 🗣️ |
12 |
| - |
13 |
| - with: |
14 |
| - ENDPOINT: https://collaboratorsv2.euwest01.umbraco.io/umbraco/api/comments/PostComment |
15 |
| - CONFIGURATION: '{ "method": "POST", "headers": {"Authorization": "Bearer ${{ secrets.OUR_BOT_API_TOKEN }}", "Content-Type": "application/json" }, "body": { "repo": "${{ github.repository }}", "number": "${{ github.event.number }}", "actor": "${{ github.actor }}", "commentType": "opened-pr-first-comment"} }' |
16 |
| - - name: Add PR comment |
17 |
| - if: "${{ env.fetch-api-data != '' }}" |
18 |
| - uses: actions/github-script@v5 |
| 14 | + - name: Install dependencies |
| 15 | + run: | |
| 16 | + npm install node-fetch@2 |
| 17 | + - name: Fetch random comment 🗣️ and add it to the PR |
| 18 | + uses: actions/github-script@v6 |
19 | 19 | with:
|
20 | 20 | script: |
|
21 |
| - github.rest.issues.createComment({ |
22 |
| - issue_number: context.issue.number, |
23 |
| - owner: context.repo.owner, |
24 |
| - repo: context.repo.repo, |
25 |
| - body: `${{ env.fetch-api-data }}` |
26 |
| - }) |
| 21 | + const fetch = require('node-fetch') |
| 22 | +
|
| 23 | + const response = await fetch('https://collaboratorsv2.euwest01.umbraco.io/umbraco/api/comments/PostComment', { |
| 24 | + method: 'post', |
| 25 | + body: JSON.stringify({ |
| 26 | + repo: '${{ github.repository }}', |
| 27 | + number: '${{ github.event.number }}', |
| 28 | + actor: '${{ github.actor }}', |
| 29 | + commentType: 'opened-pr-first-comment' |
| 30 | + }), |
| 31 | + headers: { |
| 32 | + 'Authorization': 'Bearer ${{ secrets.OUR_BOT_API_TOKEN }}', |
| 33 | + 'Content-Type': 'application/json' |
| 34 | + } |
| 35 | + }); |
| 36 | +
|
| 37 | + try { |
| 38 | + const data = await response.text(); |
| 39 | +
|
| 40 | + if(response.status === 200 && data !== '') { |
| 41 | + github.rest.issues.createComment({ |
| 42 | + issue_number: context.issue.number, |
| 43 | + owner: context.repo.owner, |
| 44 | + repo: context.repo.repo, |
| 45 | + body: data |
| 46 | + }); |
| 47 | + } else { |
| 48 | + console.log("Status code did not indicate success:", response.status); |
| 49 | + console.log("Returned data:", data); |
| 50 | + } |
| 51 | + } catch(error) { |
| 52 | + console.log(error); |
| 53 | + } |
0 commit comments