forked from oamg/convert2rhel
-
Notifications
You must be signed in to change notification settings - Fork 0
43 lines (38 loc) · 1.56 KB
/
jira-links.yml
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
---
name: Handle release
on:
release:
types: [published]
jobs:
update_jira_links:
name: Update Jira links
if: ${{ github.event_name == 'release' }}
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
steps:
- name: Get release content
run: gh release view ${{github.ref_name}} --json body --jq '.body' > releaseBody.txt
- name: Add Jira links
shell: python
run: |
import re
# RegEx explained
# (?<!\/) Negative lookbehind of / to avoid grabbing URLs
# ((?:RHELC?|HMS)-\d+) Get HMS, RHEL or RHELC keys, add to a group
# \b Word boundary to indicate this should be the end of the match
# (?!\]\() Negative lookahead of ]( to prevent Jira keys in markdown links
regex=re.compile(r"(?<!\/)((?:RHELC?|HMS)-\d+)\b(?!\]\()", re.MULTILINE)
with open("releaseBody.txt", 'r+') as f:
data = f.read()
f.seek(0)
# RegEx explained
# Replace the grabbed Jira key with a Markdown link [key](i.r.c/browse/key)
# [\g<0>] Add the Jira key group 0, equivalent of \1
# (https://issues.redhat.com/browse/\g<0>) Add the Jira key group 0, equivalent of \1, to end of URL
body = regex.sub(r"[\g<0>](https://issues.redhat.com/browse/\g<0>)", data)
f.write(body)
f.truncate()
- name: Update release body with Jira links
run: gh release edit ${{github.ref_name}} --notes-file releaseBody.txt