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
6 changes: 4 additions & 2 deletions actions/setup/js/create_issue.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ async function main() {
effectiveParentIssueNumber = undefined;
}
} else {
// It's a real issue number
effectiveParentIssueNumber = parseInt(String(createIssueItem.parent), 10);
// It's a real issue number (may have # prefix)
const parentStr = String(createIssueItem.parent).trim();
const parentWithoutHash = parentStr.startsWith('#') ? parentStr.substring(1) : parentStr;
effectiveParentIssueNumber = parseInt(parentWithoutHash, 10);
if (isNaN(effectiveParentIssueNumber)) {
core.warning(`Invalid parent value: ${createIssueItem.parent}`);
effectiveParentIssueNumber = undefined;
Expand Down
63 changes: 63 additions & 0 deletions actions/setup/js/create_issue.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -329,5 +329,68 @@ const mockCore = {
(mockGithub.rest.issues.create.mockResolvedValue({ data: mockIssue }),
await eval(`(async () => { ${createIssueScript}; await main(); })()`),
expect(mockCore.warning).toHaveBeenCalledWith(expect.stringContaining("Parent temporary ID 'aw_000000000000' not found")));
}),
it("should handle parent issue number with # prefix", async () => {
setAgentOutput({ items: [{ type: "create_issue", title: "Sub Issue", body: "Sub issue with parent", parent: "#555" }] });
const mockIssue = { number: 556, html_url: "https://github.com/testowner/testrepo/issues/556" };
mockGithub.rest.issues.create.mockResolvedValue({ data: mockIssue });
let graphqlCallCount = 0;
(mockGithub.graphql.mockImplementation(
() => (
graphqlCallCount++,
1 === graphqlCallCount
? Promise.resolve({ repository: { issue: { id: "parent-node-id-555" } } })
: 2 === graphqlCallCount
? Promise.resolve({ repository: { issue: { id: "child-node-id-556" } } })
: 3 === graphqlCallCount
? Promise.resolve({ addSubIssue: { subIssue: { id: "child-node-id-556", number: 556 } } })
: Promise.reject(new Error("Unexpected graphql call"))
)
),
await eval(`(async () => { ${createIssueScript}; await main(); })()`));
const createArgs = mockGithub.rest.issues.create.mock.calls[0][0];
(expect(createArgs.body).toContain("Related to #555"), expect(mockCore.info).toHaveBeenCalledWith("Using explicit parent issue number from item: testowner/testrepo#555"));
}),
it("should handle parent issue number without # prefix", async () => {
setAgentOutput({ items: [{ type: "create_issue", title: "Sub Issue", body: "Sub issue with parent", parent: "777" }] });
const mockIssue = { number: 778, html_url: "https://github.com/testowner/testrepo/issues/778" };
mockGithub.rest.issues.create.mockResolvedValue({ data: mockIssue });
let graphqlCallCount = 0;
(mockGithub.graphql.mockImplementation(
() => (
graphqlCallCount++,
1 === graphqlCallCount
? Promise.resolve({ repository: { issue: { id: "parent-node-id-777" } } })
: 2 === graphqlCallCount
? Promise.resolve({ repository: { issue: { id: "child-node-id-778" } } })
: 3 === graphqlCallCount
? Promise.resolve({ addSubIssue: { subIssue: { id: "child-node-id-778", number: 778 } } })
: Promise.reject(new Error("Unexpected graphql call"))
)
),
await eval(`(async () => { ${createIssueScript}; await main(); })()`));
const createArgs = mockGithub.rest.issues.create.mock.calls[0][0];
(expect(createArgs.body).toContain("Related to #777"), expect(mockCore.info).toHaveBeenCalledWith("Using explicit parent issue number from item: testowner/testrepo#777"));
}),
it("should handle parent issue number as integer", async () => {
setAgentOutput({ items: [{ type: "create_issue", title: "Sub Issue", body: "Sub issue with parent", parent: 888 }] });
const mockIssue = { number: 889, html_url: "https://github.com/testowner/testrepo/issues/889" };
mockGithub.rest.issues.create.mockResolvedValue({ data: mockIssue });
let graphqlCallCount = 0;
(mockGithub.graphql.mockImplementation(
() => (
graphqlCallCount++,
1 === graphqlCallCount
? Promise.resolve({ repository: { issue: { id: "parent-node-id-888" } } })
: 2 === graphqlCallCount
? Promise.resolve({ repository: { issue: { id: "child-node-id-889" } } })
: 3 === graphqlCallCount
? Promise.resolve({ addSubIssue: { subIssue: { id: "child-node-id-889", number: 889 } } })
: Promise.reject(new Error("Unexpected graphql call"))
)
),
await eval(`(async () => { ${createIssueScript}; await main(); })()`));
const createArgs = mockGithub.rest.issues.create.mock.calls[0][0];
(expect(createArgs.body).toContain("Related to #888"), expect(mockCore.info).toHaveBeenCalledWith("Using explicit parent issue number from item: testowner/testrepo#888"));
}));
}));
Loading