-1

i am trying to update jira status with jira-python. My code doesn't throw any error but nothing is gets updated ,the status of the issues remains same(I'm beginner trying to learn python)

project = jira.projects('project=')
for project in projects:
    if issue.fields.status in ('pending'):
       jira.transition_issue(issue, transition='closed')
   print('')
   return "successful"
Cvetan Mihaylov
  • 872
  • 6
  • 15
att
  • 41
  • 2
  • 8
  • Notice that `('pending')` is not a tuple, it's just a string enclosed by a pair of parenthesis. If you want a tuple, you need `('pending',)` (or just `'pending',`). Shouldn't matter, though, as `'pending' in 'pending'` happens to be True... – Imperishable Night Jun 16 '19 at 00:21

3 Answers3

1

You seem to fetch project objects but you want to update issue objects

After a quick reference to the docs here:

https://jira.readthedocs.io/en/master/examples.html#searching https://jira.readthedocs.io/en/master/examples.html#transitions

I think this code should be more suitable to for updating issues to closed:

issues_in_project = jira.search_issues('project=PROJECT_NAME')
for issue in issues_in_project:
    if issue.fields.status in ('pending'):
        jira.transition_issue(issue, '2')
   print('')
return "successful"

Notes:

Replace PROJECT_NAME with name of your project for which you want to update issues, or remove 'project=PROJECT_NAME' at all if you don't want to filter by project.

Also, according to the docs transition id '2' should be for 'Close Issue'.

Cvetan Mihaylov
  • 872
  • 6
  • 15
  • Thank You!! i tried the above solution, i'm getting error : Issue' object is not subscriptable .AttributeError: object has no attribute 'field' ('Issue' object is not subscriptable) – att Jun 17 '19 at 11:25
0

Not sure about jira, but I would update your iterator or your variable

projects = jira.projects('project=')
for project in projects:
    if issue.fields.status in ('pending'):
        jira.transition_issue(issue, transition='closed')
    print('')
    return "successful"
0

fixed issue, below is the code: issues_in_proj = jira.search_issues('project=TEST')

  for issue in issues_in_proj:
        if ("Pending" in issue.fields.status.name):
              jira.transition_issue(issue, 'ID')

Now I'm looking to filter issues with component name/Id swell along with status added condition : ("Pending" in issue.fields.status.name and "component name" in issue.fields.components) . But it's not filtering the components

att
  • 41
  • 2
  • 8