-
Notifications
You must be signed in to change notification settings - Fork 51
61 lines (52 loc) · 1.97 KB
/
post-live-url.yml
File metadata and controls
61 lines (52 loc) · 1.97 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
name: Comment live URL on merged publish PR
on:
pull_request:
types: [closed]
branches: [main]
jobs:
post-live-url:
if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'publish/issue-')
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Find content file and build live URL
id: detect
uses: actions/github-script@v7
with:
script: |
const { data: files } = await github.rest.pulls.listFiles({
...context.repo,
pull_number: context.payload.pull_request.number,
});
const contentFile = files.find(f =>
/^src\/content\/(apps|mechanisms|research|case-studies|campaigns)\/.+\.md$/.test(f.filename)
);
if (!contentFile) return;
const [, type, slug] = contentFile.filename.match(
/^src\/content\/(apps|mechanisms|research|case-studies|campaigns)\/(.+)\.md$/
);
core.setOutput('url', `https://gitcoin.co/${type}/${slug}`);
- name: Comment on PR and issue
if: steps.detect.outputs.url
uses: actions/github-script@v7
with:
script: |
const url = '${{ steps.detect.outputs.url }}';
const body = `Live at: ${url}`;
// Comment on the PR
await github.rest.issues.createComment({
...context.repo,
issue_number: context.payload.pull_request.number,
body,
});
// Comment on the original issue (encoded in the branch name)
const branch = context.payload.pull_request.head.ref;
const issueMatch = branch.match(/publish\/issue-(\d+)/);
if (issueMatch) {
await github.rest.issues.createComment({
...context.repo,
issue_number: parseInt(issueMatch[1]),
body,
});
}