Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: base ref #1618

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions pkg/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1539,7 +1539,7 @@ func (c *DefaultController) dividePool(pool map[string]PullRequest, pjs []v1alph
repo := string(pr.Repository.Name)
branch := string(pr.BaseRef.Name)
cloneURL := string(pr.Repository.URL)
baseSHA := string(pr.BaseRefOID)
baseSHA := string(pr.BaseRef.Target.OID)
if cloneURL == "" {
return nil, errors.New("no clone URL specified for repository")
}
Expand Down Expand Up @@ -1587,6 +1587,9 @@ type GraphQLAuthor struct {
type GraphQLBaseRef struct {
Name githubql.String
Prefix githubql.String
Target struct {
OID githubql.String `graphql:"oid"`
}
}

// PullRequest holds graphql data about a PR, including its commits and their contexts.
Expand All @@ -1596,7 +1599,6 @@ type PullRequest struct {
BaseRef GraphQLBaseRef
HeadRefName githubql.String `graphql:"headRefName"`
HeadRefOID githubql.String `graphql:"headRefOid"`
BaseRefOID githubql.String
Mergeable githubql.MergeableState
Repository Repository
Commits struct {
Expand Down Expand Up @@ -1888,6 +1890,9 @@ func scmPRToGraphQLPR(scmPR *scm.PullRequest, scmRepo *scm.Repository) *PullRequ
baseRef := GraphQLBaseRef{
Name: githubql.String(scmPR.Target),
Prefix: githubql.String(strings.TrimSuffix(scmPR.Base.Ref, scmPR.Target)),
Target: struct {
OID githubql.String `graphql:"oid"`
}{OID: githubql.String(scmPR.Base.Sha)},
}

if baseRef.Prefix == "" {
Expand Down Expand Up @@ -1917,7 +1922,6 @@ func scmPRToGraphQLPR(scmPR *scm.PullRequest, scmRepo *scm.Repository) *PullRequ
BaseRef: baseRef,
HeadRefName: githubql.String(scmPR.Source),
HeadRefOID: githubql.String(scmPR.Head.Sha),
BaseRefOID: githubql.String(scmPR.Base.Sha),
Mergeable: mergeable,
Repository: scmRepoToGraphQLRepo(scmRepo),
Labels: labels,
Expand Down
2 changes: 1 addition & 1 deletion pkg/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ func TestDividePool(t *testing.T) {
npr := PullRequest{Number: githubql.Int(p.number)}
npr.BaseRef.Name = githubql.String(p.branch)
npr.BaseRef.Prefix = "refs/heads/"
npr.BaseRefOID = githubql.String(testPJs[idx].baseSHA)
npr.BaseRef.Target.OID = githubql.String(testPJs[idx].baseSHA)
npr.Repository.Name = githubql.String(p.repo)
npr.Repository.Owner.Login = githubql.String(p.org)
npr.Repository.URL = githubql.String(fmt.Sprintf("https://github.com/%s/%s.git", p.org, p.repo))
Expand Down
9 changes: 3 additions & 6 deletions pkg/keeper/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,7 @@ func TestExpectedStatus(t *testing.T) {
secondQuery,
}.QueryMap()
var pr PullRequest
pr.BaseRef = struct {
Name githubql.String
Prefix githubql.String
}{
pr.BaseRef = GraphQLBaseRef{
Name: githubql.String(tc.baseref),
}
for _, label := range tc.labels {
Expand All @@ -272,15 +269,15 @@ func TestExpectedStatus(t *testing.T) {
)
}
if len(tc.contexts) > 0 {
pr.HeadRefOID = githubql.String("head")
pr.HeadRefOID = "head"
pr.Commits.Nodes = append(
pr.Commits.Nodes,
struct{ Commit Commit }{
Commit: Commit{
Status: struct{ Contexts []Context }{
Contexts: tc.contexts,
},
OID: githubql.String("head"),
OID: "head",
},
},
)
Expand Down
Loading