Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
"image": "mcr.microsoft.com/devcontainers/go:1-bookworm",
"customizations": {
"vscode": {
"extensions": ["golang.go", "GitHub.copilot-chat", "GitHub.copilot", "github.vscode-github-actions", "astro-build.astro-vscode", "DavidAnson.vscode-markdownlint"]
"extensions": [
"golang.go",
"GitHub.copilot-chat",
"GitHub.copilot",
"github.vscode-github-actions",
"astro-build.astro-vscode",
"DavidAnson.vscode-markdownlint"
]
},
"codespaces": {
"repositories": {
Expand Down
38 changes: 20 additions & 18 deletions actions/setup/js/add_labels.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -251,67 +251,69 @@ const mockCore = {
expect(summaryCall).toBeDefined();
}),
it("should handle GitHub API errors", async () => {
(setAgentOutput({ items: [{ type: "add_labels", labels: ["bug"] }] }), (process.env.GH_AW_LABELS_ALLOWED = "bug,enhancement"));
setAgentOutput({ items: [{ type: "add_labels", labels: ["bug"] }] });
process.env.GH_AW_LABELS_ALLOWED = "bug,enhancement";
const apiError = new Error("Label does not exist");
mockGithub.rest.issues.addLabels.mockRejectedValue(apiError);
const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => {});
(await eval(`(async () => { ${addLabelsScript}; await main(); })()`),
(mockGithub.rest.issues.addLabels.mockRejectedValue(apiError),
await eval(`(async () => { ${addLabelsScript}; await main(); })()`),
expect(mockCore.error).toHaveBeenCalledWith("Failed to add labels: Label does not exist"),
expect(mockCore.setFailed).toHaveBeenCalledWith("Failed to add labels: Label does not exist"));
}),
it("should handle non-Error objects in catch block", async () => {
(setAgentOutput({ items: [{ type: "add_labels", labels: ["bug"] }] }), (process.env.GH_AW_LABELS_ALLOWED = "bug,enhancement"));
setAgentOutput({ items: [{ type: "add_labels", labels: ["bug"] }] });
process.env.GH_AW_LABELS_ALLOWED = "bug,enhancement";
const stringError = "Something went wrong";
mockGithub.rest.issues.addLabels.mockRejectedValue(stringError);
const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => {});
(await eval(`(async () => { ${addLabelsScript}; await main(); })()`),
(mockGithub.rest.issues.addLabels.mockRejectedValue(stringError),
await eval(`(async () => { ${addLabelsScript}; await main(); })()`),
expect(mockCore.error).toHaveBeenCalledWith("Failed to add labels: Something went wrong"),
expect(mockCore.setFailed).toHaveBeenCalledWith("Failed to add labels: Something went wrong"));
}));
}),
describe("Output and logging", () => {
(it("should log agent output content length", async () => {
(setAgentOutput({ items: [{ type: "add_labels", labels: ["bug", "enhancement"] }] }),
((setAgentOutput({ items: [{ type: "add_labels", labels: ["bug", "enhancement"] }] }),
(process.env.GH_AW_LABELS_ALLOWED = "bug,enhancement"),
await eval(`(async () => { ${addLabelsScript}; await main(); })()`),
expect(mockCore.info).toHaveBeenCalledWith("Agent output content length: 64"));
expect(mockCore.info).toHaveBeenCalledWith("Agent output content length: 64")));
}),
it("should log allowed labels and max count", async () => {
(setAgentOutput({ items: [{ type: "add_labels", labels: ["bug"] }] }),
((setAgentOutput({ items: [{ type: "add_labels", labels: ["bug"] }] }),
(process.env.GH_AW_LABELS_ALLOWED = "bug,enhancement,feature"),
(process.env.GH_AW_LABELS_MAX_COUNT = "5"),
await eval(`(async () => { ${addLabelsScript}; await main(); })()`),
expect(mockCore.info).toHaveBeenCalledWith(`Allowed label additions: ${JSON.stringify(["bug", "enhancement", "feature"])}`),
expect(mockCore.info).toHaveBeenCalledWith("Max count: 5"));
expect(mockCore.info).toHaveBeenCalledWith("Max count: 5")));
}),
it("should log requested labels", async () => {
(setAgentOutput({ items: [{ type: "add_labels", labels: ["bug", "enhancement", "invalid"] }] }),
((setAgentOutput({ items: [{ type: "add_labels", labels: ["bug", "enhancement", "invalid"] }] }),
(process.env.GH_AW_LABELS_ALLOWED = "bug,enhancement"),
await eval(`(async () => { ${addLabelsScript}; await main(); })()`),
expect(mockCore.info).toHaveBeenCalledWith(`Requested labels: ${JSON.stringify(["bug", "enhancement", "invalid"])}`));
expect(mockCore.info).toHaveBeenCalledWith(`Requested labels: ${JSON.stringify(["bug", "enhancement", "invalid"])}`)));
}),
it("should log final labels being added", async () => {
(setAgentOutput({ items: [{ type: "add_labels", labels: ["bug", "enhancement"] }] }),
((setAgentOutput({ items: [{ type: "add_labels", labels: ["bug", "enhancement"] }] }),
(process.env.GH_AW_LABELS_ALLOWED = "bug,enhancement"),
(process.env.GH_AW_LABELS_MAX_COUNT = "10"),
await eval(`(async () => { ${addLabelsScript}; await main(); })()`),
expect(mockCore.info).toHaveBeenCalledWith(`Adding 2 labels to issue #123: ${JSON.stringify(["bug", "enhancement"])}`));
expect(mockCore.info).toHaveBeenCalledWith(`Adding 2 labels to issue #123: ${JSON.stringify(["bug", "enhancement"])}`)));
}));
}),
describe("Edge cases", () => {
(it("should handle whitespace in allowed labels", async () => {
(setAgentOutput({ items: [{ type: "add_labels", labels: ["bug", "enhancement"] }] }),
((setAgentOutput({ items: [{ type: "add_labels", labels: ["bug", "enhancement"] }] }),
(process.env.GH_AW_LABELS_ALLOWED = " bug , enhancement , feature "),
(process.env.GH_AW_LABELS_MAX_COUNT = "10"),
await eval(`(async () => { ${addLabelsScript}; await main(); })()`),
expect(mockCore.info).toHaveBeenCalledWith(`Allowed label additions: ${JSON.stringify(["bug", "enhancement", "feature"])}`),
expect(mockGithub.rest.issues.addLabels).toHaveBeenCalledWith({ owner: "testowner", repo: "testrepo", issue_number: 123, labels: ["bug", "enhancement"] }));
expect(mockGithub.rest.issues.addLabels).toHaveBeenCalledWith({ owner: "testowner", repo: "testrepo", issue_number: 123, labels: ["bug", "enhancement"] })));
}),
it("should handle empty entries in allowed labels", async () => {
(setAgentOutput({ items: [{ type: "add_labels", labels: ["bug"] }] }),
((setAgentOutput({ items: [{ type: "add_labels", labels: ["bug"] }] }),
(process.env.GH_AW_LABELS_ALLOWED = "bug,,enhancement,"),
await eval(`(async () => { ${addLabelsScript}; await main(); })()`),
expect(mockCore.info).toHaveBeenCalledWith(`Allowed label additions: ${JSON.stringify(["bug", "enhancement"])}`));
expect(mockCore.info).toHaveBeenCalledWith(`Allowed label additions: ${JSON.stringify(["bug", "enhancement"])}`)));
}),
it("should handle single label output", async () => {
(setAgentOutput({ items: [{ type: "add_labels", labels: ["bug"] }] }),
Expand Down