Skip to content

Commit

Permalink
feat: changed pull-request by graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Aug 25, 2024
1 parent 31cb560 commit 4de373f
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ static/dist
.env
junit.xml
coverage
test-dashboard.md
6 changes: 6 additions & 0 deletions graphql.config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
schema:
- https://api.github.com/graphql:
headers:
Authorization: Bearer ${GITHUB_TOKEN}
documents: src/*
projects: {}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"dependencies": {
"@actions/core": "1.10.1",
"@actions/github": "6.0.0",
"@octokit/graphql-schema": "15.25.0",
"@octokit/plugin-retry": "6.0.1",
"@octokit/rest": "20.1.0",
"@octokit/webhooks": "13.2.7",
Expand Down
35 changes: 34 additions & 1 deletion src/data-collection/collect-linked-pulls.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
import { GitHubLinkEvent, isGitHubLinkEvent } from "../github-types";
import { IssueParams, getAllTimelineEvents, parseGitHubUrl } from "../start";
import { getAllTimelineEvents, IssueParams, parseGitHubUrl } from "../start";
import { getOctokitInstance } from "../octokit";
import { LINKED_PULL_REQUESTS } from "../types/requests";
import { PullRequest, Repository, User } from "@octokit/graphql-schema";

type ClosedByPullRequestsReferences = {
node: Pick<PullRequest, "url" | "title" | "number" | "state" | "body"> & {
author: Pick<User, "login" | "id">;
repository: Pick<Repository, "owner" | "name">;
};
};

type IssueWithClosedByPRs = {
repository: {
issue: {
closedByPullRequestsReferences: {
edges: ClosedByPullRequestsReferences[];
};
};
};
};

export async function collectLinkedMergedPulls2(issue: IssueParams) {
const octokit = getOctokitInstance();
const { owner, repo, issue_number } = issue;

const result = await octokit.graphql<IssueWithClosedByPRs>(LINKED_PULL_REQUESTS, {
owner,
repo,
issue_number,
});

return result.repository.issue.closedByPullRequestsReferences.edges.map((edge) => edge.node);
}

export async function collectLinkedMergedPulls(issue: IssueParams) {
// normally we should only use this one to calculate incentives, because this specifies that the pull requests are merged (accepted)
Expand Down
11 changes: 6 additions & 5 deletions src/issue-activity.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CommentAssociation, CommentKind } from "./configuration/comment-types";
import configuration from "./configuration/config-reader";
import { DataCollectionConfiguration } from "./configuration/data-collection-config";
import { collectLinkedMergedPulls } from "./data-collection/collect-linked-pulls";
import { collectLinkedMergedPulls2 } from "./data-collection/collect-linked-pulls";
import {
GitHubIssue,
GitHubIssueComment,
Expand Down Expand Up @@ -46,19 +46,20 @@ export class IssueActivity {
}

private async _getLinkedReviews(): Promise<Review[]> {
const pulls = await collectLinkedMergedPulls(this._issueParams);
const pulls = await collectLinkedMergedPulls2(this._issueParams);
logger.debug("Collected linked pull-requests", { pulls });
const promises = pulls
.map(async (pull) => {
const repository = pull.source.issue.repository;
const repository = pull.repository;

if (!repository) {
console.error(`No repository found for [${pull.source.issue.repository}]`);
logger.error(`No repository found for`, { ...pull.repository });
return null;
} else {
const pullParams = {
owner: repository.owner.login,
repo: repository.name,
pull_number: pull.source.issue.number,
pull_number: pull.number,
};
const review = new Review(pullParams);
await review.init();
Expand Down
30 changes: 30 additions & 0 deletions src/types/requests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export const LINKED_PULL_REQUESTS = /* GraphQL */ `
query collectLinkedPullRequests($owner: String!, $repo: String!, $issue_number: Int!) {
repository(owner: $owner, name: $repo) {
issue(number: $issue_number) {
id
closedByPullRequestsReferences(first: 100, includeClosedPrs: true) {
edges {
node {
id
title
number
author {
login
... on User {
id: databaseId
}
}
repository {
owner {
login
}
name
}
}
}
}
}
}
}
`;
22 changes: 21 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2606,6 +2606,14 @@
"@octokit/types" "^13.1.0"
universal-user-agent "^6.0.0"

"@octokit/[email protected]":
version "15.25.0"
resolved "https://registry.yarnpkg.com/@octokit/graphql-schema/-/graphql-schema-15.25.0.tgz#30bb8ecc494c249650991b33f2f0d9332dbe87e9"
integrity sha512-aqz9WECtdxVWSqgKroUu9uu+CRt5KnfErWs0dBPKlTdrreAeWzS5NRu22ZVcGdPP7s3XDg2Gnf5iyoZPCRZWmQ==
dependencies:
graphql "^16.0.0"
graphql-tag "^2.10.3"

"@octokit/graphql@^7.1.0":
version "7.1.0"
resolved "https://registry.yarnpkg.com/@octokit/graphql/-/graphql-7.1.0.tgz#9bc1c5de92f026648131f04101cab949eeffe4e0"
Expand Down Expand Up @@ -5330,7 +5338,14 @@ graphemer@^1.4.0:
resolved "https://registry.yarnpkg.com/graphemer/-/graphemer-1.4.0.tgz#fb2f1d55e0e3a1849aeffc90c4fa0dd53a0e66c6"
integrity sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==

graphql@^16.8.1:
graphql-tag@^2.10.3:
version "2.12.6"
resolved "https://registry.yarnpkg.com/graphql-tag/-/graphql-tag-2.12.6.tgz#d441a569c1d2537ef10ca3d1633b48725329b5f1"
integrity sha512-FdSNcu2QQcWnM2VNvSCCDCVS5PpPqpzgFT8+GXzqJuoDd0CBncxCY278u4mhRO7tMgo2JjgJA5aZ+nWSQ/Z+xg==
dependencies:
tslib "^2.1.0"

graphql@^16.0.0, graphql@^16.8.1:
version "16.9.0"
resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.9.0.tgz#1c310e63f16a49ce1fbb230bd0a000e99f6f115f"
integrity sha512-GGTKBX4SD7Wdb8mqeDLni2oaRGYQWjWHGKPQ24ZMnUtKfcsVoiv4uX8+LJr1K6U5VW2Lu1BwJnj7uiori0YtRw==
Expand Down Expand Up @@ -8350,6 +8365,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.0.tgz#7cecaa7f073ce680a05847aa77be941098f36dc3"
integrity sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==

tslib@^2.1.0:
version "2.7.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.7.0.tgz#d9b40c5c40ab59e8738f297df3087bf1a2690c01"
integrity sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==

[email protected]:
version "4.7.1"
resolved "https://registry.yarnpkg.com/tsx/-/tsx-4.7.1.tgz#27af6cbf4e1cdfcb9b5425b1c61bb7e668eb5e84"
Expand Down

0 comments on commit 4de373f

Please sign in to comment.