-
Notifications
You must be signed in to change notification settings - Fork 1
60 lines (53 loc) · 1.76 KB
/
comment-compare-url.yaml
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
name: Comment GitHub diff URL
on:
pull_request:
branches:
- main
types:
- opened
jobs:
comment:
runs-on: ubuntu-latest
permissions:
pull-requests: write
timeout-minutes: 3
if: github.actor == 'renovate[bot]'
steps:
- name: Comment
uses: actions/github-script@v6
with:
script: |
const pullNumber = "${{ github.event.pull_request.number }}"
const pr = await github.rest.pulls.get({
pull_number: pullNumber,
owner: context.repo.owner,
repo: context.repo.repo,
})
console.log(pr.data.body)
const re = /\| .+ \| digest \| `.+` -> `.+` \|\n/
const results = re.exec(pr.data.body)
if (results === null) {
console.log("The description comment does not contain \`digest\`. So skip.")
return
}
/*
Input:
| neovim/nvim-lspconfig | digest | `62856b2` -> `95b7a69` |
Output
repository: neovim/nvim-lspconfig
baseSha: 62856b2
targetSha: 95b7a69
*/
const matched = results[0]
const s = matched.replaceAll(" ", "").replaceAll("`", "").replace("->", "|").split("|")
const repository = s[1]
const baseSha = s[3]
const targetSha = s[4]
const url = `https://github.com/${repository}/compare/${baseSha}...${targetSha}`
const body = `[diff](${url})`
await github.rest.issues.createComment({
issue_number: pullNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
})