如何使用python API调用检查GitLab中的合并请求状态,我想在合并前检查批准状态,根据批准状态必须做一些检查,一旦检查被批准,就会发生合并
import gitlab
import os
import json
Gitlab_repo = "https://gitlab.devtools.xxxx.com/"
gl = gitlab.Gitlab(Gitlab_repo, private_token='xxxx')
project = gl.projects.get(projectid)
merge_request = project.mergerequests.get(merge_request number)
print(merge_request)
输出:
{
"source_branch":"",
"id":,
"references":{
"full":"",
"relative":"",
"short":""
},
"project_id":,
"time_stats":{
"time_estimate":0,
"human_total_time_spent":"None",
"total_time_spent":0,
"human_time_estimate":"None"
},
"description":"",
"merge_when_pipeline_succeeds":,
"work_in_progress":,
"changes_count":"",
"reference":"",
"first_deployed_to_production_at":"None",
"source_project_id":,
"should_remove_source_branch":"None",
"milestone":"None",
"updated_at":"",
"user_notes_count":0,
"latest_build_finished_at":"None",
"head_pipeline":"None",
"subscribed":true,
"web_url":"",
"state":"opened",
"created_at":"",
"approvals_before_merge":"None",
"user":{
"can_merge":true
},
"iid":,
"assignee":{
"avatar_url":"None",
"web_url":"",
"id":,
"username":"",
"state":"",
"name":""
},
"author":{
"avatar_url":"None",
"web_url":"",
"id":,
"username":"",
"state":"active",
"name":""
},
"target_project_id":,
"merge_error":"None",
"task_completion_status":{
"count":0,
"completed_count":0
},
"target_branch":"master",
"squash":false,
"assignees":[
{
"avatar_url":"None",
"web_url":"",
"id":,
"username":"",
"state":"active",
"name":""
}
],
"merged_at":"None",
"has_conflicts":false,
"force_remove_source_branch":true,
"merge_status":"can_be_merged",
"labels":[
],
"pipeline":"None",
"title":"",
"merged_by":"None",
"closed_by":"None",
"sha":"",
"closed_at":"None",
"diff_refs":{
"start_sha":"",
"head_sha":"",
"base_sha":""
},
"squash_commit_sha":"None",
"latest_build_started_at":"None",
"downvotes":0,
"upvotes":0,
"discussion_locked":"None",
"merge_commit_sha":"None",
"blocking_discussions_resolved":true
}