forked from laravel/laravel
-
Notifications
You must be signed in to change notification settings - Fork 2
67 lines (57 loc) · 2.24 KB
/
set-pr-title.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
name: Set PR title
on:
pull_request:
types:
- opened
jobs:
set-title:
runs-on: ubuntu-latest
if: github.actor != 'dependabot[bot]'
steps:
- name: Set PR title
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { owner, repo, number: pull_number } = context.issue;
const pr = context.payload.pull_request;
const body = pr.body || '';
const branchName = pr.head.ref;
const baseBranch = pr.base.ref;
const changeTypes = {
feature: '- [x] 💎 Feature',
bugfix: '- [x] 🐛 Bug Fix',
hotfix: '- [x] 🔥 Hot Fix',
release: '- [x] 🚀 Release',
};
const format = (str, ...args) => {
return str.replace(/{(\d+)}/g, (match, number) => {
return typeof args[number] !== 'undefined' ? args[number] : match;
});
};
const today = new Date();
let title = `Invalid branch name 👀 (type/task-id/description)`;
let updatedBody = body;
if (["main", "master"].includes(baseBranch)) {
title = `[Release] vX.X.X 🚀 - ${today.toLocaleDateString('en-GB')}`;
updatedBody = '';
} else if (["main", "master", "staging", "develop", "demo"].includes(branchName)) {
title = `Merge from ${branchName} to ${baseBranch}`;
} else {
try {
const [type, id, description] = branchName.split('/');
const templateTitle = description.split("-").join(' ').replace(/\b\w/g, (l) => l.toUpperCase());
const taskCode = id.startsWith("CU-") ? id.split("CU-").join('') : id;
const typeOfChange = changeTypes[type] || '- [ ] Unknown Type';
title = `[${id}] ${templateTitle}`;
updatedBody = format(body, templateTitle, id, taskCode, typeOfChange);
} catch (e) {
}
}
await github.rest.pulls.update({
owner,
repo,
pull_number,
title,
body: updatedBody
});