44 workflow_call :
55 inputs :
66 thank_you_message :
7- description : ' Message when PR follows conventional commits'
87 required : false
9- 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 🚀"
109 type : string
1110
1211 merge_thank_you_message :
13- description : ' Message when PR is merged'
1412 required : false
15- default : ' 🎉 Thank you for contributing to Open DevHub! We appreciate your work.'
13+ default : " 🎉 Thank you for contributing to Open DevHub! We appreciate your work."
1614 type : string
1715
1816 cc_warning_message :
19- description : ' Message when PR does NOT follow conventional commits'
2017 required : false
21- default : ' ⚠️ Consider following Conventional Commits for your PR title and commit messages. '
18+ default : " ⚠️ Please consider using Conventional Commits (e.g. feat:, fix:, docs:). "
2219 type : string
2320
2421 secrets :
2825 required : true
2926
3027jobs :
31- pr-opened :
32- if : github.event_name == 'pull_request' && github.event.action != 'closed' && github.event.pull_request.head.repo.full_name == github.repository
28+ pr-handler :
3329 runs-on : ubuntu-latest
30+ if : github.event_name == 'pull_request'
3431
3532 steps :
3633 - name : Generate DevHub Bot token
4037 app-id : ${{ secrets.DEVHUB_APP_ID }}
4138 private-key : ${{ secrets.DEVHUB_APP_PRIVATE_KEY }}
4239
43- - name : Checkout Code
40+ - name : Checkout repo
4441 uses : actions/checkout@v5
4542 with :
46- # super-linter needs the full git history to get the
47- # list of files that changed across commits
4843 fetch-depth : 0
4944 persist-credentials : false
5045
6257 pull_number: context.payload.pull_request.number
6358 }
6459 );
65- core.setOutput("messages", JSON.stringify(commits.map(c => c.commit.message)));
60+ core.setOutput(
61+ "messages",
62+ JSON.stringify(commits.map(c => c.commit.message))
63+ );
6664
67- - name : Analyze PR title + commits for labels
65+ - name : Analyze PR title & commits
6866 id : analyze
6967 run : |
7068 echo '${{ steps.commits.outputs.messages }}' > commits.json
@@ -73,73 +71,72 @@ jobs:
7371 LABELS=""
7472 PR_TITLE="${{ github.event.pull_request.title }}"
7573
76- # Check PR title
77- if [[ "$PR_TITLE" =~ ^(feat|fix|docs|style|refactor|perf|test|chore)(\(.+\))?:\ .+ ]]; then
74+ regex='^(feat|fix|docs|style|refactor|perf|test|chore)(\(.+\))?:\ .+'
75+
76+ if [[ "$PR_TITLE" =~ $regex ]]; then
7877 TYPE=$(echo "$PR_TITLE" | sed -E 's/^([a-z]+).*/\1/')
7978 LABELS="$LABELS $TYPE"
8079 FOUND=true
8180 fi
8281
83- # Check commits
8482 while read -r msg; do
85- if [[ "$msg" =~ ^(feat|fix|docs|style|refactor|perf|test|chore)(\(.+\))?:\ .+ ]]; then
83+ if [[ "$msg" =~ $regex ]]; then
8684 TYPE=$(echo "$msg" | sed -E 's/^([a-z]+).*/\1/')
8785 LABELS="$LABELS $TYPE"
8886 FOUND=true
8987 fi
9088 done < <(jq -r '.[]' commits.json)
9189
92- # Remove duplicates and prepare comma-separated labels
93- LABELS=$(echo $LABELS | tr ' ' '\n' | sort -u | tr '\n' ',' | sed 's/,$//')
90+ LABELS=$(echo "$LABELS" | tr ' ' '\n' | sort -u | tr '\n' ',' | sed 's/,$//')
91+
9492 echo "pass=$FOUND" >> $GITHUB_OUTPUT
9593 echo "labels=$LABELS" >> $GITHUB_OUTPUT
9694
97- - name : Apply labels to PR
95+ - name : Apply labels
9896 if : steps.analyze.outputs.labels != ''
9997 uses : actions/github-script@v7
10098 with :
10199 github-token : ${{ steps.app-token.outputs.token }}
102100 script : |
103- const pr_number = context.payload.pull_request.number;
104- const labels = "${{ steps.analyze.outputs.labels }}".split(",");
105101 await github.rest.issues.addLabels({
106102 owner: context.repo.owner,
107103 repo: context.repo.repo,
108- issue_number: pr_number ,
109- labels: labels
104+ issue_number: context.payload.pull_request.number ,
105+ labels: "${{ steps.analyze.outputs. labels }}".split(",")
110106 });
111107
112- - name : Run Super Linter
113- id : linter
114- uses : super-linter/super-linter@v8.4.0
115- env :
116- GITHUB_TOKEN : ${{ steps.app-token.outputs.token }}
117- VALIDATE_JAVASCRIPT_PRETTIER : true
118- VALIDATE_TYPESCRIPT_PRETTIER : true
119- VALIDATE_ALL_CODEBASE : false
120- ENABLE_GITHUB_ACTIONS_GROUP_TITLE : true
121-
122108 - name : Comment on PR
123109 uses : actions/github-script@v7
124110 with :
125111 github-token : ${{ steps.app-token.outputs.token }}
126112 script : |
127- const pr_number = context.payload.pull_request.number;
128- const msg = "${{ steps.analyze.outputs.pass }}" === "true"
129- ? `${{ inputs.thank_you_message }}`
130- : `${{ inputs.cc_warning_message }}`;
113+ const body =
114+ "${{ steps.analyze.outputs.pass }}" === "true"
115+ ? `${{ inputs.thank_you_message }}`
116+ : `${{ inputs.cc_warning_message }}`;
117+
131118 await github.rest.issues.createComment({
132119 owner: context.repo.owner,
133120 repo: context.repo.repo,
134- issue_number: pr_number ,
135- body: msg
121+ issue_number: context.payload.pull_request.number ,
122+ body
136123 });
137124
125+ - name : Super Linter (non-blocking)
126+ continue-on-error : true
127+ uses : super-linter/super-linter@v8.4.0
128+ env :
129+ GITHUB_TOKEN : ${{ steps.app-token.outputs.token }}
130+ VALIDATE_ALL_CODEBASE : false
131+ VALIDATE_JAVASCRIPT_PRETTIER : true
132+ VALIDATE_TYPESCRIPT_PRETTIER : true
133+
138134 pr-merged :
139- if : github.event_name == 'pull_request' && github.event.pull_request.merged == true
140135 runs-on : ubuntu-latest
136+ if : github.event_name == 'pull_request' && github.event.pull_request.merged == true
137+
141138 steps :
142- - name : Generate DevHub Bot token
139+ - name : Generate token
143140 id : app-token
144141 uses : actions/create-github-app-token@v1
145142 with :
@@ -159,27 +156,78 @@ jobs:
159156 });
160157
161158 issue-opened :
162- if : github.event_name == 'issues' && github.event.action == 'opened'
163159 runs-on : ubuntu-latest
160+ if : github.event_name == 'issues' && github.event.action == 'opened'
161+
164162 steps :
165- - name : Generate DevHub Bot token
163+ - name : Generate token
166164 id : app-token
167165 uses : actions/create-github-app-token@v1
168166 with :
169167 app-id : ${{ secrets.DEVHUB_APP_ID }}
170168 private-key : ${{ secrets.DEVHUB_APP_PRIVATE_KEY }}
171169
172- - name : Add bug label if title contains "bug"
170+ - name : Handle new issue (labels + comment)
173171 uses : actions/github-script@v7
174172 with :
175173 github-token : ${{ steps.app-token.outputs.token }}
176174 script : |
177- const title = context.payload.issue.title.toLowerCase();
178- if (title.includes("bug")) {
175+ const issue = context.payload.issue;
176+
177+ const text = `${issue.title}\n${issue.body || ""}`.toLowerCase();
178+
179+ const labels = new Set();
180+
181+ const rules = [
182+ {
183+ keywords: ["bug", "error", "crash", "fail"],
184+ label: "bug",
185+ },
186+ {
187+ keywords: ["feature", "request", "enhancement"],
188+ label: "enhancement",
189+ },
190+ {
191+ keywords: ["doc", "docs", "readme"],
192+ label: "documentation",
193+ },
194+ {
195+ keywords: ["question", "help"],
196+ label: "question",
197+ },
198+ ];
199+
200+ for (const rule of rules) {
201+ if (rule.keywords.some((k) => text.includes(k))) {
202+ labels.add(rule.label);
203+ }
204+ }
205+
206+ if (labels.size > 0) {
179207 await github.rest.issues.addLabels({
180208 owner: context.repo.owner,
181209 repo: context.repo.repo,
182- issue_number: context.payload. issue.number,
183- labels: ["bug"]
210+ issue_number: issue.number,
211+ labels: Array.from(labels),
184212 });
185213 }
214+
215+ const commentLines = [
216+ "👋 **Thanks for opening this issue!**",
217+ "",
218+ "The Open DevHub maintainers have been notified and will review it as soon as possible 🚀",
219+ "",
220+ "📌 **Tips to speed things up:**",
221+ "- Provide clear steps to reproduce (if it's a bug)",
222+ "- Attach screenshots or logs if relevant",
223+ "- Mention expected vs actual behavior",
224+ "",
225+ "We appreciate your contribution 💙",
226+ ];
227+
228+ await github.rest.issues.createComment({
229+ owner: context.repo.owner,
230+ repo: context.repo.repo,
231+ issue_number: issue.number,
232+ body: commentLines.join("\n"),
233+ });
0 commit comments