Skip to content

Commit f0b8dc4

Browse files
jorgedc93Jorge DominguezrnorthDan7-7-7
authored
feat(pr-status): add build status to pr-status list table (#129)
* Add build status to pr-status list table * Use correct field for status * Update README * Rename field * add pending status check --------- Co-authored-by: Jorge Dominguez <[email protected]> Co-authored-by: Richard North <[email protected]> Co-authored-by: Danny Ranson <[email protected]> Co-authored-by: Daniel Ranson <[email protected]>
1 parent 77c3a54 commit f0b8dc4

File tree

4 files changed

+137
-30
lines changed

4 files changed

+137
-30
lines changed

README.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,16 @@ Viewing a detailed list of status per repo:
204204
```
205205
$ turbolift pr-status --list
206206
...
207-
Repository State Reviews URL
208-
redacted/redacted OPEN REVIEW_REQUIRED https://github.redacted/redacted/redacted/pull/262
209-
redacted/redacted OPEN REVIEW_REQUIRED https://github.redacted/redacted/redacted/pull/515
210-
redacted/redacted OPEN REVIEW_REQUIRED https://github.redacted/redacted/redacted/pull/342
211-
redacted/redacted MERGED APPROVED https://github.redacted/redacted/redacted/pull/407
212-
redacted/redacted MERGED REVIEW_REQUIRED https://github.redacted/redacted/redacted/pull/220
213-
redacted/redacted OPEN REVIEW_REQUIRED https://github.redacted/redacted/redacted/pull/105
214-
redacted/redacted MERGED APPROVED https://github.redacted/redacted/redacted/pull/532
215-
redacted/redacted MERGED APPROVED https://github.redacted/redacted/redacted/pull/268
216-
redacted/redacted OPEN REVIEW_REQUIRED https://github.redacted/redacted/redacted/pull/438
207+
Repository State Reviews Build status URL
208+
redacted/redacted OPEN REVIEW_REQUIRED SUCCESS https://github.redacted/redacted/redacted/pull/262
209+
redacted/redacted OPEN REVIEW_REQUIRED SUCCESS https://github.redacted/redacted/redacted/pull/515
210+
redacted/redacted OPEN REVIEW_REQUIRED SUCCESS https://github.redacted/redacted/redacted/pull/342
211+
redacted/redacted MERGED APPROVED SUCCESS https://github.redacted/redacted/redacted/pull/407
212+
redacted/redacted MERGED REVIEW_REQUIRED SUCCESS https://github.redacted/redacted/redacted/pull/220
213+
redacted/redacted OPEN REVIEW_REQUIRED FAILURE https://github.redacted/redacted/redacted/pull/105
214+
redacted/redacted MERGED APPROVED SUCCESS https://github.redacted/redacted/redacted/pull/532
215+
redacted/redacted MERGED APPROVED SUCCESS https://github.redacted/redacted/redacted/pull/268
216+
redacted/redacted OPEN REVIEW_REQUIRED FAILURE https://github.redacted/redacted/redacted/pull/438
217217
...
218218
```
219219

cmd/prstatus/prstatus.go

+19-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func run(c *cobra.Command, _ []string) {
8888
statuses := make(map[string]int)
8989
reactions := make(map[string]int)
9090

91-
detailsTable := table.New("Repository", "State", "Reviews", "URL")
91+
detailsTable := table.New("Repository", "State", "Reviews", "Checks status", "URL")
9292
detailsTable.WithHeaderFormatter(color.New(color.Underline).SprintfFunc())
9393
detailsTable.WithFirstColumnFormatter(color.New(color.FgCyan).SprintfFunc())
9494
detailsTable.WithWriter(logger.Writer())
@@ -118,7 +118,24 @@ func run(c *cobra.Command, _ []string) {
118118
reactions[reaction.Content] += reaction.Users.TotalCount
119119
}
120120

121-
detailsTable.AddRow(repo.FullRepoName, prStatus.State, prStatus.ReviewDecision, prStatus.Url)
121+
failedCheck := false
122+
pendingCheck := false
123+
for _, check := range prStatus.StatusCheckRollup {
124+
if strings.Contains(check.State, "FAILURE") {
125+
failedCheck = true
126+
} else if strings.Contains(check.State, "PENDING") {
127+
pendingCheck = true
128+
}
129+
}
130+
131+
checksStatus := "SUCCESS"
132+
if failedCheck {
133+
checksStatus = "FAILURE"
134+
} else if pendingCheck {
135+
checksStatus = "PENDING"
136+
}
137+
138+
detailsTable.AddRow(repo.FullRepoName, prStatus.State, prStatus.ReviewDecision, checksStatus, prStatus.Url)
122139

123140
checkStatusActivity.EndWithSuccess()
124141
}

cmd/prstatus/prstatus_test.go

+93-8
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,20 @@ func TestItLogsSummaryInformation(t *testing.T) {
5656
func TestItLogsDetailedInformation(t *testing.T) {
5757
prepareFakeResponses()
5858

59-
testsupport.PrepareTempCampaign(true, "org/repo1", "org/repo2", "org/repo3")
59+
testsupport.PrepareTempCampaign(true, "org/repo1", "org/repo2", "org/repo3", "org/repo4", "org/repo5", "org/repo6")
6060

6161
out, err := runCommand(true)
6262
assert.NoError(t, err)
6363
// Should still show summary info
64-
assert.Regexp(t, "Open\\s+1", out)
65-
assert.Regexp(t, "👍\\s+4", out)
66-
67-
assert.Regexp(t, "org/repo1\\s+OPEN\\s+REVIEW_REQUIRED", out)
68-
assert.Regexp(t, "org/repo2\\s+MERGED\\s+APPROVED", out)
69-
assert.Regexp(t, "org/repo3\\s+CLOSED", out)
64+
assert.Regexp(t, "Open\\s+4", out)
65+
assert.Regexp(t, "👍\\s+13", out)
66+
67+
assert.Regexp(t, "org/repo1\\s+OPEN\\s+REVIEW_REQUIRED\\s+FAILURE", out)
68+
assert.Regexp(t, "org/repo2\\s+MERGED\\s+APPROVED\\s+SUCCESS", out)
69+
assert.Regexp(t, "org/repo3\\s+CLOSED\\s+FAILURE", out)
70+
assert.Regexp(t, "org/repo4\\s+OPEN\\s+REVIEW_REQUIRED\\s+PENDING", out)
71+
assert.Regexp(t, "org/repo5\\s+OPEN\\s+REVIEW_REQUIRED\\s+FAILURE", out)
72+
assert.Regexp(t, "org/repo6\\s+OPEN\\s+REVIEW_REQUIRED\\s+PENDING", out)
7073
}
7174

7275
func TestItSkipsUnclonedRepos(t *testing.T) {
@@ -119,6 +122,14 @@ func prepareFakeResponses() {
119122
dummyData := map[string]*github.PrStatus{
120123
"work/org/repo1": {
121124
State: "OPEN",
125+
StatusCheckRollup: []github.StatusCheckRollup{
126+
{
127+
State: "FAILURE",
128+
},
129+
{
130+
State: "SUCCESS",
131+
},
132+
},
122133
ReactionGroups: []github.ReactionGroup{
123134
{
124135
Content: "THUMBS_UP",
@@ -137,6 +148,14 @@ func prepareFakeResponses() {
137148
},
138149
"work/org/repo2": {
139150
State: "MERGED",
151+
StatusCheckRollup: []github.StatusCheckRollup{
152+
{
153+
State: "SUCCESS",
154+
},
155+
{
156+
State: "SUCCESS",
157+
},
158+
},
140159
ReactionGroups: []github.ReactionGroup{
141160
{
142161
Content: "THUMBS_UP",
@@ -148,7 +167,13 @@ func prepareFakeResponses() {
148167
ReviewDecision: "APPROVED",
149168
},
150169
"work/org/repo3": {
151-
State: "CLOSED",
170+
State: "CLOSED",
171+
Mergeable: "UNKNOWN",
172+
StatusCheckRollup: []github.StatusCheckRollup{
173+
{
174+
State: "FAILURE",
175+
},
176+
},
152177
ReactionGroups: []github.ReactionGroup{
153178
{
154179
Content: "THUMBS_DOWN",
@@ -158,6 +183,66 @@ func prepareFakeResponses() {
158183
},
159184
},
160185
},
186+
"work/org/repo4": {
187+
State: "OPEN",
188+
StatusCheckRollup: []github.StatusCheckRollup{
189+
{
190+
State: "SUCCESS",
191+
},
192+
{
193+
State: "PENDING",
194+
},
195+
},
196+
ReactionGroups: []github.ReactionGroup{
197+
{
198+
Content: "THUMBS_UP",
199+
Users: github.ReactionGroupUsers{
200+
TotalCount: 3,
201+
},
202+
},
203+
},
204+
ReviewDecision: "REVIEW_REQUIRED",
205+
},
206+
"work/org/repo5": {
207+
State: "OPEN",
208+
StatusCheckRollup: []github.StatusCheckRollup{
209+
{
210+
State: "FAILURE",
211+
},
212+
{
213+
State: "PENDING",
214+
},
215+
},
216+
ReactionGroups: []github.ReactionGroup{
217+
{
218+
Content: "THUMBS_UP",
219+
Users: github.ReactionGroupUsers{
220+
TotalCount: 3,
221+
},
222+
},
223+
},
224+
ReviewDecision: "REVIEW_REQUIRED",
225+
},
226+
"work/org/repo6": {
227+
State: "OPEN",
228+
StatusCheckRollup: []github.StatusCheckRollup{
229+
{
230+
State: "PENDING",
231+
},
232+
{
233+
State: "PENDING",
234+
},
235+
},
236+
ReactionGroups: []github.ReactionGroup{
237+
{
238+
Content: "THUMBS_UP",
239+
Users: github.ReactionGroupUsers{
240+
TotalCount: 3,
241+
},
242+
},
243+
},
244+
ReviewDecision: "REVIEW_REQUIRED",
245+
},
161246
}
162247
fakeGitHub := github.NewFakeGitHub(nil, func(workingDir string) (interface{}, error) {
163248
if workingDir == "work/org/repoWithError" {

internal/github/github.go

+15-10
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,16 @@ type PrStatusResponse struct { // https://github.com/cli/cli/blob/4b415f80d79e57
108108
}
109109

110110
type PrStatus struct {
111-
Closed bool `json:"closed"`
112-
HeadRefName string `json:"headRefName"`
113-
Mergeable string `json:"mergeable"`
114-
Number int `json:"number"`
115-
ReactionGroups []ReactionGroup `json:"reactionGroups"`
116-
ReviewDecision string `json:"reviewDecision"`
117-
State string `json:"state"`
118-
Title string `json:"title"`
119-
Url string `json:"url"`
111+
Closed bool `json:"closed"`
112+
HeadRefName string `json:"headRefName"`
113+
Mergeable string `json:"mergeable"`
114+
Number int `json:"number"`
115+
ReactionGroups []ReactionGroup `json:"reactionGroups"`
116+
ReviewDecision string `json:"reviewDecision"`
117+
State string `json:"state"`
118+
StatusCheckRollup []StatusCheckRollup `json:"statusCheckRollup"`
119+
Title string `json:"title"`
120+
Url string `json:"url"`
120121
}
121122

122123
type ReactionGroupUsers struct {
@@ -128,6 +129,10 @@ type ReactionGroup struct {
128129
Users ReactionGroupUsers
129130
}
130131

132+
type StatusCheckRollup struct {
133+
State string
134+
}
135+
131136
// GetPR is a helper function to retrieve the PR associated with the branch Name
132137
type NoPRFoundError struct {
133138
Path string
@@ -139,7 +144,7 @@ func (e *NoPRFoundError) Error() string {
139144
}
140145

141146
func (r *RealGitHub) GetPR(output io.Writer, workingDir string, branchName string) (*PrStatus, error) {
142-
s, err := execInstance.ExecuteAndCapture(output, workingDir, "gh", "pr", "status", "--json", "closed,headRefName,mergeable,number,reactionGroups,reviewDecision,state,title,url")
147+
s, err := execInstance.ExecuteAndCapture(output, workingDir, "gh", "pr", "status", "--json", "closed,headRefName,mergeable,number,reactionGroups,reviewDecision,state,statusCheckRollup,title,url")
143148
if err != nil {
144149
return nil, err
145150
}

0 commit comments

Comments
 (0)