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: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
Browsers
</th><td width=100%>
Load <code>github-project</code> directly from <a href="https://cdn.skypack.dev">cdn.skypack.dev</a>

```html
<script type="module">
import GitHubProject from "https://cdn.skypack.dev/github-project";
import GitHubProject from "https://cdn.skypack.dev/github-project";
</script>
```

Expand Down Expand Up @@ -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(",")
);
Expand Down
2 changes: 1 addition & 1 deletion api/items.get-by-content-repository-and-number.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
2 changes: 1 addition & 1 deletion api/items.remove-by-content-repository-and-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
2 changes: 1 addition & 1 deletion api/items.update-by-content-repository-and-number.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
4 changes: 1 addition & 3 deletions api/lib/project-item-node-to-github-project-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

Expand Down Expand Up @@ -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,
};
Expand Down
2 changes: 0 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,11 @@ type DraftItem<TFields> = {
id: string;
type: "DRAFT_ISSUE";
fields: TFields;
isDraft: true;
};
type NonDraftItem<TFields> = {
id: string;
type: "ISSUE" | "PULL_REQUEST" | "REDACTED";
fields: TFields;
isDraft: false;
content: Issue | PullRequest;
};

Expand Down
32 changes: 16 additions & 16 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ export async function listItemsTest() {
});
const [item] = await project.items.list();

if (item.isDraft === true) {
if (item.type === "DRAFT_ISSUE") {
expectType<string>(item.id);
expectType<string | null>(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<string>(item.id);
Expand All @@ -100,7 +100,7 @@ export async function addItemTest() {
const item = await project.items.add("issue node_id");

expectType<string>(item.id);
expectType<false>(item.isDraft);
expectNotType<"DRAFT_ISSUE">(item.type);
expectType<string | null>(item.fields.title);
expectNotType<"Title">(item.fields.title);

Expand All @@ -121,7 +121,7 @@ export async function addItemWithFieldsTest() {
});

expectType<string>(item.id);
expectType<false>(item.isDraft);
expectNotType<"DRAFT_ISSUE">(item.type);
expectType<string | null>(item.fields.title);
expectNotType<"Title">(item.fields.title);
expectType<string | null>(item.fields.myField);
Expand All @@ -148,7 +148,7 @@ export async function getItemTest() {
return;
}

if (item.isDraft === true) {
if (item.type === "DRAFT_ISSUE") {
expectType<string>(item.id);
expectType<string | null>(item.fields.title);
expectNotType<"Title">(item.fields.title);
Expand All @@ -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<string>(item.id);
Expand Down Expand Up @@ -185,7 +185,7 @@ export async function getItemByContentIdTest() {
return;
}

if (item.isDraft === true) {
if (item.type === "DRAFT_ISSUE") {
expectType<string>(item.id);
expectType<string | null>(item.fields.title);
expectNotType<"Title">(item.fields.title);
Expand All @@ -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<string>(item.id);
Expand Down Expand Up @@ -225,7 +225,7 @@ export async function getItemByRepositoryAndNumberTest() {
return;
}

if (item.isDraft === true) {
if (item.type === "DRAFT_ISSUE") {
expectType<string>(item.id);
expectType<string | null>(item.fields.title);
expectNotType<"Title">(item.fields.title);
Expand All @@ -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<string>(item.id);
Expand Down Expand Up @@ -264,7 +264,7 @@ export async function updateItemTest() {
return;
}

if (item.isDraft === true) {
if (item.type === "DRAFT_ISSUE") {
expectType<string>(item.id);
expectType<string | null>(item.fields.title);
expectNotType<"Title">(item.fields.title);
Expand All @@ -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<string>(item.id);
Expand Down Expand Up @@ -303,7 +303,7 @@ export async function updateItemByContentIdTest() {
return;
}

if (item.isDraft === true) {
if (item.type === "DRAFT_ISSUE") {
expectType<string>(item.id);
expectType<string | null>(item.fields.title);
expectNotType<"Title">(item.fields.title);
Expand All @@ -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<string>(item.id);
Expand Down Expand Up @@ -346,7 +346,7 @@ export async function updateItemByContentRepositoryAndNumberTest() {
return;
}

if (item.isDraft === true) {
if (item.type === "DRAFT_ISSUE") {
expectType<string>(item.id);
expectType<string | null>(item.fields.title);
expectNotType<"Title">(item.fields.title);
Expand All @@ -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<string>(item.id);
Expand Down
4 changes: 0 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ Generated by [AVA](https://avajs.dev).
title: 'Yes',
},
id: 'PNI_lADOBYMIeM0lfM4AAzDD',
isDraft: true,
type: 'DRAFT_ISSUE',
},
{
Expand All @@ -131,7 +130,6 @@ Generated by [AVA](https://avajs.dev).
title: null,
},
id: 'PNI_lADOBYMIeM0lfM4AAzDx',
isDraft: false,
type: 'PULL_REQUEST',
},
{
Expand All @@ -156,7 +154,6 @@ Generated by [AVA](https://avajs.dev).
title: null,
},
id: 'PNI_lADOBYMIeM0lfM4ADfm9',
isDraft: false,
type: 'ISSUE',
},
]
Expand Down Expand Up @@ -196,6 +193,5 @@ Generated by [AVA](https://avajs.dev).
title: null,
},
id: 'PNI_lADOBYMIeM0lfM4ADfm9',
isDraft: false,
type: 'ISSUE',
}
Binary file modified test.js.snap
Binary file not shown.
1 change: 0 additions & 1 deletion test/fixtures/add-item/issue/new-issue-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export const newIssueItemFixture = {
relevantToUsers: null,
suggestedChangelog: null,
},
isDraft: false,
content: {
isIssue: true,
isPullRequest: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export const newPullRequestItemFixture = {
relevantToUsers: null,
suggestedChangelog: null,
},
isDraft: false,
content: {
isIssue: false,
isPullRequest: true,
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/get-item/draft-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ export const draftItemFixture = {
relevantToUsers: "Yes",
suggestedChangelog: null,
},
isDraft: true,
};
1 change: 0 additions & 1 deletion test/fixtures/get-item/issue-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export const issueItemFixture = {
relevantToUsers: null,
suggestedChangelog: null,
},
isDraft: false,
content: {
isIssue: true,
isPullRequest: false,
Expand Down
3 changes: 0 additions & 3 deletions test/fixtures/list-items/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const listItemsFixture = [
relevantToUsers: "Yes",
suggestedChangelog: null,
},
isDraft: true,
},
{
id: "PNI_lADOBYMIeM0lfM4AAzDx",
Expand All @@ -19,7 +18,6 @@ export const listItemsFixture = [
relevantToUsers: null,
suggestedChangelog: null,
},
isDraft: false,
content: {
isIssue: false,
isPullRequest: true,
Expand All @@ -46,7 +44,6 @@ export const listItemsFixture = [
relevantToUsers: null,
suggestedChangelog: null,
},
isDraft: false,
content: {
isIssue: true,
isPullRequest: false,
Expand Down