Skip to content
This repository was archived by the owner on Feb 12, 2026. It is now read-only.

Commit 331dd47

Browse files
committed
feat(bot): make DevHub Bot fork-safe and preserve avatar/name
1 parent b9de8ff commit 331dd47

1 file changed

Lines changed: 30 additions & 89 deletions

File tree

.github/workflows/bot.yml

Lines changed: 30 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ on:
55
inputs:
66
thank_you_message:
77
required: false
8-
default: 'Thank you for opening this PR! Repo maintainers will review it ASAP 🚀'
8+
default: "Thank you for opening this PR! Repo maintainers will review it ASAP 🚀"
99
type: string
1010

1111
merge_thank_you_message:
1212
required: false
13-
default: '🎉 Thank you for contributing! We really appreciate your work.'
13+
default: "🎉 Thank you for contributing! We really appreciate your work."
1414
type: string
1515

1616
cc_warning_message:
@@ -27,23 +27,23 @@ on:
2727
jobs:
2828
pr-handler:
2929
runs-on: ubuntu-latest
30-
if: github.event_name == 'pull_request' && github.event.action != 'closed'
31-
30+
if: github.event.pull_request != null
3231
steps:
32+
- name: Checkout base branch only
33+
uses: actions/checkout@v5
34+
with:
35+
ref: ${{ github.event.pull_request.base.ref }}
36+
fetch-depth: 0
37+
persist-credentials: false
38+
3339
- name: Generate DevHub Bot token
3440
id: app-token
3541
uses: actions/create-github-app-token@v1
3642
with:
3743
app-id: ${{ secrets.DEVHUB_APP_ID }}
3844
private-key: ${{ secrets.DEVHUB_APP_PRIVATE_KEY }}
3945

