Skip to content

Commit 7d1d411

Browse files
committed
Only apply label for PR title, not commits
Signed-off-by: Kyle Squizzato <[email protected]>
1 parent e0f7fa6 commit 7d1d411

File tree

4 files changed

+30
-74
lines changed

4 files changed

+30
-74
lines changed

.github/actions/pr-labels/dist/index.js

+14-36
Original file line numberDiff line numberDiff line change
@@ -9800,12 +9800,12 @@ const SEMANTIC_TYPE_TO_LABEL = {
98009800
};
98019801

98029802
/**
9803-
* Extract semantic commit type from a message
9803+
* Extract semantic type from a PR title
98049804
* Supports formats like:
98059805
* - "feat: add new feature"
98069806
* - "fix(component): fix bug"
98079807
* - "chore: update dependencies"
9808-
* @param {string} message - The commit message or PR title
9808+
* @param {string} message - The PR title
98099809
* @returns {string|null} - The semantic type or null if not found
98109810
*/
98119811
function extractSemanticType(message) {
@@ -9855,7 +9855,7 @@ async function run() {
98559855
if (existingTypeLabels.length > 0) {
98569856
core.info("Type labels already exist on PR, skipping adding new labels");
98579857
} else {
9858-
// Get PR details to check for semantic commit messages
9858+
// Get PR details to check for semantic PR title
98599859
await addSemanticLabels(octokit, labels);
98609860
}
98619861

@@ -9913,7 +9913,7 @@ async function run() {
99139913
}
99149914

99159915
/**
9916-
* Add labels based on semantic commit messages
9916+
* Add labels based on semantic PR title
99179917
* @param {object} octokit - GitHub API client
99189918
* @param {string[]} labels - Current labels array to update
99199919
* @returns {Promise<void>}
@@ -9928,46 +9928,24 @@ async function addSemanticLabels(octokit, labels) {
99289928
pull_number: prNumber,
99299929
});
99309930

9931-
// Get the PR title and HEAD commit message
9931+
// Get the PR title
99329932
const prTitle = pullRequest.title;
99339933
core.debug(`PR title: "${prTitle}"`);
99349934

9935-
// Get the HEAD commit message
9936-
core.debug("Fetching PR commits...");
9937-
const { data: commits } = await octokit.rest.pulls.listCommits({
9938-
...github.context.repo,
9939-
pull_number: prNumber,
9940-
});
9941-
9942-
core.debug(`Found ${commits.length} commits in PR`);
9943-
const headCommitMessage = commits.length > 0 ? commits[commits.length - 1].commit.message : null;
9944-
if (headCommitMessage) {
9945-
core.debug(`HEAD commit message: "${headCommitMessage}"`);
9946-
} else {
9947-
core.debug("No HEAD commit message found");
9948-
}
9949-
9950-
// Try to extract semantic type from PR title or HEAD commit
9935+
// Try to extract semantic type from PR title only
99519936
core.debug("Extracting semantic type from PR title...");
9952-
const prTitleType = extractSemanticType(prTitle);
9953-
9954-
core.debug("Extracting semantic type from HEAD commit...");
9955-
const commitType = extractSemanticType(headCommitMessage);
9956-
9957-
// Use PR title type first, then fall back to commit type
9958-
const semanticType = prTitleType || commitType;
9937+
const semanticType = extractSemanticType(prTitle);
9938+
99599939
if (semanticType) {
9960-
core.debug(`Using semantic type: "${semanticType}"`);
9940+
core.debug(`Using semantic type from PR title: "${semanticType}"`);
99619941
} else {
9962-
core.debug("No semantic type found in PR title or HEAD commit");
9942+
core.debug("No semantic type found in PR title");
99639943
return;
99649944
}
99659945

99669946
// If we found a semantic type that maps to one of our labels, add it if not present
9967-
if (!semanticType || !SEMANTIC_TYPE_TO_LABEL[semanticType]) {
9968-
if (semanticType) {
9969-
core.debug(`Semantic type "${semanticType}" does not map to any of our labels`);
9970-
}
9947+
if (!SEMANTIC_TYPE_TO_LABEL[semanticType]) {
9948+
core.debug(`Semantic type "${semanticType}" does not map to any of our labels`);
99719949
return;
99729950
}
99739951

@@ -9980,7 +9958,7 @@ async function addSemanticLabels(octokit, labels) {
99809958
return;
99819959
}
99829960

9983-
core.info(`Adding label ${labelToAdd} based on semantic commit type: ${semanticType}`);
9961+
core.info(`Adding label ${labelToAdd} based on semantic PR title type: ${semanticType}`);
99849962

99859963
core.debug("Calling GitHub API to add label...");
99869964
await octokit.rest.issues.addLabels({
@@ -9994,7 +9972,7 @@ async function addSemanticLabels(octokit, labels) {
99949972
labels.push(labelToAdd);
99959973
core.debug(`Updated local labels array: ${labels.join(", ")}`);
99969974

9997-
core.info("Added label based on semantic commit message. Waiting for label to apply...");
9975+
core.info("Added label based on semantic PR title. Waiting for label to apply...");
99989976
// Short delay to allow the label to be properly registered
99999977
core.debug("Waiting 2 seconds for label to propagate...");
100009978
await new Promise(resolve => setTimeout(resolve, 2000));

.github/actions/pr-labels/dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/actions/pr-labels/src/index.js

+14-36
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ const SEMANTIC_TYPE_TO_LABEL = {
2424
};
2525

2626
/**
27-
* Extract semantic commit type from a message
27+
* Extract semantic type from a PR title
2828
* Supports formats like:
2929
* - "feat: add new feature"
3030
* - "fix(component): fix bug"
3131
* - "chore: update dependencies"
32-
* @param {string} message - The commit message or PR title
32+
* @param {string} message - The PR title
3333
* @returns {string|null} - The semantic type or null if not found
3434
*/
3535
function extractSemanticType(message) {
@@ -79,7 +79,7 @@ async function run() {
7979
if (existingTypeLabels.length > 0) {
8080
core.info("Type labels already exist on PR, skipping adding new labels");
8181
} else {
82-
// Get PR details to check for semantic commit messages
82+
// Get PR details to check for semantic PR title
8383
await addSemanticLabels(octokit, labels);
8484
}
8585

@@ -137,7 +137,7 @@ async function run() {
137137
}
138138

139139
/**
140-
* Add labels based on semantic commit messages
140+
* Add labels based on semantic PR title
141141
* @param {object} octokit - GitHub API client
142142
* @param {string[]} labels - Current labels array to update
143143
* @returns {Promise<void>}
@@ -152,46 +152,24 @@ async function addSemanticLabels(octokit, labels) {
152152
pull_number: prNumber,
153153
});
154154

155-
// Get the PR title and HEAD commit message
155+
// Get the PR title
156156
const prTitle = pullRequest.title;
157157
core.debug(`PR title: "${prTitle}"`);
158158

159-
// Get the HEAD commit message
160-
core.debug("Fetching PR commits...");
161-
const { data: commits } = await octokit.rest.pulls.listCommits({
162-
...github.context.repo,
163-
pull_number: prNumber,
164-
});
165-
166-
core.debug(`Found ${commits.length} commits in PR`);
167-
const headCommitMessage = commits.length > 0 ? commits[commits.length - 1].commit.message : null;
168-
if (headCommitMessage) {
169-
core.debug(`HEAD commit message: "${headCommitMessage}"`);
170-
} else {
171-
core.debug("No HEAD commit message found");
172-
}
173-
174-
// Try to extract semantic type from PR title or HEAD commit
159+
// Try to extract semantic type from PR title only
175160
core.debug("Extracting semantic type from PR title...");
176-
const prTitleType = extractSemanticType(prTitle);
177-
178-
core.debug("Extracting semantic type from HEAD commit...");
179-
const commitType = extractSemanticType(headCommitMessage);
180-
181-
// Use PR title type first, then fall back to commit type
182-
const semanticType = prTitleType || commitType;
161+
const semanticType = extractSemanticType(prTitle);
162+
183163
if (semanticType) {
184-
core.debug(`Using semantic type: "${semanticType}"`);
164+
core.debug(`Using semantic type from PR title: "${semanticType}"`);
185165
} else {
186-
core.debug("No semantic type found in PR title or HEAD commit");
166+
core.debug("No semantic type found in PR title");
187167
return;
188168
}
189169

190170
// If we found a semantic type that maps to one of our labels, add it if not present
191-
if (!semanticType || !SEMANTIC_TYPE_TO_LABEL[semanticType]) {
192-
if (semanticType) {
193-
core.debug(`Semantic type "${semanticType}" does not map to any of our labels`);
194-
}
171+
if (!SEMANTIC_TYPE_TO_LABEL[semanticType]) {
172+
core.debug(`Semantic type "${semanticType}" does not map to any of our labels`);
195173
return;
196174
}
197175

@@ -204,7 +182,7 @@ async function addSemanticLabels(octokit, labels) {
204182
return;
205183
}
206184

207-
core.info(`Adding label ${labelToAdd} based on semantic commit type: ${semanticType}`);
185+
core.info(`Adding label ${labelToAdd} based on semantic PR title type: ${semanticType}`);
208186

209187
core.debug("Calling GitHub API to add label...");
210188
await octokit.rest.issues.addLabels({
@@ -218,7 +196,7 @@ async function addSemanticLabels(octokit, labels) {
218196
labels.push(labelToAdd);
219197
core.debug(`Updated local labels array: ${labels.join(", ")}`);
220198

221-
core.info("Added label based on semantic commit message. Waiting for label to apply...");
199+
core.info("Added label based on semantic PR title. Waiting for label to apply...");
222200
// Short delay to allow the label to be properly registered
223201
core.debug("Waiting 2 seconds for label to propagate...");
224202
await new Promise(resolve => setTimeout(resolve, 2000));

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Common workflows required for some or all replicatedhq repos
33

44
## Workflows
5-
* **pr-labels.yml**: Fails if a PR does not have the necessary labels for Engineering metrics, will apply primary labels if the PR title or `HEAD` commit message contains a semantic commit, for example:
5+
* **pr-labels.yml**: Fails if a PR does not have the necessary labels for Engineering metrics, will apply primary labels if the PR title contains a semantic type, for example:
66
* `feat(ci)`, `feature(ci)`: Adds `type::feature`
77
* `bug(ci)`: Adds `type::bug`
88
* `chore(ci)`: Adds `type::chore`

0 commit comments

Comments
 (0)