Skip to content

Commit

Permalink
Merge pull request goliac-project#7 from goliac-project/branch_protec…
Browse files Browse the repository at this point in the history
…tion_fixes

branch protections fixes
  • Loading branch information
nzin authored Feb 21, 2025
2 parents ba5095c + 79a8e98 commit 66365cd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## Goliac v0.15.1

- branch protections bugfixes

## Goliac v0.15.0

- introducing branch protections

## Goliac v0.14.1

- different security updates (golang/npm)
Expand Down
23 changes: 14 additions & 9 deletions internal/engine/goliac_reconciliator.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ func (r *GoliacReconciliatorImpl) reconciliateRepositories(ctx context.Context,
branchprotections := make(map[string]*GithubBranchProtection)
for _, bp := range lRepo.Spec.BranchProtections {
branchprotection := GithubBranchProtection{
DatabaseId: 0,
Id: "",
Pattern: bp.Pattern,
RequiresApprovingReviews: bp.RequiresApprovingReviews,
RequiredApprovingReviewCount: bp.RequiredApprovingReviewCount,
Expand Down Expand Up @@ -595,7 +595,7 @@ func (r *GoliacReconciliatorImpl) reconciliateRepositories(ctx context.Context,
}
onBranchProtectionChange := func(rulename string, lBp *GithubBranchProtection, rBp *GithubBranchProtection) {
// UPDATE branchprotection
lBp.DatabaseId = rBp.DatabaseId
lBp.Id = rBp.Id
r.UpdateRepositoryBranchProtection(ctx, dryrun, reponame, lBp)
}
CompareEntities(lRepo.BranchProtections, rRepo.BranchProtections, compareBranchProtections, onBranchProtectionAdded, onBranchProtectionRemoved, onBranchProtectionChange)
Expand Down Expand Up @@ -749,8 +749,10 @@ func compareBranchProtections(bpname string, lbp *GithubBranchProtection, rbp *G
if lbp.RequiresApprovingReviews != rbp.RequiresApprovingReviews {
return false
}
if lbp.RequiredApprovingReviewCount != rbp.RequiredApprovingReviewCount {
return false
if lbp.RequiresApprovingReviews {
if lbp.RequiredApprovingReviewCount != rbp.RequiredApprovingReviewCount {
return false
}
}
if lbp.DismissesStaleReviews != rbp.DismissesStaleReviews {
return false
Expand All @@ -764,11 +766,14 @@ func compareBranchProtections(bpname string, lbp *GithubBranchProtection, rbp *G
if lbp.RequiresStatusChecks != rbp.RequiresStatusChecks {
return false
}
if lbp.RequiresStrictStatusChecks != rbp.RequiresStrictStatusChecks {
return false
}
if res, _, _ := entity.StringArrayEquivalent(lbp.RequiredStatusCheckContexts, rbp.RequiredStatusCheckContexts); !res {
return false
if lbp.RequiresStatusChecks {
if lbp.RequiresStrictStatusChecks != rbp.RequiresStrictStatusChecks {
return false
}
if res, _, _ := entity.StringArrayEquivalent(lbp.RequiredStatusCheckContexts, rbp.RequiredStatusCheckContexts); !res {
fmt.Println("false")
return false
}
}
if lbp.RequiresConversationResolution != rbp.RequiresConversationResolution {
return false
Expand Down
23 changes: 13 additions & 10 deletions internal/engine/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ query listAllReposInOrg($orgLogin: String!, $endCursor: String) {
}
branchProtectionRules(first:50) {
nodes{
databaseId
id
pattern
requiresApprovingReviews
requiredApprovingReviewCount
Expand Down Expand Up @@ -582,7 +582,7 @@ query listAllReposInOrg($orgLogin: String!, $endCursor: String) {
`

type GithubBranchProtection struct {
DatabaseId int
Id string
Pattern string
RequiresApprovingReviews bool
RequiredApprovingReviewCount int
Expand Down Expand Up @@ -1837,7 +1837,7 @@ mutation createBranchProtectionRule(
repositoryId: $repositoryId,
pattern: $pattern,
requiresApprovingReviews: $requiresApprovingReviews,
requiredApprovingReviewCount: $requriedApprovingReviewCount,
requiredApprovingReviewCount: $requiredApprovingReviewCount,
dismissesStaleReviews: $dismissesStaleReviews,
requiresCodeOwnerReviews: $requiresCodeOwnerReviews,
requireLastPushApproval: $requireLastPushApproval,
Expand All @@ -1851,7 +1851,7 @@ mutation createBranchProtectionRule(
allowsDeletions: $allowsDeletions
}) {
branchProtectionRule {
databaseId
id
}
}
}`
Expand All @@ -1860,7 +1860,7 @@ type GraphqlBranchProtectionRuleCreationResponse struct {
Data struct {
CreateBranchProtectionRule struct {
BranchProtectionRule struct {
DatabaseId int
Id string
}
}
}
Expand Down Expand Up @@ -1889,7 +1889,7 @@ func (g *GoliacRemoteImpl) AddRepositoryBranchProtection(ctx context.Context, dr
ctx,
createBranchProtectionRule,
map[string]interface{}{
"repositoryId": repo.Id,
"repositoryId": repo.RefId,
"pattern": branchprotection.Pattern,
"requiresApprovingReviews": branchprotection.RequiresApprovingReviews,
"requiredApprovingReviewCount": branchprotection.RequiredApprovingReviewCount,
Expand All @@ -1916,7 +1916,7 @@ func (g *GoliacRemoteImpl) AddRepositoryBranchProtection(ctx context.Context, dr
logrus.Errorf("failed to add branch protection to repository %s: %v", reponame, err)
}

branchprotection.DatabaseId = res.Data.CreateBranchProtectionRule.BranchProtectionRule.DatabaseId
branchprotection.Id = res.Data.CreateBranchProtectionRule.BranchProtectionRule.Id
}

repo.BranchProtections[branchprotection.Pattern] = branchprotection
Expand All @@ -1943,7 +1943,7 @@ mutation updateBranchProtectionRule(
branchProtectionRuleId: $branchProtectionRuleId,
pattern: $pattern,
requiresApprovingReviews: $requiresApprovingReviews,
requiredApprovingReviewCount: $requriedApprovingReviewCount,
requiredApprovingReviewCount: $requiredApprovingReviewCount,
dismissesStaleReviews: $dismissesStaleReviews,
requiresCodeOwnerReviews: $requiresCodeOwnerReviews,
requireLastPushApproval: $requireLastPushApproval,
Expand All @@ -1956,6 +1956,9 @@ mutation updateBranchProtectionRule(
allowsForcePushes: $allowsForcePushes,
allowsDeletions: $allowsDeletions
}) {
branchProtectionRule {
id
}
}
}`

Expand All @@ -1968,7 +1971,7 @@ func (g *GoliacRemoteImpl) UpdateRepositoryBranchProtection(ctx context.Context,
ctx,
updateBranchProtectionRule,
map[string]interface{}{
"branchProtectionRuleId": branchprotection.DatabaseId,
"branchProtectionRuleId": branchprotection.Id,
"pattern": branchprotection.Pattern,
"requiresApprovingReviews": branchprotection.RequiresApprovingReviews,
"requiredApprovingReviewCount": branchprotection.RequiredApprovingReviewCount,
Expand Down Expand Up @@ -2021,7 +2024,7 @@ func (g *GoliacRemoteImpl) DeleteRepositoryBranchProtection(ctx context.Context,
ctx,
deleteBranchProtectionRule,
map[string]interface{}{
"branchProtectionRuleId": branchprotection.DatabaseId,
"branchProtectionRuleId": branchprotection.Id,
},
)
if err != nil {
Expand Down

0 comments on commit 66365cd

Please sign in to comment.