This repository was archived by the owner on Feb 12, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
183 lines (160 loc) Β· 6.25 KB
/
bot.yml
File metadata and controls
183 lines (160 loc) Β· 6.25 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
name: DevHub Bot
on:
workflow_call:
inputs:
thank_you_message:
required: false
default: "Thank you for opening this PR! Repo maintainers will review it ASAP π"
type: string
merge_thank_you_message:
required: false
default: "π Thank you for contributing! We really appreciate your work."
type: string
cc_warning_message:
required: false
default: "β οΈ Please consider using Conventional Commits (e.g. feat:, fix:, docs:).\nhttps://www.conventionalcommits.org/en/v1.0.0/"
type: string
secrets:
DEVHUB_APP_ID:
required: false
DEVHUB_APP_PRIVATE_KEY:
required: false
jobs:
pr-handler:
runs-on: ubuntu-latest
if: github.event.pull_request != null
steps:
- name: Checkout base branch
uses: actions/checkout@v5
with:
ref: ${{ github.event.pull_request.base.ref }}
fetch-depth: 0
persist-credentials: false
- name: Generate DevHub Bot token
if: ${{ secrets.DEVHUB_APP_ID && secrets.DEVHUB_APP_PRIVATE_KEY }}
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.DEVHUB_APP_ID }}
private-key: ${{ secrets.DEVHUB_APP_PRIVATE_KEY }}
- name: Fetch PR commits
id: commits
uses: actions/github-script@v7
with:
github-token: ${{ steps.app-token.outputs.token || github.token }}
script: |
const commits = await github.paginate(
github.rest.pulls.listCommits,
{
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number
}
);
core.setOutput("messages", JSON.stringify(commits.map(c => c.commit.message)));
- name: Check CC compliance
id: analyze
run: |
echo '${{ steps.commits.outputs.messages }}' > commits.json
NON_CC=false
regex='^(feat|fix|docs|style|refactor|perf|test|chore)(\(.+\))?:\ .+'
while read -r msg; do
if [[ ! "$msg" =~ $regex ]]; then
NON_CC=true
break
fi
done < <(jq -r '.[]' commits.json)
echo "non_cc=$NON_CC" >> $GITHUB_OUTPUT
- name: Comment PR
uses: actions/github-script@v7
with:
github-token: ${{ steps.app-token.outputs.token || github.token }}
script: |
const nonCC = "${{ steps.analyze.outputs.non_cc }}" === "true";
const body = nonCC
? `${{ inputs.cc_warning_message }}`
: `${{ inputs.thank_you_message }}`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body
});
pr-merged:
runs-on: ubuntu-latest
if: github.event.pull_request != null && github.event.pull_request.merged == true
steps:
- uses: actions/checkout@v5
with:
ref: ${{ github.event.pull_request.base.ref }}
- name: Generate DevHub Bot token
if: ${{ secrets.DEVHUB_APP_ID && secrets.DEVHUB_APP_PRIVATE_KEY }}
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.DEVHUB_APP_ID }}
private-key: ${{ secrets.DEVHUB_APP_PRIVATE_KEY }}
- name: Thank contributor
uses: actions/github-script@v7
with:
github-token: ${{ steps.app-token.outputs.token || github.token }}
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: `${{ inputs.merge_thank_you_message }}`
});
issue-opened:
runs-on: ubuntu-latest
if: github.event_name == 'issues' && github.event.action == 'opened'
steps:
- name: Generate DevHub Bot token
if: ${{ secrets.DEVHUB_APP_ID && secrets.DEVHUB_APP_PRIVATE_KEY }}
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.DEVHUB_APP_ID }}
private-key: ${{ secrets.DEVHUB_APP_PRIVATE_KEY }}
- name: Handle issue open (labels + comment)
uses: actions/github-script@v7
with:
github-token: ${{ steps.app-token.outputs.token || github.token }}
script: |
const issue = context.payload.issue;
const text = `${issue.title}\n${issue.body ?? ""}`.toLowerCase();
const rules = [
{ label: "bug", keywords: ["bug", "error", "crash", "fail", "issue"] },
{ label: "enhancement", keywords: ["feature", "request", "enhance"] },
{ label: "documentation", keywords: ["docs", "readme", "documentation"] },
{ label: "question", keywords: ["question", "help"] },
];
const labels = rules
.filter(r => r.label && r.keywords.some(k => text.includes(k)))
.map(r => r.label)
.filter(l => typeof l === "string" && l.trim().length > 0);
if (labels.length > 0) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels,
});
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: [
"π **Thanks for opening this issue!**",
"",
"Our maintainers have been notified and will review it as soon as possible π",
"",
"π **To help us resolve this faster:**",
"- Include clear steps to reproduce (for bugs)",
"- Mention expected vs actual behavior",
"- Add screenshots or logs if relevant",
"",
"Thanks for contributing to **Open DevHub** π",
].join("\n"),
});