Gitlab-Python API。创建先生后,无法获得实际的MR状态信息

发布于 2025-02-13 08:00:54 字数 1090 浏览 1 评论 0原文

我用Python-Gitlab创建MR。创建后,我需要检查MR_CONFLICT和管道状态。

project = gl.projects.get(PROJECT_ID, lazy=False)
create_mr = project.mergerequests.create({'id': PROJECT_ID,
                                      'title': 'Testing multiMR',
                                      'source_branch': SOURCE_BRANCH,
                                      'target_branch': TARGET_BRANCH,
                                      'labels': [LABEL]})
mr_iid = getattr(create_mr, 'iid')

time.sleep(3)

get_mr = project.mergerequests.get(mr_iid)
mr_conflict = getattr(get_mr, 'has_conflicts')
mr_pipeline = getattr(get_mr, 'pipeline', 'No pipeline')

但是我没有获得此请求的实际信息!我的答案是像现在创建了MR这样的数据,并且没有有关Coflicts或管道的信息。

同时,如果我仅从不同的控制台启动另一个脚本以检查MR状态,则我获得了正确的实际信息。

另一个时刻。如果在具有MR Creation的脚本中,我运行周期

n = 4
while n > 0: 
  
  time.sleep(1)
  n -= 1
  project.refresh()
  get_mr = project.mergerequests.get(mr_iid)
  mr_conflict = get_mr.has_conflicts
  mr_pipeline = getattr(get_mr, 'pipeline', 'No pipeline')

仍然没有更新的信息。

如何获取有关MR Inside脚本的实际信息?

Im creating MR with python-gitlab. After creation i need to check for mr_conflicts and pipeline state.

project = gl.projects.get(PROJECT_ID, lazy=False)
create_mr = project.mergerequests.create({'id': PROJECT_ID,
                                      'title': 'Testing multiMR',
                                      'source_branch': SOURCE_BRANCH,
                                      'target_branch': TARGET_BRANCH,
                                      'labels': [LABEL]})
mr_iid = getattr(create_mr, 'iid')

time.sleep(3)

get_mr = project.mergerequests.get(mr_iid)
mr_conflict = getattr(get_mr, 'has_conflicts')
mr_pipeline = getattr(get_mr, 'pipeline', 'No pipeline')

But I dont get actual info with this requests! I have answer with data like MR was created just now and has no info about coflicts or pipelines.

Same time if i start another script from different console only for checking MR status i got right actual information.

Another moment. If in the script with MR creation i run cycle

n = 4
while n > 0: 
  
  time.sleep(1)
  n -= 1
  project.refresh()
  get_mr = project.mergerequests.get(mr_iid)
  mr_conflict = get_mr.has_conflicts
  mr_pipeline = getattr(get_mr, 'pipeline', 'No pipeline')

still no updated info.

How can i get actual info about MR inside script?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉梦枕江山 2025-02-20 08:00:55

MR对象的属性不会刷新/自行更新。您必须再次使用API​​请求信息(创建一个新对象)

my_mr = project.mergerequests.create(...)
mr_iid = my_mr.iid
# later
...
# get current data from the server
mr_info = project.mergerequests.get(mr_iid) 
print(mr_info.attributes)

The attributes of an MR object will not refresh/update themselves. You must request the information with the API again (create a new object)

my_mr = project.mergerequests.create(...)
mr_iid = my_mr.iid
# later
...
# get current data from the server
mr_info = project.mergerequests.get(mr_iid) 
print(mr_info.attributes)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文