Skip to content

Commit

Permalink
fix required_approving_review_count bug
Browse files Browse the repository at this point in the history
  • Loading branch information
GrantBirki committed Dec 12, 2024
1 parent 15aaec6 commit a6e8a55
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 18 deletions.
41 changes: 40 additions & 1 deletion __tests__/functions/branch-protection-checks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var octokit
var data
var rulesets

// const debugMock = jest.spyOn(core, 'debug').mockImplementation(() => {})
const debugMock = jest.spyOn(core, 'debug').mockImplementation(() => {})
const warningMock = jest.spyOn(core, 'warning').mockImplementation(() => {})
const infoMock = jest.spyOn(core, 'info').mockImplementation(() => {})

Expand Down Expand Up @@ -219,3 +219,42 @@ test('finds that all suggested branch rulesets are defined but required reviews
`🔐 branch ${COLORS.highlight}rulesets${COLORS.reset} for branch ${COLORS.highlight}${data.branch}${COLORS.reset} contains the required_approving_review_count parameter but it is set to 0`
)
})

test('should still pass even with many required reviewers', async () => {
rulesets = SUGGESTED_RULESETS.map(suggested_rule => {
return {
type: suggested_rule.type,
parameters: suggested_rule.parameters
}
})

rulesets = rulesets.map(rule => {
if (rule.type === 'pull_request') {
return {
type: 'pull_request',
parameters: {
...rule.parameters,
required_approving_review_count: 4
}
}
}
return rule
})

octokit = {
rest: {
repos: {
getBranchRules: jest.fn().mockReturnValueOnce({data: rulesets})
}
}
}

expect(await branchRulesetChecks(context, octokit, data)).toStrictEqual({
success: true,
failed_checks: []
})
expect(warningMock).not.toHaveBeenCalled()
expect(debugMock).toHaveBeenCalledWith(
`required_approving_review_count is 4 - OK`
)
})
21 changes: 13 additions & 8 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

21 changes: 13 additions & 8 deletions src/functions/branch-ruleset-checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,19 @@ export async function branchRulesetChecks(context, octokit, data) {
} else if (rule_parameters) {
Object.keys(rule_parameters).forEach(key => {
if (branch_rule.parameters[key] !== rule_parameters[key]) {
if (
key === 'required_approving_review_count' &&
branch_rule.parameters['required_approving_review_count'] === 0
) {
core.warning(
`🔐 branch ${COLORS.highlight}rulesets${COLORS.reset} for branch ${COLORS.highlight}${branch}${COLORS.reset} contains the required_approving_review_count parameter but it is set to 0`
)
failed_checks.push(`mismatch_${rule_type}_${key}`)
if (key === 'required_approving_review_count') {
if (
branch_rule.parameters['required_approving_review_count'] === 0
) {
core.warning(
`🔐 branch ${COLORS.highlight}rulesets${COLORS.reset} for branch ${COLORS.highlight}${branch}${COLORS.reset} contains the required_approving_review_count parameter but it is set to 0`
)
failed_checks.push(`mismatch_${rule_type}_${key}`)
} else {
core.debug(
`required_approving_review_count is ${branch_rule.parameters['required_approving_review_count']} - OK`
)
}
} else {
core.warning(
`🔐 branch ${COLORS.highlight}rulesets${COLORS.reset} for branch ${COLORS.highlight}${branch}${COLORS.reset} contains a rule of type ${COLORS.highlight}${rule_type}${COLORS.reset} with a parameter ${COLORS.highlight}${key}${COLORS.reset} which does not match the suggested parameter`
Expand Down

0 comments on commit a6e8a55

Please sign in to comment.