diff --git a/pkg/commands/git_commands/github.go b/pkg/commands/git_commands/github.go index 06f9ab550..3a6146923 100644 --- a/pkg/commands/git_commands/github.go +++ b/pkg/commands/git_commands/github.go @@ -85,12 +85,25 @@ type PullRequestNode struct { HeadRepositoryOwner GithubRepositoryOwner `json:"headRepositoryOwner"` State string `json:"state"` IsDraft bool `json:"isDraft"` + HeadRef GithubRef `json:"headRef"` } type GithubRepositoryOwner struct { Login string `json:"login"` } +type GithubRef struct { + Target GithubGitObject `json:"target"` +} + +type GithubGitObject struct { + StatusCheckRollup GithubStatusCheckRollup `json:"statusCheckRollup"` +} + +type GithubStatusCheckRollup struct { + State string `json:"state"` +} + type graphQLRequest struct { Query string `json:"query"` Variables map[string]string `json:"variables"` @@ -121,6 +134,15 @@ func fetchPullRequestsQuery(branches []string, owner string, repo string) (strin number url isDraft + headRef { + target { + ... on Commit { + statusCheckRollup { + state + } + } + } + } headRepositoryOwner { login } @@ -249,6 +271,7 @@ func parsePullRequestsResponse(respBytes []byte) ([]*models.GithubPullRequest, e Number: node.Number, Title: node.Title, State: lo.Ternary(node.IsDraft && node.State != "CLOSED", "DRAFT", node.State), + ChecksState: node.HeadRef.Target.StatusCheckRollup.State, Url: node.Url, HeadRepositoryOwner: models.GithubRepositoryOwner{ Login: node.HeadRepositoryOwner.Login, diff --git a/pkg/commands/git_commands/github_test.go b/pkg/commands/git_commands/github_test.go index 664da857d..ce068d750 100644 --- a/pkg/commands/git_commands/github_test.go +++ b/pkg/commands/git_commands/github_test.go @@ -76,6 +76,20 @@ func TestGraphQLEndpoint(t *testing.T) { } } +func TestFetchPullRequestsQueryFetchesOnlyAggregateCheckState(t *testing.T) { + query, variables := fetchPullRequestsQuery([]string{"feature"}, "owner", "repo") + + assert.Contains(t, query, "headRef {") + assert.Contains(t, query, "... on Commit {") + assert.Contains(t, query, "statusCheckRollup {") + assert.NotContains(t, query, "contexts") + assert.Equal(t, map[string]string{ + "owner": "owner", + "repo": "repo", + "branch1": "feature", + }, variables) +} + func TestParsePullRequestsResponse(t *testing.T) { t.Run("flattens aliases and normalizes drafts", func(t *testing.T) { response := []byte(`{ @@ -91,7 +105,12 @@ func TestParsePullRequestsResponse(t *testing.T) { "url": "https://github.com/jesseduffield/lazygit/pull/42", "headRepositoryOwner": {"login": "contributor"}, "state": "OPEN", - "isDraft": false + "isDraft": false, + "headRef": { + "target": { + "statusCheckRollup": {"state": "SUCCESS"} + } + } } } ] @@ -106,7 +125,8 @@ func TestParsePullRequestsResponse(t *testing.T) { "url": "https://github.com/jesseduffield/lazygit/pull/43", "headRepositoryOwner": {"login": "contributor"}, "state": "OPEN", - "isDraft": true + "isDraft": true, + "headRef": null } } ] @@ -124,6 +144,7 @@ func TestParsePullRequestsResponse(t *testing.T) { Number: 42, Title: "Add feature", State: "OPEN", + ChecksState: "SUCCESS", Url: "https://github.com/jesseduffield/lazygit/pull/42", HeadRepositoryOwner: models.GithubRepositoryOwner{Login: "contributor"}, }, @@ -176,6 +197,7 @@ func TestGenerateGithubPullRequestMap(t *testing.T) { Number: 42, Title: "Add feature", State: "OPEN", + ChecksState: "PENDING", Url: "https://github.com/jesseduffield/lazygit/pull/42", HeadRepositoryOwner: models.GithubRepositoryOwner{Login: "jesseduffield"}, }, @@ -199,6 +221,7 @@ func TestGenerateGithubPullRequestMap(t *testing.T) { Number: 42, Title: "Add feature", State: "OPEN", + ChecksState: "PENDING", Url: "https://github.com/jesseduffield/lazygit/pull/42", HeadRepositoryOwner: models.GithubRepositoryOwner{Login: "jesseduffield"}, }, diff --git a/pkg/commands/models/github.go b/pkg/commands/models/github.go index 6477c6ee6..da7bd79db 100644 --- a/pkg/commands/models/github.go +++ b/pkg/commands/models/github.go @@ -5,6 +5,7 @@ type GithubPullRequest struct { Number int `json:"number"` Title string `json:"title"` State string `json:"state"` // "MERGED", "OPEN", "CLOSED", "DRAFT" + ChecksState string `json:"checksState"` Url string `json:"url"` HeadRepositoryOwner GithubRepositoryOwner `json:"headRepositoryOwner"` } diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index d81a1402c..a0be00329 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -850,6 +850,7 @@ type CachedPullRequest struct { Number int `yaml:"number"` Title string `yaml:"title"` State string `yaml:"state"` + ChecksState string `yaml:"checksState,omitempty"` Url string `yaml:"url"` HeadRepositoryOwner string `yaml:"headRepositoryOwner"` } diff --git a/pkg/gui/controllers/helpers/refresh_helper.go b/pkg/gui/controllers/helpers/refresh_helper.go index 29784b5ff..29fb66be2 100644 --- a/pkg/gui/controllers/helpers/refresh_helper.go +++ b/pkg/gui/controllers/helpers/refresh_helper.go @@ -1770,6 +1770,7 @@ func (self *RefreshHelper) savePullRequestsToCache(prs []*models.GithubPullReque Number: pr.Number, Title: pr.Title, State: pr.State, + ChecksState: pr.ChecksState, Url: pr.Url, HeadRepositoryOwner: pr.HeadRepositoryOwner.Login, } diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index e1d387370..f536d5b64 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -674,6 +674,7 @@ func (gui *Gui) loadCachedPullRequests() []*models.GithubPullRequest { Number: cached.Number, Title: cached.Title, State: cached.State, + ChecksState: cached.ChecksState, Url: cached.Url, HeadRepositoryOwner: models.GithubRepositoryOwner{ Login: cached.HeadRepositoryOwner,