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

Paginate fetching pulls #141

Draft
wants to merge 1 commit into
base: main
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
67 changes: 45 additions & 22 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,33 +505,56 @@ class PullsHelper {
params.head = head;
if (base.length > 0)
params.base = base;
const query = `query Pulls($owner: String!, $repo: String!, $head: String, $base: String) {
repository(owner:$owner, name:$repo) {
pullRequests(first: 100, states: OPEN, headRefName: $head, baseRefName: $base) {
edges {
node {
baseRefName
headRefName
headRepository {
nameWithOwner
url
}
headRepositoryOwner {
login
}
isDraft
labels(first: 100) {
nodes {
name
const pulls = {
repository: {
pullRequests: {
edges: [],
pageInfo: {
hasNextPage: false
}
}
}
};
let cursor = undefined;
do {
const query = `query Pulls($owner: String!, $repo: String!, $head: String, $base: String, $cursor: String) {
repository(owner:$owner, name:$repo) {
pullRequests(first: 100, states: OPEN, headRefName: $head, baseRefName: $base, after: $cursor) {
edges {
cursor
node {
baseRefName
headRefName
headRepository {
nameWithOwner
url
}
headRepositoryOwner {
login
}
isDraft
labels(first: 100) {
nodes {
name
}
}
maintainerCanModify
}
maintainerCanModify
}
pageInfo {
hasNextPage
}
}
}
}
}`;
const pulls = yield this.octokit.graphql(query, params);
}`;
params.cursor = cursor;
const result = yield this.octokit.graphql(query, params);
pulls.repository.pullRequests.edges.push(...result.repository.pullRequests.edges);
const pageInfo = result.repository.pullRequests.pageInfo;
cursor = pageInfo.hasNextPage
? result.repository.pullRequests.edges[result.repository.pullRequests.edges.length - 1].cursor
: undefined;
} while (cursor);
core.debug(`Pulls: ${(0, util_1.inspect)(pulls.repository.pullRequests.edges)}`);
const filteredPulls = pulls.repository.pullRequests.edges
.map(p => {
Expand Down
78 changes: 56 additions & 22 deletions src/pulls-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,63 @@ export class PullsHelper {
}
if (head.length > 0) params.head = head
if (base.length > 0) params.base = base
const query = `query Pulls($owner: String!, $repo: String!, $head: String, $base: String) {
repository(owner:$owner, name:$repo) {
pullRequests(first: 100, states: OPEN, headRefName: $head, baseRefName: $base) {
edges {
node {
baseRefName
headRefName
headRepository {
nameWithOwner
url
}
headRepositoryOwner {
login
}
isDraft
labels(first: 100) {
nodes {
name

const pulls: Pulls = {
repository: {
pullRequests: {
edges: [],
pageInfo: {
hasNextPage: false
}
}
}
}
let cursor: string | undefined = undefined

do {
const query = `query Pulls($owner: String!, $repo: String!, $head: String, $base: String, $cursor: String) {
repository(owner:$owner, name:$repo) {
pullRequests(first: 100, states: OPEN, headRefName: $head, baseRefName: $base, after: $cursor) {
edges {
cursor
node {
baseRefName
headRefName
headRepository {
nameWithOwner
url
}
headRepositoryOwner {
login
}
isDraft
labels(first: 100) {
nodes {
name
}
}
maintainerCanModify
}
maintainerCanModify
}
pageInfo {
hasNextPage
}
}
}
}
}`
const pulls = await this.octokit.graphql<Pulls>(query, params)
}`
params.cursor = cursor
const result = await this.octokit.graphql<Pulls>(query, params)
pulls.repository.pullRequests.edges.push(
...result.repository.pullRequests.edges
)
const pageInfo = result.repository.pullRequests.pageInfo
cursor = pageInfo.hasNextPage
? result.repository.pullRequests.edges[
result.repository.pullRequests.edges.length - 1
].cursor
: undefined
} while (cursor)

core.debug(`Pulls: ${inspect(pulls.repository.pullRequests.edges)}`)

const filteredPulls = pulls.repository.pullRequests.edges
Expand Down Expand Up @@ -103,6 +133,7 @@ type Label = {
}

type Edge = {
cursor: string
node: {
baseRefName: string
headRefName: string
Expand All @@ -125,6 +156,9 @@ type Pulls = {
repository: {
pullRequests: {
edges: Edge[]
pageInfo: {
hasNextPage: boolean
}
}
}
}
Expand Down