Skip to content

Commit

Permalink
https://github.com/andgineer/jiratools/issues/1
Browse files Browse the repository at this point in the history
transition command
  • Loading branch information
andgineer committed Oct 14, 2023
1 parent 785e18d commit 1b6b83d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }}
Expand Down
2 changes: 0 additions & 2 deletions src/jiratools/clone_tickets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions src/jiratools/jiratools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
27 changes: 20 additions & 7 deletions src/jiratools/transition_tickets.py
Original file line number Diff line number Diff line change
@@ -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-')):
Expand All @@ -22,5 +36,4 @@ def transition_jira_tickets(user, password, project):
# linked.update(fields={'labels': labels + ['move2cott']})
# print(linked.key)


print('Transition complete.')

0 comments on commit 1b6b83d

Please sign in to comment.