-
Notifications
You must be signed in to change notification settings - Fork 10
42 lines (36 loc) · 1.38 KB
/
update-pr-description.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
name: Update PR Description
on:
pull_request:
types: [opened]
jobs:
update-description:
runs-on: ubuntu-latest
steps:
- name: Update PR Description
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const branchName = context.payload.pull_request.head.ref;
const prNumber = context.payload.pull_request.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
const { data: prData } = await github.rest.pulls.get({
owner: owner,
repo: repo,
pull_number: prNumber
});
let body = prData.body;
const issueNumberMatch = branchName.match(/feature\/(\d+)/);
const issueNumber = issueNumberMatch ? issueNumberMatch[1] : '';
if (issueNumber) {
body = prData.body.replace(/{issue-number}/g, issueNumber);
}
const branchNameCropped = branchName.split('feature/')[1];
body = prData.body.replace(/{branch-name}/g, branchNameCropped);
await github.rest.pulls.update({
owner: owner,
repo: repo,
pull_number: prNumber,
body: body
});