From e63c9e98924e4d666785aba109f5951bee006545 Mon Sep 17 00:00:00 2001 From: Gabriela Gutierrez Date: Tue, 18 Jul 2023 17:32:02 +0000 Subject: [PATCH] :bug: Fix Branch-Protection scoring (#3251) * fix: Verify if branch is required to be up to date before merge Signed-off-by: Gabriela Gutierrez * docs: Comment tracking GraphQL bug Signed-off-by: Gabriela Gutierrez * fix: Add validation if pointers are not null before accessing the values Signed-off-by: Gabriela Gutierrez * fix: Delete debug log file Signed-off-by: Gabriela Gutierrez --------- Signed-off-by: Gabriela Gutierrez Signed-off-by: Allen Shearin --- clients/githubrepo/branches.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/clients/githubrepo/branches.go b/clients/githubrepo/branches.go index 027ca56be19..00669be373f 100644 --- a/clients/githubrepo/branches.go +++ b/clients/githubrepo/branches.go @@ -190,7 +190,16 @@ func copyAdminSettings(src *branchProtectionRule, dst *clients.BranchProtectionR copyBoolPtr(src.DismissesStaleReviews, &dst.RequiredPullRequestReviews.DismissStaleReviews) if src.RequiresStatusChecks != nil { copyBoolPtr(src.RequiresStatusChecks, &dst.CheckRules.RequiresStatusChecks) - copyBoolPtr(src.RequiresStrictStatusChecks, &dst.CheckRules.UpToDateBeforeMerge) + // TODO(#3255): Update when GitHub GraphQL bug is fixed + // Workaround for GitHub GraphQL bug https://github.com/orgs/community/discussions/59471 + // The setting RequiresStrictStatusChecks should tell if the branch is required + // to be up to date before merge, but it only returns the correct value if + // RequiresStatusChecks is true. If RequiresStatusChecks is false, RequiresStrictStatusChecks + // is wrongly retrieved as true. + if src.RequiresStrictStatusChecks != nil { + upToDateBeforeMerge := *src.RequiresStatusChecks && *src.RequiresStrictStatusChecks + copyBoolPtr(&upToDateBeforeMerge, &dst.CheckRules.UpToDateBeforeMerge) + } } }