-
Notifications
You must be signed in to change notification settings - Fork 0
85 lines (75 loc) · 3.08 KB
/
prebuild.yaml
File metadata and controls
85 lines (75 loc) · 3.08 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: Prebuild
on:
pull_request:
types: [opened, synchronize, reopened, edited]
jobs:
validate-pr-title:
runs-on: ubuntu-latest
steps:
- name: PR Conventional Commit Validation
id: check_title
uses: ytanikin/PRConventionalCommits@1.2.0
with:
task_types: '["feat","fix","docs", "deps", "chore"]'
add_label: 'false'
- name: Leave a comment if PR title is invalid
if: ${{ failure() }}
uses: actions/github-script@v7
with:
script: |
const prNumber = context.payload.pull_request.number;
const acceptablePrefixes = ['feat', 'fix', 'docs', 'deps', 'chore'];
const commentIdentifier = '<!-- conventional-commits-comment -->';
const newBody = `${commentIdentifier}\n❌ The PR title does not follow the Conventional Commits format. Please use one of the following prefixes: ${acceptablePrefixes.join(', ')}. For example: \`feat: add new feature\``;
// Get existing comments
const { data: existingComments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
// Find previous bot comment
let botComment = existingComments.find(comment =>
comment.user.login === 'github-actions[bot]' && comment.body.includes(commentIdentifier)
);
if (botComment) {
// Update the existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: newBody,
});
} else {
// Create a new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: newBody,
});
}
- name: Remove comment if PR title is valid
if: ${{ success() }}
uses: actions/github-script@v7
with:
script: |
const prNumber = context.payload.pull_request.number;
const commentIdentifier = '<!-- conventional-commits-comment -->';
// Get existing comments
const { data: existingComments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
// Find previous bot comment
let botComment = existingComments.find(comment =>
comment.user.login === 'github-actions[bot]' && comment.body.includes(commentIdentifier)
);
if (botComment) {
// Delete the existing comment
await github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
});
}