checkPush method
Check whether a push to a specific remote/branch is permitted.
Implementation
PermissionDecision checkPush(
String remote,
String branch, {
bool force = false,
}) {
final isProtected = protectedBranches.contains(branch);
if (force && isProtected) {
return PermissionDecision(
level: PermissionLevel.deny,
reason:
'Force push to protected branch "$branch" on '
'remote "$remote" is blocked.',
);
}
final RiskLevel risk;
if (force) {
risk = RiskLevel.critical;
} else if (isProtected) {
risk = RiskLevel.high;
} else {
risk = RiskLevel.medium;
}
final request = PermissionRequest(
scope: PermissionScope.git,
action: 'push',
resource: '$remote/$branch',
detail: force
? 'Force push to $remote/$branch'
: 'Push to $remote/$branch',
riskLevel: risk,
metadata: {
'remote': remote,
'branch': branch,
'force': force,
'isProtected': isProtected,
},
);
return _ruleSet.evaluateWithCache(request, _cache);
}