forked from x402-foundation/x402
-
Notifications
You must be signed in to change notification settings - Fork 0
125 lines (112 loc) · 4.07 KB
/
Copy pathlabeler.yml
File metadata and controls
125 lines (112 loc) · 4.07 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
name: "Pull Request Labeler"
on:
pull_request_target:
types: [opened, reopened, synchronize]
permissions:
contents: read
pull-requests: write
issues: write
id-token: none
jobs:
labeler:
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9 # v5.0.0
with:
sync-labels: true
check-verified-commits:
needs: labeler
runs-on: ubuntu-latest
steps:
- name: Ensure commits are verified
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
with:
script: |
const { owner, repo } = context.repo;
const pullRequest = context.payload.pull_request;
const marker = '<!-- verified-commits-required -->';
const unverifiedLabel = 'unverified';
const ignoreNotFound = error => {
if (error.status !== 404) {
throw error;
}
};
const commits = await github.paginate(github.rest.pulls.listCommits, {
owner,
repo,
pull_number: pullRequest.number,
per_page: 100
});
const unverifiedCommits = commits.filter(commit => !commit.commit.verification?.verified);
if (unverifiedCommits.length === 0) {
await github.rest.issues.removeLabel({
owner,
repo,
issue_number: pullRequest.number,
name: unverifiedLabel
}).catch(ignoreNotFound);
core.notice('All pull request commits are verified.');
return;
}
await github.rest.issues.getLabel({
owner,
repo,
name: unverifiedLabel
}).catch(async error => {
if (error.status !== 404) {
throw error;
}
await github.rest.issues.createLabel({
owner,
repo,
name: unverifiedLabel,
color: 'd73a4a',
description: 'Pull request contains unverified commits'
});
});
await github.rest.issues.addLabels({
owner,
repo,
issue_number: pullRequest.number,
labels: [unverifiedLabel]
});
const commitList = unverifiedCommits
.map(commit => '- `' + commit.sha.slice(0, 7) + '`: ' + (commit.commit.verification?.reason || 'unverified'))
.join('\n');
const body = [
marker,
'Thanks for your contribution @' + pullRequest.user.login + '!',
'Note that we require commit signing, please rebase and verify your commits.',
'',
'See here for instructions: https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification',
'',
'The team will not review this PR before ALL commits have been verified and it will be closed after 1 week of inactivity.',
'',
'Unverified commits:',
commitList
].join('\n');
const comments = await github.paginate(github.rest.issues.listComments, {
owner,
repo,
issue_number: pullRequest.number,
per_page: 100
});
const existingComment = comments.find(comment => (
comment.user.type === 'Bot' && comment.body.includes(marker)
));
if (existingComment) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existingComment.id,
body
});
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number: pullRequest.number,
body
});
}
core.setFailed('Pull request contains unverified commits.');