From 15c97d2e01a9d46e199cfaade80ab77edfa4b018 Mon Sep 17 00:00:00 2001 From: Mike Surowiec Date: Fri, 25 Mar 2022 16:54:27 -0500 Subject: [PATCH] BREAKING CHANGE: remove '.isDraft' from projectItem fixes discriminated union type, reduces confusion since isDraft exists on projectItem.content when item is a PR --- README.md | 6 ++-- ...ms.get-by-content-repository-and-number.js | 2 +- ...s.remove-by-content-repository-and-name.js | 2 +- ...update-by-content-repository-and-number.js | 2 +- ...roject-item-node-to-github-project-item.js | 4 +-- index.d.ts | 2 -- index.test-d.ts | 32 +++++++++--------- test.js | 4 --- test.js.md | 4 --- test.js.snap | Bin 1755 -> 1726 bytes .../fixtures/add-item/issue/new-issue-item.js | 1 - .../pull-request/new-pull-request-item.js | 1 - test/fixtures/get-item/draft-item.js | 1 - test/fixtures/get-item/issue-item.js | 1 - test/fixtures/list-items/items.js | 3 -- 15 files changed, 23 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 604e194d..1cb6605b 100644 --- a/README.md +++ b/README.md @@ -19,10 +19,10 @@ Browsers Load github-project directly from cdn.skypack.dev - + ```html ``` @@ -66,7 +66,7 @@ for (const item of items) { item.fields.title, item.fields.dueAt, item.fields.priority, - item.isDraft + item.type === "DRAFT_ISSUE" ? "_draft_" : item.content.assignees.map(({ login }) => login).join(",") ); diff --git a/api/items.get-by-content-repository-and-number.js b/api/items.get-by-content-repository-and-number.js index 54fb8003..d30bdb0c 100644 --- a/api/items.get-by-content-repository-and-number.js +++ b/api/items.get-by-content-repository-and-number.js @@ -21,7 +21,7 @@ export async function getItemByContentRepositoryAndNumber( const stateWithItems = await getStateWithProjectItems(project, state); return stateWithItems.items.find((item) => { - if (item.isDraft === true) return; + if (item.type === "DRAFT_ISSUE") return; return ( item.content.repository === repositoryName && diff --git a/api/items.remove-by-content-repository-and-name.js b/api/items.remove-by-content-repository-and-name.js index 94649302..6fbd527f 100644 --- a/api/items.remove-by-content-repository-and-name.js +++ b/api/items.remove-by-content-repository-and-name.js @@ -22,7 +22,7 @@ export async function removeItemByContentRepositoryAndNumber( const stateWithItems = await getStateWithProjectItems(project, state); const existingItem = stateWithItems.items.find((item) => { - if (item.isDraft === true) return; + if (item.type === "DRAFT_ISSUE") return; return ( item.content.repository === repositoryName && diff --git a/api/items.update-by-content-repository-and-number.js b/api/items.update-by-content-repository-and-number.js index 3c75fb88..54f2c57f 100644 --- a/api/items.update-by-content-repository-and-number.js +++ b/api/items.update-by-content-repository-and-number.js @@ -25,7 +25,7 @@ export async function updateItemByContentRepositoryAndNumber( const stateWithItems = await getStateWithProjectItems(project, state); const item = stateWithItems.items.find((item) => { - if (item.isDraft === true) return; + if (item.type === "DRAFT_ISSUE") return; return ( item.content.repository === repositoryName && diff --git a/api/lib/project-item-node-to-github-project-item.js b/api/lib/project-item-node-to-github-project-item.js index 60cc5d71..3880bccc 100644 --- a/api/lib/project-item-node-to-github-project-item.js +++ b/api/lib/project-item-node-to-github-project-item.js @@ -14,12 +14,11 @@ export function projectItemNodeToGitHubProjectItem(state, itemNode) { const fields = itemFieldsNodesToFieldsMap(state, itemNode.fieldValues.nodes); // item is draft - if (!itemNode.content || itemNode.type === 'DRAFT_ISSUE') { + if (!itemNode.content || itemNode.type === "DRAFT_ISSUE") { return { id: itemNode.id, type: itemNode.type, fields, - isDraft: true, }; } @@ -55,7 +54,6 @@ export function projectItemNodeToGitHubProjectItem(state, itemNode) { id: itemNode.id, type: itemNode.type, fields, - isDraft: false, // @ts-expect-error - complains about `.merged` property content, }; diff --git a/index.d.ts b/index.d.ts index f1d3021f..5a6dafa6 100644 --- a/index.d.ts +++ b/index.d.ts @@ -97,13 +97,11 @@ type DraftItem = { id: string; type: "DRAFT_ISSUE"; fields: TFields; - isDraft: true; }; type NonDraftItem = { id: string; type: "ISSUE" | "PULL_REQUEST" | "REDACTED"; fields: TFields; - isDraft: false; content: Issue | PullRequest; }; diff --git a/index.test-d.ts b/index.test-d.ts index 56939f54..e875dc18 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -75,12 +75,12 @@ export async function listItemsTest() { }); const [item] = await project.items.list(); - if (item.isDraft === true) { + if (item.type === "DRAFT_ISSUE") { expectType(item.id); expectType(item.fields.title); expectNotType<"Title">(item.fields.title); - // @ts-expect-error - `.content` is not set if `.isDraft` is true + // @ts-expect-error - `.content` is not set if `.type` is "DRAFT_ISSUE" item.content; } else { expectType(item.id); @@ -100,7 +100,7 @@ export async function addItemTest() { const item = await project.items.add("issue node_id"); expectType(item.id); - expectType(item.isDraft); + expectNotType<"DRAFT_ISSUE">(item.type); expectType(item.fields.title); expectNotType<"Title">(item.fields.title); @@ -121,7 +121,7 @@ export async function addItemWithFieldsTest() { }); expectType(item.id); - expectType(item.isDraft); + expectNotType<"DRAFT_ISSUE">(item.type); expectType(item.fields.title); expectNotType<"Title">(item.fields.title); expectType(item.fields.myField); @@ -148,7 +148,7 @@ export async function getItemTest() { return; } - if (item.isDraft === true) { + if (item.type === "DRAFT_ISSUE") { expectType(item.id); expectType(item.fields.title); expectNotType<"Title">(item.fields.title); @@ -157,7 +157,7 @@ export async function getItemTest() { // @ts-expect-error any Property 'notField' does not exist on type item.fields.notField; - // @ts-expect-error - `.content` is not set if `.isDraft` is true + // @ts-expect-error - `.content` is not set if `.type` is "DRAFT_ISSUE" item.content; } else { expectType(item.id); @@ -185,7 +185,7 @@ export async function getItemByContentIdTest() { return; } - if (item.isDraft === true) { + if (item.type === "DRAFT_ISSUE") { expectType(item.id); expectType(item.fields.title); expectNotType<"Title">(item.fields.title); @@ -194,7 +194,7 @@ export async function getItemByContentIdTest() { // @ts-expect-error any Property 'notField' does not exist on type item.fields.notField; - // @ts-expect-error - `.content` is not set if `.isDraft` is true + // @ts-expect-error - `.content` is not set if `.type` is "DRAFT_ISSUE" item.content; } else { expectType(item.id); @@ -225,7 +225,7 @@ export async function getItemByRepositoryAndNumberTest() { return; } - if (item.isDraft === true) { + if (item.type === "DRAFT_ISSUE") { expectType(item.id); expectType(item.fields.title); expectNotType<"Title">(item.fields.title); @@ -234,7 +234,7 @@ export async function getItemByRepositoryAndNumberTest() { // @ts-expect-error any Property 'notField' does not exist on type item.fields.notField; - // @ts-expect-error - `.content` is not set if `.isDraft` is true + // @ts-expect-error - `.content` is not set if `.type` is "DRAFT_ISSUE" item.content; } else { expectType(item.id); @@ -264,7 +264,7 @@ export async function updateItemTest() { return; } - if (item.isDraft === true) { + if (item.type === "DRAFT_ISSUE") { expectType(item.id); expectType(item.fields.title); expectNotType<"Title">(item.fields.title); @@ -273,7 +273,7 @@ export async function updateItemTest() { // @ts-expect-error any Property 'notField' does not exist on type item.fields.notField; - // @ts-expect-error - `.content` is not set if `.isDraft` is true + // @ts-expect-error - `.content` is not set if `.type` is "DRAFT_ISSUE" item.content; } else { expectType(item.id); @@ -303,7 +303,7 @@ export async function updateItemByContentIdTest() { return; } - if (item.isDraft === true) { + if (item.type === "DRAFT_ISSUE") { expectType(item.id); expectType(item.fields.title); expectNotType<"Title">(item.fields.title); @@ -312,7 +312,7 @@ export async function updateItemByContentIdTest() { // @ts-expect-error any Property 'notField' does not exist on type item.fields.notField; - // @ts-expect-error - `.content` is not set if `.isDraft` is true + // @ts-expect-error - `.content` is not set if `.type` is "DRAFT_ISSUE" item.content; } else { expectType(item.id); @@ -346,7 +346,7 @@ export async function updateItemByContentRepositoryAndNumberTest() { return; } - if (item.isDraft === true) { + if (item.type === "DRAFT_ISSUE") { expectType(item.id); expectType(item.fields.title); expectNotType<"Title">(item.fields.title); @@ -355,7 +355,7 @@ export async function updateItemByContentRepositoryAndNumberTest() { // @ts-expect-error any Property 'notField' does not exist on type item.fields.notField; - // @ts-expect-error - `.content` is not set if `.isDraft` is true + // @ts-expect-error - `.content` is not set if `.type` is "DRAFT_ISSUE" item.content; } else { expectType(item.id); diff --git a/test.js b/test.js index c24cee46..8ed78237 100644 --- a/test.js +++ b/test.js @@ -295,13 +295,11 @@ test("project.items.list() without configuring custom fields", async (t) => { id: "PNI_lADOBYMIeM0lfM4AAzDD", fields: { title: "Manual entry", status: null }, type: "DRAFT_ISSUE", - isDraft: true, }, { id: "PNI_lADOBYMIeM0lfM4AAzDx", type: "PULL_REQUEST", fields: { title: "Update README.md", status: "In Progress" }, - isDraft: false, content: { isIssue: false, isPullRequest: true, @@ -326,7 +324,6 @@ test("project.items.list() without configuring custom fields", async (t) => { title: "Enforce setting project via github actions", status: null, }, - isDraft: false, content: { isIssue: true, isPullRequest: false, @@ -615,7 +612,6 @@ test("project.items.add() without configuring custom fields", async (t) => { title: "Enforce setting project via github actions", status: null, }, - isDraft: false, content: { isIssue: true, isPullRequest: false, diff --git a/test.js.md b/test.js.md index b639f4e6..9a057906 100644 --- a/test.js.md +++ b/test.js.md @@ -105,7 +105,6 @@ Generated by [AVA](https://avajs.dev). title: 'Yes', }, id: 'PNI_lADOBYMIeM0lfM4AAzDD', - isDraft: true, type: 'DRAFT_ISSUE', }, { @@ -131,7 +130,6 @@ Generated by [AVA](https://avajs.dev). title: null, }, id: 'PNI_lADOBYMIeM0lfM4AAzDx', - isDraft: false, type: 'PULL_REQUEST', }, { @@ -156,7 +154,6 @@ Generated by [AVA](https://avajs.dev). title: null, }, id: 'PNI_lADOBYMIeM0lfM4ADfm9', - isDraft: false, type: 'ISSUE', }, ] @@ -196,6 +193,5 @@ Generated by [AVA](https://avajs.dev). title: null, }, id: 'PNI_lADOBYMIeM0lfM4ADfm9', - isDraft: false, type: 'ISSUE', } diff --git a/test.js.snap b/test.js.snap index c463f0852978f2e4b05ca6671e6504b578c3f41b..5632205946ae73e7df7f671c9ac2c0988dc8027d 100644 GIT binary patch literal 1726 zcmV;v20{5jRzV5^PaF&Ra11vxaC@? z7l1_dSs#lC00000000B+nO|&ERUF6f?ca4<*X|Ews9+6|2Xt($D6*ie(t(xzV{F8M z2JYI^?y`G(%e}X-p$~)@h-iEe&4SSw2rn9qzDO`Ji$Q`WiYAztXh<+dVhm9pl$gMa z-*dW__S~(dMe2ht`=sCXeA{#GxxfC-@3$ULj4N7f(l~g6n6jymspY#=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