Skip to content
Draft
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
18 changes: 18 additions & 0 deletions __test__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,24 @@ describe("with Octokit setup", () => {
expect(mock.done()).toBe(true);
});

test("fetchContentMetadata returns empty object if node is null", async () => {
const data = {
data: {
node: null,
},
};
mockGraphQL(data, "nullContentMetadata", "projectItems");

const result = await updateProject.fetchContentMetadata(
"PR_closed_node_id",
"test",
1,
"github"
);
expect(result).toEqual({});
expect(mock.done()).toBe(true);
});

test("fetchProjectMetadata fetches project metadata", async () => {
const expected = {
projectId: 1,
Expand Down
5 changes: 5 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9770,6 +9770,11 @@ function fetchContentMetadata(contentId, fieldName, projectNumber, owner) {
}
}
`, { contentId, fieldName });
// Handle case where node is null (e.g., when PR is closed without merging)
if (!result.node) {
(0, core_1.setFailed)(`Content not found with ID ${contentId} - it may have been deleted or is not accessible`);
return {};
}
const item = result.node.projectItems.nodes.find((node) => {
return (node.project.number === projectNumber &&
node.project.owner.login === owner);
Expand Down
10 changes: 9 additions & 1 deletion src/update-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ export async function fetchContentMetadata(
{ contentId, fieldName }
);

// Handle case where node is null (e.g., when PR is closed without merging)
if (!result.node) {
setFailed(
`Content not found with ID ${contentId} - it may have been deleted or is not accessible`
);
return {};
}

const item = result.node.projectItems.nodes.find(
(node: GraphQlQueryResponseData) => {
return (
Expand Down Expand Up @@ -222,7 +230,7 @@ export function convertValueToFieldType(
value: string,
fieldType: string
): string | number {
if (fieldType === "NUMBER") {
if (fieldType === "number") {
const numValue = parseFloat(value);
if (isNaN(numValue)) {
throw new Error(`Invalid number value: ${value}`);
Expand Down