X Tutup
Skip to content

Commit 85ff75e

Browse files
author
vilmibm
committed
fix PR matching
1 parent 7d55ab1 commit 85ff75e

File tree

4 files changed

+70
-30
lines changed

4 files changed

+70
-30
lines changed

pkg/cmd/run/shared/shared.go

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,48 @@ import (
1515

1616
const (
1717
// Run statuses
18-
Queued = "queued"
19-
Completed = "completed"
20-
InProgress = "in_progress"
21-
Requested = "requested"
22-
Waiting = "waiting"
18+
Queued Status = "queued"
19+
Completed Status = "completed"
20+
InProgress Status = "in_progress"
21+
Requested Status = "requested"
22+
Waiting Status = "waiting"
2323

2424
// Run conclusions
25-
ActionRequired = "action_required"
26-
Cancelled = "cancelled"
27-
Failure = "failure"
28-
Neutral = "neutral"
29-
Skipped = "skipped"
30-
Stale = "stale"
31-
StartupFailure = "startup_failure"
32-
Success = "success"
33-
TimedOut = "timed_out"
25+
ActionRequired Conclusion = "action_required"
26+
Cancelled Conclusion = "cancelled"
27+
Failure Conclusion = "failure"
28+
Neutral Conclusion = "neutral"
29+
Skipped Conclusion = "skipped"
30+
Stale Conclusion = "stale"
31+
StartupFailure Conclusion = "startup_failure"
32+
Success Conclusion = "success"
33+
TimedOut Conclusion = "timed_out"
3434
)
3535

3636
type Status string
3737
type Conclusion string
38-
type RunEvent string
3938

4039
type Run struct {
41-
Name string
42-
CreatedAt time.Time `json:"created_at"`
43-
UpdatedAt time.Time `json:"updated_at"`
44-
Status Status
45-
Conclusion Conclusion
46-
Event RunEvent
47-
ID int
48-
HeadBranch string `json:"head_branch"`
49-
JobsURL string `json:"jobs_url"`
50-
HeadCommit Commit `json:"head_commit"`
51-
HeadSha string `json:"head_sha"`
52-
URL string `json:"html_url"`
40+
Name string
41+
CreatedAt time.Time `json:"created_at"`
42+
UpdatedAt time.Time `json:"updated_at"`
43+
Status Status
44+
Conclusion Conclusion
45+
Event string
46+
ID int
47+
HeadBranch string `json:"head_branch"`
48+
JobsURL string `json:"jobs_url"`
49+
HeadCommit Commit `json:"head_commit"`
50+
HeadSha string `json:"head_sha"`
51+
URL string `json:"html_url"`
52+
HeadRepository Repo `json:"head_repository"`
53+
}
54+
55+
type Repo struct {
56+
Owner struct {
57+
Login string
58+
}
59+
Name string
5360
}
5461

5562
type Commit struct {

pkg/cmd/run/shared/test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ func TestRun(name string, id int, s Status, c Conclusion) Run {
3232
},
3333
HeadSha: "1234567890",
3434
URL: fmt.Sprintf("runs/%d", id),
35+
HeadRepository: Repo{
36+
Owner: struct{ Login string }{Login: "OWNER"},
37+
Name: "REPO",
38+
},
3539
}
3640
}
3741

pkg/cmd/run/view/view.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,13 @@ func prForRun(client *api.Client, repo ghrepo.Interface, run shared.Run) (int, e
205205
Repository struct {
206206
PullRequests struct {
207207
Nodes []struct {
208-
Number int
208+
Number int
209+
HeadRepository struct {
210+
Owner struct {
211+
Login string
212+
}
213+
Name string
214+
}
209215
}
210216
}
211217
}
@@ -224,6 +230,12 @@ func prForRun(client *api.Client, repo ghrepo.Interface, run shared.Run) (int, e
224230
pullRequests(headRefName: $headRefName, first: 1, orderBy: { field: CREATED_AT, direction: DESC }) {
225231
nodes {
226232
number
233+
headRepository {
234+
owner {
235+
login
236+
}
237+
name
238+
}
227239
}
228240
}
229241
}
@@ -241,5 +253,17 @@ func prForRun(client *api.Client, repo ghrepo.Interface, run shared.Run) (int, e
241253
return -1, fmt.Errorf("no matching PR found for %s", run.HeadBranch)
242254
}
243255

244-
return prs[0].Number, nil
256+
number := -1
257+
258+
for _, pr := range prs {
259+
if pr.HeadRepository.Owner.Login == run.HeadRepository.Owner.Login && pr.HeadRepository.Name == run.HeadRepository.Name {
260+
number = pr.Number
261+
}
262+
}
263+
264+
if number == -1 {
265+
return number, fmt.Errorf("no matching PR found for %s", run.HeadBranch)
266+
}
267+
268+
return number, nil
245269
}

pkg/cmd/run/view/view_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,12 @@ func TestViewRun(t *testing.T) {
129129
"repository": {
130130
"pullRequests": {
131131
"nodes": [
132-
{"number": 2898}
132+
{"number": 2898,
133+
"headRepository": {
134+
"owner": {
135+
"login": "OWNER"
136+
},
137+
"name": "REPO"}}
133138
]}}}}`))
134139
reg.Register(
135140
httpmock.REST("GET", "runs/3/jobs"),

0 commit comments

Comments
 (0)
X Tutup