Title: how can I specify the branches for a merge request approval rule? · python-gitlab/python-gitlab · Discussion #3225 · GitHub
Open Graph Title: how can I specify the branches for a merge request approval rule? · python-gitlab/python-gitlab · Discussion #3225
X Title: how can I specify the branches for a merge request approval rule? · python-gitlab/python-gitlab · Discussion #3225
Description: how can I specify the branches for a merge request approval rule?
Open Graph Description: I would like to automatically create a merge request approval rule. Unfortunately, I don't find an option to specify which branch this applies to. Using this code always leads to a rule applying to...
X Description: I would like to automatically create a merge request approval rule. Unfortunately, I don't find an option to specify which branch this applies to. Using this code always leads to a rule applyin...
Opengraph URL: https://github.com/python-gitlab/python-gitlab/discussions/3225
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"QAPage","mainEntity":{"@type":"Question","name":"how can I specify the branches for a merge request approval rule?","text":"I would like to automatically create a merge request approval rule.
\nUnfortunately, I don't find an option to specify which branch this applies to.
\nUsing this code always leads to a rule applying to all branches
\nproject.approvalrules.create(\n {\n \"name\": rule_name,\n \"approvals_required\": 1,\n \"rule_type\": \"regular\",\n \"branches\": [\"main\"], # This does not have an effect.\n \"group_ids\": approver_group_ids,\n })\n
\nAny idea how to fix this?
","upvoteCount":1,"answerCount":2,"acceptedAnswer":{"@type":"Answer","text":"I found a solution
\nproject = gl.projects.get(\"my-project\")\nmain_branch = project.protectedbranches.get(\"main\")\nproject.approvalrules.create(\n {\n \"name\": rule_name,\n \"approvals_required\": 1,\n \"rule_type\": \"regular\",\n \"protected_branch_ids\": [main_branch_id.id],\n \"group_ids\": approver_group_ids,\n }\n )\n
","upvoteCount":1,"url":"https://github.com/python-gitlab/python-gitlab/discussions/3225#discussioncomment-13597753"}}}
| route-pattern | /_view_fragments/Voltron::DiscussionsFragmentsController/show/:user_id/:repository/:discussion_number/discussion_layout(.:format) |
| route-controller | voltron_discussions_fragments |
| route-action | discussion_layout |
| fetch-nonce | v2:f842c554-e7f3-b2b7-2ca1-d6308e78fa74 |
| current-catalog-service-hash | 9f0abe34da433c9b6db74bffa2466494a717b579a96b30a5d252e5090baea7be |
| request-id | E3A2:B2D82:1B7905A:25305CB:6972BE27 |
| html-safe-nonce | e96969e19575ea68b8143371920d327f7f12cc4d605fe513ef8b5d6ed5e38304 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFM0EyOkIyRDgyOjFCNzkwNUE6MjUzMDVDQjo2OTcyQkUyNyIsInZpc2l0b3JfaWQiOiIzODU0NDU2ODg0NzQ3NzQ2ODU1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e3233cc7bd98e04f918e2e933f1851d386e1bdb14314316801cacd3eba9e9aa7 |
| hovercard-subject-tag | discussion:8502662 |
| github-keyboard-shortcuts | repository,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/Voltron::DiscussionsFragmentsController/show/python-gitlab/python-gitlab/3225/discussion_layout |
| twitter:image | https://opengraph.githubassets.com/83f8e2862be94ffac149451e9c24027df09a5b7e68e26a62828b0f092339e33f/python-gitlab/python-gitlab/discussions/3225 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/83f8e2862be94ffac149451e9c24027df09a5b7e68e26a62828b0f092339e33f/python-gitlab/python-gitlab/discussions/3225 |
| og:image:alt | I would like to automatically create a merge request approval rule. Unfortunately, I don't find an option to specify which branch this applies to. Using this code always leads to a rule applying to... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | aa656e37a6f46b81c2416d9c983f7c54e264ee31be17c0e6c9414b9f9f9c6eb4 |
| turbo-cache-control | no-preview |
| go-import | github.com/python-gitlab/python-gitlab git https://github.com/python-gitlab/python-gitlab.git |
| octolytics-dimension-user_id | 28886265 |
| octolytics-dimension-user_login | python-gitlab |
| octolytics-dimension-repository_id | 8077625 |
| octolytics-dimension-repository_nwo | python-gitlab/python-gitlab |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 8077625 |
| octolytics-dimension-repository_network_root_nwo | python-gitlab/python-gitlab |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cd2db6550c3226c3d384891fd6e7c212a34667be |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width