Skip to content

Commit 5e2f777

Browse files
authored
check label name when set label action (#36590)
1 parent 31be26d commit 5e2f777

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

.github/workflows/src/sdk-breaking-change-labels.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ export async function getLabelAndActionImpl({ details_url, core, retryOptions =
9999
}
100100
}
101101

102-
if (!labelAction) {
103-
core.info("No label action found, defaulting to None");
102+
if (!labelAction || !labelName) {
103+
core.info("No label action or name found, defaulting to None");
104104
labelAction = LabelAction.None;
105105
}
106106

.github/workflows/test/sdk-breaking-change-labels.test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,62 @@ describe("sdk-breaking-change-labels", () => {
138138
issueNumber: 123,
139139
});
140140
});
141+
it("should correctly set labelAction to none when label name is empty", async () => {
142+
// Setup inputs
143+
const inputs = {
144+
details_url: "https://dev.azure.com/project/_build/results?buildId=12345",
145+
head_sha: "abc123",
146+
};
147+
148+
// Setup mock for extractInputs
149+
const { extractInputs } = await import("../src/context.js");
150+
extractInputs.mockResolvedValue(inputs);
151+
152+
// Mock artifact responses with 'remove' action
153+
const mockArtifactResponse = {
154+
ok: true,
155+
json: vi.fn().mockResolvedValue({
156+
resource: {
157+
downloadUrl: "https://dev.azure.com/download?format=zip",
158+
},
159+
}),
160+
};
161+
162+
const language = "azure-sdk-for-java";
163+
const mockContentResponse = {
164+
ok: true,
165+
text: vi.fn().mockResolvedValue(
166+
JSON.stringify({
167+
labelAction: false,
168+
language,
169+
prNumber: "123",
170+
}),
171+
),
172+
};
173+
174+
// Setup fetch to return different responses for each call
175+
global.fetch.mockImplementation((url) => {
176+
if (url.includes("artifacts?artifactName=")) {
177+
return mockArtifactResponse;
178+
} else {
179+
return mockContentResponse;
180+
}
181+
});
182+
183+
// Call function
184+
const result = await getLabelAndAction({
185+
github: mockGithub,
186+
context: mockContext,
187+
core: mockCore,
188+
});
189+
190+
// Verify result has none action
191+
expect(result).toEqual({
192+
labelName: sdkLabels[language].breakingChange,
193+
labelAction: LabelAction.None,
194+
issueNumber: 123,
195+
});
196+
});
141197
it("should throw error with invalid inputs", async () => {
142198
// Setup inputs
143199
const inputs = {

0 commit comments

Comments
 (0)