Skip to content

Commit c1d1476

Browse files
authored
Created new pull request template and auto labeler (#1046)
Created new pull request template and autolabler
1 parent fbf64e5 commit c1d1476

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

.github/pull_request_template.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!-- Thanks for sending a pull request! Here are some tips for you:
2+
3+
1. If this is your first time, please read our contributor guidelines: https://github.com/GoogleCloudPlatform/ai-on-gke/blob/main/contributing.md
4+
2. Please label this pull request according to what type of issue you are addressing.
5+
3. Ensure you have added or ran the appropriate tests for your PR.
6+
-->
7+
8+
**What type of PR is this?**
9+
> Uncomment only one ` /kind <>` line, press enter to put that in a new line, and remove leading whitespace from that line:
10+
>
11+
> /kind breaking
12+
> /kind bug
13+
> /kind cleanup
14+
> /kind documentation
15+
> /kind enhancement
16+
17+
**What this PR does / Why we need it**:
18+
19+
**Which issue(s) this PR fixes**:
20+
<!--
21+
*Automatically closes linked issue when PR is merged.
22+
Usage: `Closes #<issue number>`, or `Closes (paste link of issue)`.
23+
-->
24+
Closes #
25+
26+
**Special notes for your reviewer**:

.github/workflows/label-pr.yaml

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
# Copyright 2025 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
# This workflow utilizes https://github.com/actions/github-script in GitHub Actions to apply labels to pull requests.
17+
#
18+
name: Label PR
19+
on: [pull_request_target]
20+
jobs:
21+
label:
22+
runs-on: ubuntu-latest
23+
permissions:
24+
contents: read
25+
pull-requests: write
26+
steps:
27+
- name: Label PR
28+
uses: actions/github-script@v6
29+
with:
30+
script: |-
31+
const keywords = {
32+
"breaking": "kind/breaking",
33+
"bug": "kind/bug",
34+
"enhancement": "kind/enhancement",
35+
"cleanup": "kind/cleanup",
36+
"documentation": "kind/documentation"
37+
};
38+
const prBody = context.payload.pull_request.body;
39+
const prLabels = [];
40+
if (prBody === null || prBody.trim() === "") {
41+
console.log("Pull Request body is empty");
42+
prLabels.push("kind/other");
43+
} else {
44+
const regex = /^\s*\/kind\s+(.+)$/m;
45+
const match = prBody.match(regex);
46+
console.log(`PR body: '${prBody}'`);
47+
console.log(`Regex match: '${match}'`);
48+
if (match && match[1] in keywords) {
49+
const keyword = match[1];
50+
const label = keywords[keyword];
51+
console.log(`Adding label: '${label}' based on keyword '${keyword}'`);
52+
prLabels.push(label);
53+
} else {
54+
console.log(`Adding label: 'kind/other' as no matching keyword found.`);
55+
prLabels.push("kind/other");
56+
}
57+
}
58+
try {
59+
github.rest.issues.addLabels({
60+
owner: context.repo.owner,
61+
repo: context.repo.repo,
62+
issue_number: context.payload.pull_request.number,
63+
labels: prLabels
64+
});
65+
} catch (error) {
66+
console.error(`Error retrieving files: ${error}`);
67+
}

0 commit comments

Comments
 (0)