Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

how can I specify the branches for a merge request approval rule?#3225

Answeredbyguerda
guerda asked this question inQ&A
Discussion options

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 all branches

project.approvalrules.create(            {                "name": rule_name,                "approvals_required": 1,                "rule_type": "regular",                "branches": ["main"], # This does not have an effect.                "group_ids": approver_group_ids,            })

Any idea how to fix this?

You must be logged in to vote

I found a solution

project = gl.projects.get("my-project")main_branch = project.protectedbranches.get("main")project.approvalrules.create(                {                    "name": rule_name,                    "approvals_required": 1,                    "rule_type": "regular",                    "protected_branch_ids": [main_branch_id.id],                    "group_ids": approver_group_ids,                }            )

Replies: 2 comments

Comment options

I'm not sure if this is even supported by the GitLab API:https://archives.docs.gitlab.com/17.11/api/merge_request_approvals/#create-project-approval-rule
Related forum posting:https://forum.gitlab.com/t/how-can-i-specify-the-branches-for-a-merge-request-approval-rule/127624

You must be logged in to vote
0 replies
Comment options

I found a solution

project = gl.projects.get("my-project")main_branch = project.protectedbranches.get("main")project.approvalrules.create(                {                    "name": rule_name,                    "approvals_required": 1,                    "rule_type": "regular",                    "protected_branch_ids": [main_branch_id.id],                    "group_ids": approver_group_ids,                }            )
You must be logged in to vote
0 replies
Answer selected byguerda
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
1 participant
@guerda

[8]ページ先頭

©2009-2025 Movatter.jp