40-
- name: Checkout repo
41-
uses: actions/checkout@v5
42-
with:
43-
fetch-depth: 0
44-
persist-credentials: false
45-
46-
- name: Fetch PR commits
46+
- name: Fetch all PR commits via API
4747
id: commits
4848
uses: actions/github-script@v7
4949
with:
@@ -57,81 +57,33 @@ jobs:
5757
pull_number: context.payload.pull_request.number
5858
}
5959
);
60-
core.setOutput(
61-
"messages",
62-
JSON.stringify(commits.map(c => c.commit.message))
63-
);
60+
core.setOutput("messages", JSON.stringify(commits.map(c => c.commit.message)));
6461
65-
- name: Analyze PR title & commits
62+
- name: Check Conventional Commits
6663
id: analyze
6764
run: |
6865
echo '${{ steps.commits.outputs.messages }}' > commits.json
6966
70-
FOUND=false
71-
LABELS=""
72-
PR_TITLE="${{ github.event.pull_request.title }}"
73-
67+
NON_CC=false
7468
regex='^(feat|fix|docs|style|refactor|perf|test|chore)(\(.+\))?:\ .+'
7569
76-
if [[ "$PR_TITLE" =~ $regex ]]; then
77-
TYPE=$(echo "$PR_TITLE" | sed -E 's/^([a-z]+).*/\1/')
78-
LABELS="$LABELS $TYPE"
79-
FOUND=true
80-
fi
81-
8270
while read -r msg; do
83-
if [[ "$msg" =~ $regex ]]; then
84-
TYPE=$(echo "$msg" | sed -E 's/^([a-z]+).*/\1/')
85-
LABELS="$LABELS $TYPE"
86-
FOUND=true
71+
if [[ ! "$msg" =~ $regex ]]; then
72+
NON_CC=true
73+
break
8774
fi
8875
done < <(jq -r '.[]' commits.json)
8976
90-
LABELS=$(echo "$LABELS" | tr ' ' '\n' | sort -u | tr '\n' ',' | sed 's/,$//')
91-
92-
echo "pass=$FOUND" >> $GITHUB_OUTPUT
93-
echo "labels=$LABELS" >> $GITHUB_OUTPUT
77+
echo "non_cc=$NON_CC" >> $GITHUB_OUTPUT
9478
95-
- name: Apply labels
79+
- name: Comment as bot
9680
uses: actions/github-script@v7
9781
with:
9882
github-token: ${{ steps.app-token.outputs.token }}
9983
script: |
100-
const raw = "${{ steps.analyze.outputs.labels }}";
101-
102-
if (!raw || raw.trim().length === 0) {
103-
console.log("No labels to apply");
104-
return;
105-
}
106-
107-
const labels = raw
108-
.split(",")
109-
.map(l => l.trim())
110-
.filter(l => l.length > 0);
111-
112-
if (labels.length === 0) {
113-
console.log("Labels resolved to empty after filtering");
114-
return;
115-
}
116-
117-
console.log("Applying labels:", labels);
118-
119-
await github.rest.issues.addLabels({
120-
owner: context.repo.owner,
121-
repo: context.repo.repo,
122-
issue_number: context.payload.pull_request.number,
123-
labels,
124-
});
125-
126-
- name: Comment on PR
127-
uses: actions/github-script@v7
128-
with:
129-
github-token: ${{ steps.app-token.outputs.token }}
130-
script: |
131-
const body =
132-
"${{ steps.analyze.outputs.pass }}" === "true"
133-
? `${{ inputs.thank_you_message }}`
134-
: `${{ inputs.cc_warning_message }}`;
84+
const body = "${{ steps.analyze.outputs.non_cc }}" === "true"
85+
? `${{ inputs.cc_warning_message }}`
86+
: `${{ inputs.thank_you_message }}`;
13587
13688
await github.rest.issues.createComment({
13789
owner: context.repo.owner,
@@ -140,28 +92,22 @@ jobs:
14092
body
14193
});
14294
143-
- name: Super Linter (non-blocking)
144-
continue-on-error: true
145-
uses: super-linter/super-linter@v8.4.0
146-
env:
147-
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
148-
VALIDATE_ALL_CODEBASE: false
149-
VALIDATE_JAVASCRIPT_PRETTIER: true
150-
VALIDATE_TYPESCRIPT_PRETTIER: true
151-
15295
pr-merged:
15396
runs-on: ubuntu-latest
154-
if: github.event_name == 'pull_request' && github.event.pull_request.merged == true
155-
97+
if: github.event.pull_request != null && github.event.pull_request.merged == true
15698
steps:
157-
- name: Generate token
99+
- uses: actions/checkout@v5
100+
with:
101+
ref: ${{ github.event.pull_request.base.ref }}
102+
103+
- name: Generate DevHub Bot token
158104
id: app-token
159105
uses: actions/create-github-app-token@v1
160106
with:
161107
app-id: ${{ secrets.DEVHUB_APP_ID }}
162108
private-key: ${{ secrets.DEVHUB_APP_PRIVATE_KEY }}
163109

164-
- name: Thank contributor
110+
- name: Thank contributor as bot
165111
uses: actions/github-script@v7
166112
with:
167113
github-token: ${{ steps.app-token.outputs.token }}
@@ -176,9 +122,8 @@ jobs:
176122
issue-opened:
177123
runs-on: ubuntu-latest
178124
if: github.event_name == 'issues' && github.event.action == 'opened'
179-
180125
steps:
181-
- name: Generate token
126+
- name: Generate DevHub Bot token
182127
id: app-token
183128
uses: actions/create-github-app-token@v1
184129
with:
@@ -207,16 +152,12 @@ jobs:
207152
.filter(l => typeof l === "string" && l.trim().length > 0);
208153
209154
if (labels.length > 0) {
210-
console.log("Applying labels:", labels);
211-
212155
await github.rest.issues.addLabels({
213156
owner: context.repo.owner,
214157
repo: context.repo.repo,
215158
issue_number: issue.number,
216159
labels,
217160
});
218-
} else {
219-
console.log("No labels detected — skipping label API call");
220161
}
221162
222163
await github.rest.issues.createComment({

0 commit comments

Comments
 (0)