Skip to content

Commit bcf4ec2

Browse files
Update pr-first-response.yml
1 parent 0c42260 commit bcf4ec2

File tree

1 file changed

+43
-16
lines changed

1 file changed

+43
-16
lines changed
Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,53 @@
11
name: pr-first-response
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
types: [opened]
66

7-
jobs:
7+
jobs:
88
send-response:
99
runs-on: ubuntu-latest
10+
permissions:
11+
issues: write
12+
pull-requests: write
1013
steps:
11-
- name: Fetch random comment 🗣️
12-
uses: JamesIves/[email protected]
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
1919
with:
2020
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

Comments
 (0)