feat: [CODE-3194] new branch rule to auto add Code Owners as reviewers (#3522)

* feat: [CODE-3194] new rule to auto add Code Owners as reviewers
try-new-ui
Ritik Kapoor 2025-03-10 05:24:38 +00:00 committed by Harness
parent ec12dda66b
commit 0f1e5cda15
7 changed files with 37 additions and 0 deletions

View File

@ -243,6 +243,7 @@ const BranchProtectionForm = (props: {
minReviewers: minReviewerCheck
? (rule.definition as ProtectionBranch)?.pullreq?.approvals?.require_minimum_count
: '',
autoAddCodeOwner: (rule.definition as ProtectionBranch)?.pullreq?.reviewers?.request_code_owners,
requireCodeOwner: (rule.definition as ProtectionBranch)?.pullreq?.approvals?.require_code_owners,
requireNewChanges: (rule.definition as ProtectionBranch)?.pullreq?.approvals?.require_latest_commit,
reqResOfChanges: (rule.definition as ProtectionBranch)?.pullreq?.approvals?.require_no_change_request,
@ -323,6 +324,9 @@ const BranchProtectionForm = (props: {
require_latest_commit: formData.requireNewChanges,
require_no_change_request: formData.reqResOfChanges
},
reviewers: {
request_code_owners: formData.autoAddCodeOwner
},
comments: {
require_resolve_all: formData.requireCommentResolution
},

View File

@ -166,6 +166,16 @@ const ProtectionRulesForm = (props: {
/>
</Container>
)}
<hr className={css.dividerContainer} />
<FormInput.CheckBox
className={css.checkboxLabel}
label={getString('branchProtection.addCodeownersToReviewTitle')}
name={'autoAddCodeOwner'}
/>
<Text padding={{ left: 'xlarge' }} className={css.checkboxText}>
{getString('branchProtection.addCodeownersToReviewText')}
</Text>
<hr className={css.dividerContainer} />
<FormInput.CheckBox
className={css.checkboxLabel}

View File

@ -213,6 +213,12 @@ const BranchProtectionListing = (props: {
requiredRule: {
[RuleFields.LIFECYCLE_UPDATE_FORCE_FORBIDDEN]: true
}
},
autoAddCodeownersToReview: {
title: getString('branchProtection.addCodeownersToReviewTitle'),
requiredRule: {
[RuleFields.AUTO_ADD_CODE_OWNERS]: true
}
}
}

View File

@ -66,6 +66,8 @@ export interface StringsMap {
branchNotFound: string
branchNotFoundError: string
branchNotFoundMessage: string
'branchProtection.addCodeownersToReviewText': string
'branchProtection.addCodeownersToReviewTitle': string
'branchProtection.allRepoOwners': string
'branchProtection.autoDeleteText': string
'branchProtection.autoDeleteTitle': string

View File

@ -1016,6 +1016,8 @@ branchProtection:
requireMinReviewersContent: Require approval on pull requests from a minimum number of reviewers
minNumber: Minimum number
minNumberPlaceholder: Enter the minimum number
addCodeownersToReviewTitle: Add Code Owners as reviewers
addCodeownersToReviewText: Automatically add relevant Code Owners as reviewers
reqReviewFromCodeOwnerTitle: Require review from code owners
reqReviewFromCodeOwnerText: Require approval on pull requests from one reviewer for each Code Owner rule
reqNewChangesTitle: Require approval of new changes

View File

@ -784,9 +784,15 @@ export interface ProtectionDefPullReq {
approvals?: ProtectionDefApprovals
comments?: ProtectionDefComments
merge?: ProtectionDefMerge
reviewers?: ProtectionDefReviewers
status_checks?: ProtectionDefStatusChecks
}
export interface ProtectionDefReviewers {
default_reviewer_ids?: number[]
request_code_owners?: boolean
}
export interface ProtectionDefStatusChecks {
require_identifiers?: string[]
}

View File

@ -392,6 +392,7 @@ export type RulesFormPayload = {
bypassList?: string[]
requireMinReviewers: boolean
minReviewers?: string | number
autoAddCodeOwner?: boolean
requireCodeOwner?: boolean
requireNewChanges?: boolean
reqResOfChanges?: boolean
@ -990,6 +991,7 @@ export enum RuleFields {
APPROVALS_REQUIRE_CODE_OWNERS = 'pullreq.approvals.require_code_owners',
APPROVALS_REQUIRE_NO_CHANGE_REQUEST = 'pullreq.approvals.require_no_change_request',
APPROVALS_REQUIRE_LATEST_COMMIT = 'pullreq.approvals.require_latest_commit',
AUTO_ADD_CODE_OWNERS = 'pullreq.reviewers.request_code_owners',
COMMENTS_REQUIRE_RESOLVE_ALL = 'pullreq.comments.require_resolve_all',
STATUS_CHECKS_ALL_MUST_SUCCEED = 'pullreq.status_checks.all_must_succeed',
STATUS_CHECKS_REQUIRE_IDENTIFIERS = 'pullreq.status_checks.require_identifiers',
@ -1020,6 +1022,7 @@ export type BranchProtectionRulesMapType = Record<string, BranchProtectionRule>
export function createRuleFieldsMap(ruleDefinition: Rule): RuleFieldsMap {
const ruleFieldsMap: RuleFieldsMap = {
[RuleFields.APPROVALS_REQUIRE_MINIMUM_COUNT]: false,
[RuleFields.AUTO_ADD_CODE_OWNERS]: false,
[RuleFields.APPROVALS_REQUIRE_CODE_OWNERS]: false,
[RuleFields.APPROVALS_REQUIRE_NO_CHANGE_REQUEST]: false,
[RuleFields.APPROVALS_REQUIRE_LATEST_COMMIT]: false,
@ -1062,6 +1065,10 @@ export function createRuleFieldsMap(ruleDefinition: Rule): RuleFieldsMap {
Array.isArray(ruleDefinition.pullreq.status_checks.require_identifiers) &&
ruleDefinition.pullreq.status_checks.require_identifiers.length > 0
}
if (ruleDefinition.pullreq.reviewers) {
ruleFieldsMap[RuleFields.AUTO_ADD_CODE_OWNERS] = !!ruleDefinition.pullreq.reviewers.request_code_owners
}
}
if (ruleDefinition.lifecycle) {