How to reopen a closed Gitlab Projectissue with the python gitlab module

Viewed 69

Trying to automate reopening a bunch of issues on a kanban board in Gitlab does not seem to be working as expected. I can edit pretty much everything else: labels, title, description, due date and so on, but changing the state from 'closed' to 'opened' is not doing anything. Funny enough the save() method, takes some time to complete and is not throwing any error (but it does when I try to update an issue without having changed anything)

import gitlab

gl = gitlab.Gitlab(URL, private_token=TOKEN, api_version = 4)
gl.auth()
Project = gl.projects.get(project_id, lazy=True)
editable_issue = Project.issues.get(issue_id)

I use this to instantiate the gitlab object

This works:

editable_issue.labels.append('some label')
editable_issue.save()

editable_issue.title = title + '\n' + 'edited.'
editable_issue.save()

But this doesn't:

editable_issue.state = 'opened'
editable_issue.save()

I have also tried changing several fields, like so:

editable_issue.state = 'opened'
editable_issue.closed_at = None
editable_issue.save()

But, albeit I receive no error, the task is not being updated.

Is there something I'm overlooking ?

edit Oh yes, I forgot to mention that the documentation seems to be mentioning state_event as a method, while my object does not know of such a method. Is this method only there when a projectissue is being created by the api, perhaps ?

1 Answers

As mentioned in the documentation, you must set the state_event attribute, then save. This attribute won't exist at first -- you must create it.

issue.state_event = 'reopen'
issue.save()

Modifying state or closed_at won't work because the issues edit API doesn't accept state or closed_at parameters.

(this is also why state_event doesn't exist on the object at first, because the issue detail API doesn't include state_event in its response -- all the attributes are set dynamically by the response JSON)

Related