Skip to content
Prev Previous commit
Next Next commit
Treat empty add_labels list as a no-op instead of a failure
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
  • Loading branch information
Copilot and pelikhan authored Sep 16, 2026
commit 3a88e25a01bee89f3a956b25c2084cffd8ba317c
5 changes: 5 additions & 0 deletions .changeset/add-labels-empty-list-no-op.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions actions/setup/js/add_labels.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -390,12 +390,18 @@ const main = createCountGatedHandler({
}
}

// If no labels provided, return a helpful message with allowed labels if configured
// If no labels provided, skip the request with a warning instead of failing the job.
// An empty list means there is nothing to add, which is not an error condition.
if (requestedLabelNames.length === 0) {
const labelSource = allowedLabels.length > 0 ? `the allowed list: ${JSON.stringify(allowedLabels)}` : "the repository's available labels";
const error = `No labels provided. Please provide at least one label from ${labelSource}`;
core.info(error);
return { success: false, error };
const message = `No labels provided. Skipping add_labels. Provide at least one label from ${labelSource}`;
core.warning(message);
return {
success: true,
number: itemNumber,
labelsAdded: [],
message,
};
Comment on lines +399 to +407

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 9ebe596 and 3c0e220: the empty-labels path now returns { success: true, skipped: true, reasonCode: "NO_LABELS_PROVIDED", reason: "No labels provided", ... }. classifySafeOutputResult checks skipped before success, so it is counted in items_skipped rather than items_applied, and the summary renders the reason code. Tests assert result.skipped === true, the reason code, and classifySafeOutputResult(result) === "skipped".

}

// Enforce max limits on labels before validation
Expand Down
33 changes: 18 additions & 15 deletions actions/setup/js/add_labels.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ describe("add_labels", () => {
expect(result.labelsAdded).toEqual(["bug", "enhancement"]);
});

it("should handle empty labels array", async () => {
it("should skip empty labels array without failing", async () => {
const handler = await main({ max: 10 });

const result = await handler(
Expand All @@ -818,12 +818,13 @@ describe("add_labels", () => {
{}
);

expect(result.success).toBe(false);
expect(result.error).toContain("No labels provided");
expect(result.error).toContain("repository's available labels");
expect(result.success).toBe(true);
expect(result.labelsAdded).toEqual([]);
expect(result.message).toContain("No labels provided");
expect(result.message).toContain("repository's available labels");
});

it("should handle missing labels field", async () => {
it("should skip missing labels field without failing", async () => {
const handler = await main({ max: 10 });

const result = await handler(
Expand All @@ -833,12 +834,13 @@ describe("add_labels", () => {
{}
);

expect(result.success).toBe(false);
expect(result.error).toContain("No labels provided");
expect(result.error).toContain("repository's available labels");
expect(result.success).toBe(true);
expect(result.labelsAdded).toEqual([]);
expect(result.message).toContain("No labels provided");
expect(result.message).toContain("repository's available labels");
});

it("should return allowed labels list when labels missing and allowed list configured", async () => {
it("should report allowed labels list when labels missing and allowed list configured", async () => {
const handler = await main({
allowed: ["bug", "enhancement", "documentation"],
max: 10,
Expand All @@ -852,12 +854,13 @@ describe("add_labels", () => {
{}
);

expect(result.success).toBe(false);
expect(result.error).toContain("No labels provided");
expect(result.error).toContain("allowed list");
expect(result.error).toContain("bug");
expect(result.error).toContain("enhancement");
expect(result.error).toContain("documentation");
expect(result.success).toBe(true);
expect(result.labelsAdded).toEqual([]);
expect(result.message).toContain("No labels provided");
expect(result.message).toContain("allowed list");
expect(result.message).toContain("bug");
expect(result.message).toContain("enhancement");
expect(result.message).toContain("documentation");
});

it("should handle API errors gracefully", async () => {
Expand Down