1

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?

Dim
  • 13
  • 4

1 Answers1

0

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)
sytech
  • 29,298
  • 3
  • 45
  • 86
  • This is exactly what i did. Sorry i didnt add this string in question `get_mr = project.mergerequests.get(mr_iid)` And i got wrong old data about MR – Dim Jul 06 '22 at 11:15
  • @Dim you have to do the `.get` inside the loop. – sytech Jul 06 '22 at 11:16
  • Something is wrong or i dont understand thing Tried your advice and had no effect. I corrected my topic info. Is that way you meant i should do for update MR info? – Dim Jul 06 '22 at 11:50
  • @Dim what makes you believe it is not working? What is the behavior you're expecting and what is the behavior you are observing? – sytech Jul 06 '22 at 18:33
  • Your advice worked, thank you I was confused by output of this string `mr_pipeline = getattr(get_mr, 'pipeline', 'No pipeline')` – Dim Jul 15 '22 at 14:01