I can add a label like this
issue.fields.labels.append("MYNEWLABEL")
but I have searched the docs and duckduckgo'd until my hair has gone greyer but I have not figured out how to remove a label. I tried the method I used to remove a component but it didn't work
# doesn't work:
issue.update(update={"labels": [{"remove": {"name": "MYOLDLABEL"}}],},)
this works for components, so I thought something similar would work for labels, but not for me
# works:
issue.update(update={"components": [{"remove": {"name": "MYOLDCOMPONENT"}}],},)
would be ever so happy to hear how to do this, I don't want to have to manually change hundreds of issues (the bulk editor doesnt' work for me in the browser).
FYI, here's the core essence of my script:
#!/usr/bin/env python3
import sys
# https://pypi.org/project/jira/
from jira import JIRA
JIRA_API_TOKEN_ENV_NAME = 'JIRA_API_TOKEN'
JIRA_FQDN = 'https://jira.example.com'
JIRA_JQL = 'labels in (OLDLABEL and labels not in (NEWLABEL)'
def main():
jira_api_token = os.environ[JIRA_API_TOKEN_ENV_NAME]
issues = jira.search_issues(JIRA_JQL)
issue_num = 1
for issue in issues:
print(f'=== {issue_num} - {issue.key} ===')
print(f'project { issue.fields.project.key}')
print(f'state.name { issue.fields.status.name}')
was_closed = False
if issue.fields.status.name == 'Closed':
was_closed = True
print(f'labels before { issue.fields.labels }')
if was_closed:
print('Was closed, reopening')
jira.transition_issue(issue, '3') # transition id 3 - name Reopen Issue
# works:
issue.fields.labels.append('NEWLABEL')
# fails:
issue.update(update={"labels": [{"remove": {"name": "OLDLABEL"}}],},)
# works:
issue.update(fields={"labels": issue.fields.labels})
if was_closed:
print('Was closed, reclosing')
jira.transition_issue(issue, '2') # transition id 2 - name Close Issue
issue_num = issue_num + 1
print('')