Merge pull request #530 from doi-t/issue-467

Ability to differentiate pull requests by their state
This commit is contained in:
Nate Smith 2020-03-02 16:12:55 -06:00 committed by GitHub
commit fdf940eeba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 8 deletions

View file

@ -10,7 +10,7 @@ import (
type PullRequestsPayload struct {
ViewerCreated PullRequestAndTotalCount
ReviewRequested PullRequestAndTotalCount
CurrentPR *PullRequest
CurrentPRs []PullRequest
}
type PullRequestAndTotalCount struct {
@ -151,6 +151,7 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
fragment pr on PullRequest {
number
title
state
url
headRefName
headRepositoryOwner {
@ -187,7 +188,7 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
queryPrefix := `
query($owner: String!, $repo: String!, $headRefName: String!, $viewerQuery: String!, $reviewerQuery: String!, $per_page: Int = 10) {
repository(owner: $owner, name: $repo) {
pullRequests(headRefName: $headRefName, states: OPEN, first: $per_page) {
pullRequests(headRefName: $headRefName, first: $per_page, orderBy: { field: CREATED_AT, direction: DESC }) {
totalCount
edges {
node {
@ -261,11 +262,13 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
reviewRequested = append(reviewRequested, edge.Node)
}
var currentPR = resp.Repository.PullRequest
if currentPR == nil {
var currentPRs []PullRequest
if resp.Repository.PullRequest != nil {
currentPRs = append(currentPRs, *resp.Repository.PullRequest)
} else {
for _, edge := range resp.Repository.PullRequests.Edges {
if edge.Node.HeadLabel() == currentPRHeadRef {
currentPR = &edge.Node
currentPRs = append(currentPRs, edge.Node)
}
}
}
@ -279,7 +282,7 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
PullRequests: reviewRequested,
TotalCount: resp.ReviewRequested.TotalCount,
},
CurrentPR: currentPR,
CurrentPRs: currentPRs,
}
return &payload, nil