Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Trigger bot to cleanup columns #352

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 6 additions & 11 deletions src/queries/all-open-prs-query.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { gql, TypedDocumentNode } from "@apollo/client/core";
import { client } from "../graphql-client";
import { GetAllOpenPRsAndCardIDs, GetAllOpenPRsAndCardIDsVariables } from "./schema/GetAllOpenPRsAndCardIDs";
import { GetAllOpenPRs, GetAllOpenPRsVariables } from "./schema/GetAllOpenPRs";
import { noNullish } from "../util/util";

export const getAllOpenPRsAndCardIDsQuery: TypedDocumentNode<GetAllOpenPRsAndCardIDs, GetAllOpenPRsAndCardIDsVariables> = gql`
query GetAllOpenPRsAndCardIDs($endCursor: String) {
export const getAllOpenPRsQuery: TypedDocumentNode<GetAllOpenPRs, GetAllOpenPRsVariables> = gql`
query GetAllOpenPRs($endCursor: String) {
repository(owner: "DefinitelyTyped", name: "DefinitelyTyped") {
id
pullRequests(states: OPEN, orderBy: { field: UPDATED_AT, direction: DESC }, first: 100, after: $endCursor) {
nodes {
number
projectCards(first: 100) { nodes { id } }
}
pageInfo {
hasNextPage
Expand All @@ -20,22 +19,18 @@ query GetAllOpenPRsAndCardIDs($endCursor: String) {
}
}`;

export async function getAllOpenPRsAndCardIDs() {
export async function getAllOpenPRs() {
const prNumbers: number[] = [];
const cardIDs: string[] = [];
let endCursor: string | undefined | null;
while (true) {
const result = await client.query({
query: getAllOpenPRsAndCardIDsQuery,
query: getAllOpenPRsQuery,
fetchPolicy: "no-cache",
variables: { endCursor },
});
prNumbers.push(...noNullish(result.data.repository?.pullRequests.nodes).map(pr => pr.number));
for (const pr of noNullish(result.data.repository?.pullRequests.nodes)) {
cardIDs.push(...noNullish(pr.projectCards.nodes).map(card => card.id));
}
if (!result.data.repository?.pullRequests.pageInfo.hasNextPage) {
return { prNumbers, cardIDs };
return prNumbers;
}
endCursor = result.data.repository.pullRequests.pageInfo.endCursor;
}
Expand Down
26 changes: 0 additions & 26 deletions src/queries/card-id-to-pr-query.ts

This file was deleted.

38 changes: 15 additions & 23 deletions src/queries/projectboard-cards.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { gql, TypedDocumentNode } from "@apollo/client/core";
import { client } from "../graphql-client";
import { GetProjectBoardCards } from "./schema/GetProjectBoardCards";
import { noNullish } from "../util/util";

const GetProjectBoardCardsQuery: TypedDocumentNode<GetProjectBoardCards, never> = gql`
query GetProjectBoardCards {
Expand All @@ -17,6 +18,11 @@ const GetProjectBoardCardsQuery: TypedDocumentNode<GetProjectBoardCards, never>
nodes {
id
updatedAt
content {
... on PullRequest {
number
}
}
}
}
}
Expand All @@ -25,16 +31,6 @@ const GetProjectBoardCardsQuery: TypedDocumentNode<GetProjectBoardCards, never>
}
}`;

interface CardInfo {
id: string;
updatedAt: string;
}
interface ColumnInfo {
name: string;
totalCount: number;
cards: CardInfo[];
}

export async function getProjectBoardCards() {
const results = await client.query({
query: GetProjectBoardCardsQuery,
Expand All @@ -47,17 +43,13 @@ export async function getProjectBoardCards() {
throw new Error("No project found");
}

const columns: ColumnInfo[] = [];
project.columns.nodes?.forEach(col => {
if (!col) return;
const cards: CardInfo[] = [];
col.cards.nodes?.forEach(card => card && cards.push({ id: card.id, updatedAt: card.updatedAt }));
columns.push({
name: col.name,
totalCount: col.cards.totalCount,
cards,
});
});

return columns;
return noNullish(project.columns.nodes).map(column => ({
name: column.name,
totalCount: column.cards.totalCount,
cards: noNullish(column.cards.nodes).map(card => ({
id: card.id,
updatedAt: card.updatedAt,
number: card.content && "number" in card.content ? card.content.number : undefined,
})),
}));
}
53 changes: 0 additions & 53 deletions src/queries/schema/CardIdToPr.ts

This file was deleted.

60 changes: 60 additions & 0 deletions src/queries/schema/GetAllOpenPRs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* tslint:disable */
/* eslint-disable */
// @generated
// This file was automatically generated and should not be edited.

// ====================================================
// GraphQL query operation: GetAllOpenPRs
// ====================================================

export interface GetAllOpenPRs_repository_pullRequests_nodes {
__typename: "PullRequest";
/**
* Identifies the pull request number.
*/
number: number;
}

export interface GetAllOpenPRs_repository_pullRequests_pageInfo {
__typename: "PageInfo";
/**
* When paginating forwards, are there more items?
*/
hasNextPage: boolean;
/**
* When paginating forwards, the cursor to continue.
*/
endCursor: string | null;
}

export interface GetAllOpenPRs_repository_pullRequests {
__typename: "PullRequestConnection";
/**
* A list of nodes.
*/
nodes: (GetAllOpenPRs_repository_pullRequests_nodes | null)[] | null;
/**
* Information to aid in pagination.
*/
pageInfo: GetAllOpenPRs_repository_pullRequests_pageInfo;
}

export interface GetAllOpenPRs_repository {
__typename: "Repository";
id: string;
/**
* A list of pull requests that have been opened in the repository.
*/
pullRequests: GetAllOpenPRs_repository_pullRequests;
}

export interface GetAllOpenPRs {
/**
* Lookup a given repository by the owner and repository name.
*/
repository: GetAllOpenPRs_repository | null;
}

export interface GetAllOpenPRsVariables {
endCursor?: string | null;
}
77 changes: 0 additions & 77 deletions src/queries/schema/GetAllOpenPRsAndCardIDs.ts

This file was deleted.

18 changes: 18 additions & 0 deletions src/queries/schema/GetProjectBoardCards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,31 @@
// GraphQL query operation: GetProjectBoardCards
// ====================================================

export interface GetProjectBoardCards_repository_project_columns_nodes_cards_nodes_content_Issue {
__typename: "Issue";
}

export interface GetProjectBoardCards_repository_project_columns_nodes_cards_nodes_content_PullRequest {
__typename: "PullRequest";
/**
* Identifies the pull request number.
*/
number: number;
}

export type GetProjectBoardCards_repository_project_columns_nodes_cards_nodes_content = GetProjectBoardCards_repository_project_columns_nodes_cards_nodes_content_Issue | GetProjectBoardCards_repository_project_columns_nodes_cards_nodes_content_PullRequest;

export interface GetProjectBoardCards_repository_project_columns_nodes_cards_nodes {
__typename: "ProjectCard";
id: string;
/**
* Identifies the date and time when the object was last updated.
*/
updatedAt: any;
/**
* The card content item
*/
content: GetProjectBoardCards_repository_project_columns_nodes_cards_nodes_content | null;
}

export interface GetProjectBoardCards_repository_project_columns_nodes_cards {
Expand Down
Loading