From f2490879d30800cbe29995cd92fec53570ea6253 Mon Sep 17 00:00:00 2001 From: psjakubowska Date: Fri, 12 Sep 2025 12:15:21 +0200 Subject: [PATCH] Check both name and id to display rule details This is Duo assisted PoC. Check thoroughly before commiting as production code. --- .../branch_rules/components/view/index.vue | 15 ++- .../settings/repository/branch_rules/app.vue | 1 + .../branch_rules/components/branch_rule.vue | 8 +- .../components/view/index_spec.js | 98 +++++++++++++++++-- .../components/branch_rule_spec.js | 3 +- .../repository/branch_rules/mock_data.js | 12 ++- 6 files changed, 120 insertions(+), 17 deletions(-) diff --git a/app/assets/javascripts/projects/settings/branch_rules/components/view/index.vue b/app/assets/javascripts/projects/settings/branch_rules/components/view/index.vue index cc138ddcaf9523..2ef281c818f45e 100644 --- a/app/assets/javascripts/projects/settings/branch_rules/components/view/index.vue +++ b/app/assets/javascripts/projects/settings/branch_rules/components/view/index.vue @@ -111,7 +111,14 @@ export default { }; }, update({ project: { branchRules, group } }) { - const branchRule = branchRules.nodes.find((rule) => rule.name === this.branch); + const branchRule = branchRules.nodes.find((rule) => { + if (this.ruleId) { + // If we have a rule ID, match by both name and ID for precision + return rule.name === this.branch && getIdFromGraphQLId(rule.id) === this.ruleId; + } + // Fallback to name-only matching for backward compatibility + return rule.name === this.branch; + }); this.branchRule = branchRule; this.branchProtection = branchRule?.branchProtection; this.statusChecks = branchRule?.externalStatusChecks?.nodes || []; @@ -149,8 +156,12 @@ export default { }, }, data() { + const branchParam = getParameterByName(BRANCH_PARAM_NAME); + const ruleId = getParameterByName('id'); + return { - branch: getParameterByName(BRANCH_PARAM_NAME), + branch: branchParam, + ruleId, branchProtection: {}, statusChecks: [], branchRule: {}, diff --git a/app/assets/javascripts/projects/settings/repository/branch_rules/app.vue b/app/assets/javascripts/projects/settings/repository/branch_rules/app.vue index 5aeabbace7e22b..9c54f4d56bfddb 100644 --- a/app/assets/javascripts/projects/settings/repository/branch_rules/app.vue +++ b/app/assets/javascripts/projects/settings/repository/branch_rules/app.vue @@ -188,6 +188,7 @@ export default {