Skip to content

Commit

Permalink
Add URLs to tide PullRequests
Browse files Browse the repository at this point in the history
  • Loading branch information
YuviGold committed Oct 1, 2021
1 parent 53d7636 commit e62a284
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
12 changes: 11 additions & 1 deletion prow/tide/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"errors"
"fmt"
"net/url"
"sort"
"strings"
"testing"
Expand Down Expand Up @@ -790,7 +791,8 @@ func TestExpectedStatus(t *testing.T) {
)
pr.Author = struct {
Login githubql.String
}{githubql.String(tc.author)}
Url githubql.URI
}{githubql.String(tc.author), githubql.URI{&url.URL{Path: "html"}}}
if tc.milestone != "" {
pr.Milestone = &struct {
Title githubql.String
Expand Down Expand Up @@ -1013,10 +1015,12 @@ func TestTargetUrl(t *testing.T) {
pr: &PullRequest{
Author: struct {
Login githubql.String
Url githubql.URI
}{Login: githubql.String("author")},
Repository: struct {
Name githubql.String
NameWithOwner githubql.String
Url githubql.URI
Owner struct {
Login githubql.String
}
Expand All @@ -1031,10 +1035,12 @@ func TestTargetUrl(t *testing.T) {
pr: &PullRequest{
Author: struct {
Login githubql.String
Url githubql.URI
}{Login: githubql.String("author")},
Repository: struct {
Name githubql.String
NameWithOwner githubql.String
Url githubql.URI
Owner struct {
Login githubql.String
}
Expand All @@ -1053,10 +1059,12 @@ func TestTargetUrl(t *testing.T) {
pr: &PullRequest{
Author: struct {
Login githubql.String
Url githubql.URI
}{Login: githubql.String("author")},
Repository: struct {
Name githubql.String
NameWithOwner githubql.String
Url githubql.URI
Owner struct {
Login githubql.String
}
Expand All @@ -1075,10 +1083,12 @@ func TestTargetUrl(t *testing.T) {
pr: &PullRequest{
Author: struct {
Login githubql.String
Url githubql.URI
}{Login: githubql.String("author")},
Repository: struct {
Name githubql.String
NameWithOwner githubql.String
Url githubql.URI
Owner struct {
Login githubql.String
}
Expand Down
32 changes: 17 additions & 15 deletions prow/tide/tide.go
Original file line number Diff line number Diff line change
Expand Up @@ -1360,15 +1360,7 @@ func (c *Controller) trigger(sp subpool, presubmits []config.Presubmit, prs []Pu
BaseSHA: sp.sha,
}
for _, pr := range prs {
refs.Pulls = append(
refs.Pulls,
prowapi.Pull{
Number: int(pr.Number),
Title: string(pr.Title),
Author: string(pr.Author.Login),
SHA: string(pr.HeadRefOID),
},
)
refs.Pulls = append(refs.Pulls, pr.toPull())
}

// If PRs require the same job, we only want to trigger it once.
Expand Down Expand Up @@ -1692,12 +1684,7 @@ func (c *Controller) syncSubpool(sp subpool, blocks []blockers.Blocker) (Pool, e
func prMeta(prs ...PullRequest) []prowapi.Pull {
var res []prowapi.Pull
for _, pr := range prs {
res = append(res, prowapi.Pull{
Number: int(pr.Number),
Author: string(pr.Author.Login),
Title: string(pr.Title),
SHA: string(pr.HeadRefOID),
})
res = append(res, pr.toPull())
}
return res
}
Expand Down Expand Up @@ -1811,6 +1798,7 @@ type PullRequest struct {
Number githubql.Int
Author struct {
Login githubql.String
Url githubql.URI
}
BaseRef struct {
Name githubql.String
Expand All @@ -1822,6 +1810,7 @@ type PullRequest struct {
Repository struct {
Name githubql.String
NameWithOwner githubql.String
Url githubql.URI
Owner struct {
Login githubql.String
}
Expand All @@ -1848,6 +1837,7 @@ type PullRequest struct {
Body githubql.String
Title githubql.String
UpdatedAt githubql.DateTime
Url githubql.URI
}

type CommitNode struct {
Expand Down Expand Up @@ -1918,6 +1908,18 @@ func (pr *PullRequest) logFields() logrus.Fields {
}
}

func (pr *PullRequest) toPull() prowapi.Pull {
return prowapi.Pull{
Number: int(pr.Number),
Title: string(pr.Title),
Author: string(pr.Author.Login),
SHA: string(pr.HeadRefOID),
Link: pr.Url.String(),
AuthorLink: pr.Author.Url.String(),
CommitLink: fmt.Sprintf("%s/pull/%d/commits/%s", pr.Repository.Url.String(), pr.Number, pr.HeadRefOID),
}
}

// headContexts gets the status contexts for the commit with OID == pr.HeadRefOID
//
// First, we try to get this value from the commits we got with the PR query.
Expand Down
1 change: 1 addition & 0 deletions prow/tide/tide_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,7 @@ func TestMergeMethodCheckerAndPRMergeMethod(t *testing.T) {
Repository: struct {
Name githubql.String
NameWithOwner githubql.String
Url githubql.URI
Owner struct {
Login githubql.String
}
Expand Down

0 comments on commit e62a284

Please sign in to comment.