Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
107 lines (97 loc) · 3.29 KB
/
Copy pathaction.yml
File metadata and controls
107 lines (97 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
name: "Add URL to Pull request"
description: "Add environment url to pull request description"
inputs:
url:
description: "URL of Devcloud environment"
required: true
caption:
description: "Override caption for the link"
required: false
fetch:
description: Whether to force PR body fetched via API
type: boolean
required: false
default: false
runs:
using: "composite"
steps:
- name: Get associated pull request
if: ${{ github.event_name == 'push' }}
uses: jwalton/gh-find-current-pr@v1
id: findPr
- name: Add environment link to pull request comment
if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' }}
uses: actions/github-script@v8
with:
script: |
let now = new Date();
console.log(now.toUTCString());
console.log(context.payload)
let url = `${{ inputs.url }}`;
if (! url.startsWith('http')) {
url = `https://${url}`;
}
let caption = '${{ inputs.caption }}'
if (! caption) {
caption = 'View environment ${url}'
}
const snippet = `<h3><a href="${url}">:arrow_forward: ${caption}</a></h3>`
const owner = context.payload.repository.owner.login
const repo = context.payload.repository.name
let fetch_body = '${{ inputs.fetch }}'
let pr;
let body;
if (context.payload.pull_request) {
pr = context.payload.pull_request.number
body = context.payload.pull_request.body
}
else {
pr = '${{ steps.findPr.outputs.number }}'
fetch_body = 'true'
}
if (pr) {
if (fetch_body === 'true') {
console.log(`Fetching description from PR ${pr}`);
if (pr) {
const data = await github
.request('GET /repos/{owner}/{repo}/pulls/{pull_number}', {
owner,
repo,
pull_number: pr,
})
.then(({ data }) => data)
body = data.body;
}
}
else {
console.log(`Updating description from PR ${pr}`);
}
let updatedBody;
console.log(`Body being processed:`);
console.log(body);
if (body) {
if (body.includes(snippet)) {
console.log('Description already includes deployed url');
return 0;
}
console.log(`Adding link to existing body`);
updatedBody = `${body} \n\n ${snippet}`;
}
else {
console.log(`Adding link to empty body`);
updatedBody = `${snippet}`;
}
console.log(`Body being written to PR:`);
console.log(updatedBody);
const updateResponse = await github
.request('PATCH /repos/{owner}/{repo}/pulls/{pull_number}', {
owner,
repo,
pull_number: pr,
body: updatedBody,
})
if (!updateResponse) {
console.log(`Error while updating PR ${pr}`);
return 1;
}
}