Merge "Frontend: support configuring multiple override approvals"
diff --git a/ui/code-owners-service.js b/ui/code-owners-service.js
index 0e07411..8bb14d1 100644
--- a/ui/code-owners-service.js
+++ b/ui/code-owners-service.js
@@ -117,12 +117,20 @@
* @param {string} project
* @param {string} branch
*/
- getBranchConfig(project, branch) {
- return this.restApi.get(
+ async getBranchConfig(project, branch) {
+ const config = await this.restApi.get(
`/projects/${encodeURIComponent(project)}/` +
`branches/${encodeURIComponent(branch)}/` +
`code_owners.branch_config`
);
+ if (config.override_approval && !(config.override_approval instanceof Array)) {
+ // In the upcoming backend changes, the override_approval will be changed
+ // to array with (possible) multiple items.
+ // While this transition is in progress, the frontend supports both API -
+ // the old one and the new one.
+ return {...config, override_approval: [config.override_approval]};
+ }
+ return config;
}
}
diff --git a/ui/owner-requirement.js b/ui/owner-requirement.js
index d08bacc..1ad5b4b 100644
--- a/ui/owner-requirement.js
+++ b/ui/owner-requirement.js
@@ -112,7 +112,7 @@
},
_isOverriden: {
type: Boolean,
- computed: '_computeIsOverriden(model.branchConfig)',
+ computed: '_computeIsOverriden(change, model.branchConfig)',
},
_overrideInfoUrl: {
type: String,
@@ -165,19 +165,23 @@
? branchConfig.general.override_info_url : '';
}
- _computeIsOverriden(branchConfig) {
- if (!branchConfig || !branchConfig['override_approval']) {
- // no override label configured
+ _computeIsOverriden(change, branchConfig) {
+ if (!change || !branchConfig || !branchConfig['override_approval']) {
+ // no override labels configured
return false;
}
- const overridenLabel = branchConfig['override_approval'].label;
- const overridenValue = branchConfig['override_approval'].value;
- if (this.change.labels[overridenLabel]) {
- const votes = this.change.labels[overridenLabel].all || [];
- if (votes.find(v => `${v.value}` === `${overridenValue}`)) {
- return true;
+ for(const requiredApprovalInfo of branchConfig['override_approval']) {
+ const overridenLabel = requiredApprovalInfo.label;
+ const overridenValue = Number(requiredApprovalInfo.value);
+ if (isNaN(overridenValue)) continue;
+
+ if (this.change.labels[overridenLabel]) {
+ const votes = change.labels[overridenLabel].all || [];
+ if (votes.find(v => Number(v.value) >= overridenValue)) {
+ return true;
+ }
}
}