Skip to content

Commit

Permalink
fix: base ref
Browse files Browse the repository at this point in the history
  • Loading branch information
msvticket committed Nov 18, 2024
1 parent b7d99c7 commit e79f0f1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
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

0 comments on commit e79f0f1

Please sign in to comment.