From 1b6b83d30cfc3412eef4504e9753ad03ff1aba1b Mon Sep 17 00:00:00 2001 From: Andrei Sorokin Date: Sat, 14 Oct 2023 09:50:05 +0200 Subject: [PATCH] https://github.com/andgineer/jiratools/issues/1 transition command --- .github/workflows/ci.yml | 6 +++--- src/jiratools/clone_tickets.py | 2 -- src/jiratools/jiratools.py | 5 +++-- src/jiratools/transition_tickets.py | 27 ++++++++++++++++++++------- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 156c949..8907978 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,11 +26,11 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - python -m pip install --upgrade pip - python -m pip install . + pip install --upgrade pip + pip install . - name: Test with pytest run: | - python -m coverage run -m pytest tests + coverage run -m pytest tests - name: Upload Coverage to Codecov if: ${{ matrix.python-version == 3.11 && matrix.platform == 'ubuntu-latest' }} diff --git a/src/jiratools/clone_tickets.py b/src/jiratools/clone_tickets.py index d372837..58bf2f4 100644 --- a/src/jiratools/clone_tickets.py +++ b/src/jiratools/clone_tickets.py @@ -3,10 +3,8 @@ def clone_jira_tickets(user, password, jql, project, issue_type, assignee, endpoint): - # Initialize JIRA with credentials or defaults jira = initialize_jira(user, password) - # Retrieve issues based on provided JQL query issues = jira.search_issues(jql) for issue in issues: diff --git a/src/jiratools/jiratools.py b/src/jiratools/jiratools.py index 00e378b..ac00a59 100644 --- a/src/jiratools/jiratools.py +++ b/src/jiratools/jiratools.py @@ -25,9 +25,10 @@ def clone(user, password, jql, project, issue_type, assignee, endpoint): @click.option('--user', default=None, help='JIRA username (defaults to environment variable)') @click.option('--password', default=None, help='JIRA password (defaults to environment variable)') @click.option('--project', default='COTTMODERN', help='Project name') -def transition(user, password, project): +@click.option('--transition', default='In Review', help='Transition name') +def transition(user, password, project, transition_name): """Transition JIRA tickets based on specific logic.""" - transition_jira_tickets(user, password, project) + transition_jira_tickets(user, password, project, transition_name) if __name__ == "__main__": diff --git a/src/jiratools/transition_tickets.py b/src/jiratools/transition_tickets.py index df6d86a..7d7f537 100644 --- a/src/jiratools/transition_tickets.py +++ b/src/jiratools/transition_tickets.py @@ -1,17 +1,31 @@ from jiratools.config import initialize_jira -def transition_jira_tickets(user, password, project): - jira = initialize_jira() +def transition_jira_tickets(user, password, project, transition_name): + jira = initialize_jira(user, password) - # Fetch issues based on some criteria (example) issues = jira.search_issues(f'project = {project} AND status = "In Progress"') for issue in issues: - print(f'Transitioning issue {issue.key}') + print(f'Transitioning issue {issue.key} to "{transition_name}"') + + # Fetch available transitions for the issue + transitions = jira.transitions(issue) + transition_id = None + + # Find the transition ID for the specified transition name + for transition in transitions: + if transition['name'] == transition_name: + transition_id = transition['id'] + break + + if transition_id is not None: + # Perform the transition + jira.transition_issue(issue, transition_id) + print(f'Successfully transitioned issue {issue.key} to "{transition_name}"') + else: + print(f'Error: Transition "{transition_name}" not found for issue {issue.key}') - # jira.transition_issue(issue, '1') - # print(r) # for link in issue.fields.issuelinks: # linked = link.outwardIssue if hasattr(link, 'outwardIssue') else link.inwardIssue # if (linked.fields.status.name == 'Open' and linked.key.startswith('COTTMODERN-')): @@ -22,5 +36,4 @@ def transition_jira_tickets(user, password, project): # linked.update(fields={'labels': labels + ['move2cott']}) # print(linked.key) - print('Transition complete.')