Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/comment pagination #53

Draft
wants to merge 3 commits into
base: trunk
Choose a base branch
from
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
248 changes: 244 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/github": "^6.0.0",
"@octokit/plugin-paginate-graphql": "^4.0.0",
"node-fetch": "^3.3.2"
},
"devDependencies": {
Expand Down
27 changes: 22 additions & 5 deletions src/github.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import * as core from "@actions/core";
import * as github from "@actions/github";
import {paginateGraphql} from "@octokit/plugin-paginate-graphql";
import { GitHub as OctokitPluginUtil, getOctokitOptions } from '@actions/github/lib/utils'

export default class GitHub {
constructor() {
const token = core.getInput("token") || process.env.GITHUB_TOKEN || "";
this.octokit = github.getOctokit(token);
// Exit early if no token is provided.
if (token.length === 0) {
core.error("No GitHub token provided.");
}

// Create a new Octokit class instance with the paginateGraphql plugin.
this.octokitInstance = OctokitPluginUtil.plugin(paginateGraphql);
// Instantiate the Octokit class with the paginateGraphql plugin.
this.octokit = this.octokitInstance(getOctokitOptions(token));
}

/**
Expand Down Expand Up @@ -34,8 +43,12 @@ export default class GitHub {
async getContributorData({ owner, repo, prNumber }) {
core.info('Gathering contributor list.');

const data = await this.octokit.graphql(
`query($owner:String!, $name:String!, $prNumber:Int!) {
const ownerTest = 'WordPress';
const repoTest = 'gutenberg';
const prNumberTest = 57841;

const data = await this.octokit.graphql.paginateGraphql(
`query($owner:String!, $name:String!, $prNumber:Int!, $cursor: String) {
repository(owner:$owner, name:$name) {
pullRequest(number:$prNumber) {
commits(first: 100) {
Expand Down Expand Up @@ -67,6 +80,10 @@ export default class GitHub {
login
}
}
pageInfo {
hasNextPage
endCursor
}
}
closingIssuesReferences(first:100){
nodes {
Expand All @@ -85,7 +102,7 @@ export default class GitHub {
}
}
}`,
{ owner, name: repo, prNumber }
{ ownerTest, name: repoTest, prNumberTest }
);

return data?.repository?.pullRequest;
Expand Down