Jira python change status

Jira module¶

Get issues from jql search result with all related fields¶

jql_request = 'project = DEMO AND status NOT IN (Closed, Resolved) ORDER BY issuekey' issues = jira.jql(jql_request) print(issues) 

Reindex Jira¶

# Reindexing Jira jira.reindex() # Reindex status jira.reindex_status() # Reindex type jira.reindex_with_type(indexing_type="BACKGROUND_PREFERRED") """ FOREGROUND - runs a lock/full reindexing BACKGROUND - runs a background reindexing. If JIRA fails to finish the background reindexing, respond with 409 Conflict (error message). BACKGROUND_PREFERRED - If possible do a background reindexing. If it's not possible (due to an inconsistent index), do a foreground reindexing. """ 

Manage users¶

# Get user jira.user(account_id) # Remove user jira.user_remove(username) # Deactivate user. Works from 8.3.0 release jira.user_deactivate(username) # Get web sudo cookies using normal http request jira.user_get_websudo() # Fuzzy search using emailAddress or displayName jira.user_find_by_user_string(query, start=0, limit=50, include_inactive_users=False) # Get groups of a user. This API is only available for Jira Cloud platform. jira.get_user_groups(account_id) 

Manage groups¶

# Create a group jira.create_group(name) # Delete a group # If you delete a group and content is restricted to that group, the content will be hidden from all users # To prevent this, use this parameter to specify a different group to transfer the restrictions # (comments and worklogs only) to jira.remove_group(name, swap_group=None) # Get all users from group jira.get_all_users_from_group(group, include_inactive_users=False, start=0, limit=50) # Add given user to a group jira.add_user_to_group(username=None, group_name=None, account_id=None) # Remove given user from a group jira.remove_user_from_group(username=None, group_name=None, account_id=None) 

Manage projects¶

# Get all projects # Returns all projects which are visible for the currently logged in user. jira.projects(included_archived=None) # Get all project alternative call # Returns all projects which are visible for the currently logged in user. jira.get_all_projects(included_archived=None) # Delete project jira.delete_project(key) # Archive Project jira.archive_project(key) # Get project jira.project(key, expand=None) # Get project info jira.get_project(key, expand=None) # Get project components using project key jira.get_project_components(key) # Get a full representation of a the specified project's versions jira.get_project_versions(key, expand=None) # Returns all versions for the specified project. Results are paginated. # Results can be ordered by the following fields: sequence, name, startDate, releaseDate. # Results can be filtered by the following fields: query, status. jira.get_project_versions_paginated(key, start=None, limit=None, order_by=None, expand=None, query=None, status=None) # Add missing version to project jira.add_version(key, project_id, version, is_archived=False, is_released=False) # Update an existing version jira.update_version(version, name=None, description=None, is_archived=None, is_released=None, start_date=None, release_date=None) # Get project leaders jira.project_leaders() # Get last project issuekey jira.get_project_issuekey_last(project) # Get all project issue keys. # JIRA Cloud API can return up to 100 results in one API call. # If your project has more than 100 issues see following community discussion: # https://community.atlassian.com/t5/Jira-Software-questions/Is-there-a-limit-to-the-number-of-quot-items-quot-returned-from/qaq-p/1317195 jira.get_project_issuekey_all(project) # Get project issues count jira.get_project_issues_count(project) # Get all project issues jira.get_all_project_issues(project, fields='*all', start=100, limit=500) # Get all assignable users for project jira.get_all_assignable_users_for_project(project_key, start=0, limit=50) # Update a project jira.update_project(project_key, data, expand='lead,description') # Get project permission scheme # Use 'expand' to get details (default is None) jira.get_project_permission_scheme(project_id_or_key, expand='permissions,user,group,projectRole,field,all') # Get the issue security scheme for project. # Returned if the user has the administrator permission or if the scheme is used in a project in which the # user has the administrative permission. # Use only_levels=True for get the only levels entries jira.get_project_issue_security_scheme(project_id_or_key, only_levels=False) # Resource for associating notification schemes and projects. # Gets a notification scheme associated with the project. # Follow the documentation of /notificationscheme/ resource for all details about returned value. # Use 'expand' to get details (default is None) possible values are notificationSchemeEvents,user,group,projectRole,field,all jira.get_priority_scheme_of_project(project_key_or_id, expand=None) # Returns a list of active users who have browse permission for a project that matches the search string for username. # Using " " string (space) for username gives All the active users who have browse permission for a project jira.get_users_with_browse_permission_to_a_project(self, username, issue_key=None, project_key=None, start=0, limit=100) 

Manage issues¶

# Get issue by key jira.issue(key) # Get issue field value jira.issue_field_value(key, field) # Update issue field fields = 'summary': 'New summary'> jira.update_issue_field(key, fields) # Get existing custom fields or find by filter jira.get_custom_fields(self, search=None, start=1, limit=50): # Check issue exists jira.issue_exists(issue_key) # Check issue deleted jira.issue_deleted(issue_key) # Update issue jira.issue_update(issue_key, fields) # Assign issue to user jira.assign_issue(issue_key, account_id) # Create issue jira.issue_create(fields) # Issue create or update jira.issue_create_or_update(fields) # Get issue transitions jira.get_issue_transitions(issue_key) # Get status ID from name jira.get_status_id_from_name(status_name) # Get transition id to status name jira.get_transition_id_to_status_name(issue_key, status_name) # Transition issue jira.issue_transition(issue_key, status) # Set issue status jira.set_issue_status(issue_key, status_name, fields=None) # Set issue status by transition_id jira.set_issue_status_by_transition_id(issue_key, transition_id) # Get issue status jira.get_issue_status(issue_key) # Get Issue Link jira.get_issue_link(link_id) # Get Issue Edit Meta jira.issue_editmeta(issue_key) # Create Issue Link data =  "type": "name": "Duplicate" >, "inwardIssue":  "key": "HSP-1">, "outwardIssue": "key": "MKY-1">, "comment":  "body": "Linked related issue!", "visibility":  "type": "group", "value": "jira-software-users" > > > jira.create_issue_link(data) # Remove Issue Link jira.remove_issue_link(link_id) # Create or Update Issue Remote Links jira.create_or_update_issue_remote_links(issue_key, link_url, title, global_id=None, relationship=None, icon_url=None, icon_title=None) # Get Issue Remote Link by link ID jira.get_issue_remote_link_by_id(issue_key, link_id) # Update Issue Remote Link by link ID jira.update_issue_remote_link_by_id(issue_key, link_id, url, title, global_id=None, relationship=None) # Delete Issue Remote Links jira.delete_issue_remote_link_by_id(issue_key, link_id) # Export Issues to csv jira.csv(jql, all_fields=False) # Add watcher to an issue jira.issue_add_watcher(issue_key, user) # Remove watcher from an issue jira.issue_delete_watcher(issue_key, user) # Get watchers for an issue jira.issue_get_watchers(issue_key) # Archive an issue jira.issue_archive(issue_id_or_key) # Restore an issue jira.issue_restore(issue_id_or_key) # Issue Comments jira.issue_get_comments(issue_id_or_key) # Get issue comment by id jira.issue_get_comment(issue_id_or_key, comment_id) # Get comments over all issues by ids jira.issues_get_comments_by_id(comment_id, [comment_id. ]) # Get change history for an issue jira.get_issue_changelog(issue_key) # Get worklog for an issue jira.issue_get_worklog(issue_key) # Create a new worklog entry for an issue # started is a date string in the format %Y-%m-%dT%H:%M:%S.000+0000%z jira.issue_worklog(issue_key, started, time_in_sec) 

Epic Issues¶

# Issues within an Epic jira.epic_issues(epic_key) 

Источник

Выгружаем историю изменений статуса задачи в Jira с помощью Python

В данной статье поэтапно расскажу, как подключится к Jira используя Python и выгрузить историю изменений статуса.

Подключение

Первым делом нам нужно установить библиотеку, которая упрощает работу с API Jira, делаем это с помощью следующей команды в консоли:

После установки импортируем библиотеку в наш проект и создаем экземпляр класса JIRA, указав адрес сервера Jira и учетные данные пользователя:

from jira import JIRA jira = JIRA(server='https://yourjiraserver', basic_auth=('username', 'password'))

Мы подключились к серверу и можем выгружать различные данные. Например, чтобы получить краткую информацию о задаче с ключом ‘Jira_key-123’, можно использовать следующий код:

from jira import JIRA jira = JIRA(server='https://yourjiraserver', basic_auth=('username', 'password')) issue = jira.issue('Jira_key-123') print(issue.fields.summary)

Как узнать названия полей?

Для того чтобы получить список доступных полей в задаче и их содержимое, нам нужно немного доработать наш предыдущий код добавив параметр expand со значением editmeta:

from jira import JIRA jira = JIRA(server='https://yourjiraserver', basic_auth=('username', 'password')) issue = jira.issue('Jira_key-123', expand='editmeta') with open('jira.txt', 'w', encoding='utf-8') as output: for field_name in issue.raw['fields']: print("Field:", field_name, "Value:", issue.raw['fields'][field_name] , file=output)

После выполнения кода рядом с вашим исполняемым файлом появится txt файл со списком доступных полей и их содержимым.

Как выгрузить историю изменений статуса?

Нужно по списку задач, которые были созданы вчера, получить историю изменений статуса. Формат вывода: Номер задачи, Из статуса, В статус, Дата и время, Автор изменений.

Первым делом нам нужно написать JQL запрос, который будет выдавать нам фильтрованный список заявок, которые подходят под наши условия.

Пример простого запроса, который отфильтрует заявки созданные вчера и принадлежащие определенному проекту:

project = 'Yourproject' AND created >= startOfDay(-1d) AND created < startOfDay(0d)

Далее дополняем наш код следующим образом:

import pandas as pd from jira import JIRA # Создаем переменную с нашим JQL запросом JQL # Создаем подключение к серверу Jira jira = JIRA(server='https://yourjiraserver', basic_auth=('username', 'password')) # Выгружаем список задач по нашему JQL запросу # maxResults - максимальное количество выгружаемых задач jira_key = jira.search_issues(JQL, maxResults=1000) # Выгружаем историю статусов и записываем в history_log history_log = [] for keyid in range(len(jira_key)): key_name = str(jira_keyJira python change status) issue = jira.issue(key_name, expand='changelog') changelog = issue.changelog for history in changelog.histories: for change in history.items: if change.field == 'status': statuses = <> statuses['ID'] = key_name statuses['fromString'] = change.fromString statuses['toString'] = change.toString statuses['created'] = history.created statuses['author'] = history.author.displayName history_log.append(statuses) # Сохраняем histiry_log как файл Excel pd.DataFrame(history_log).to_excel('jira.xlsx', index=False)

Выполнив код выше, мы получим желаемый результат.

Источник

Change status of issue in Jira using Rest call from Python

Change status of issue in Jira using Rest call from Python

I am trying to update the status of issue from ‘Request Info’ state to ‘Submitted’ via rest API in python.

after digging a lot in the documentation , I ran a Rest call to get the allowed status for the issue ID and i can see that the status ‘Submitted’ is allows:

"expand": "transitions", "transitions": [< "id": "381", "name": "Resubmit", "to": < "self": "https://ies-valor-jira.ies.mentorg.com/rest/api/2/status/10000", "description": "", "iconUrl": "https://ies-valor-jira.ies.mentorg.com/", "name": "Submitted", "id": "10000", "statusCategory": < "self": "https://ies-valor-jira.ies.mentorg.com/rest/api/2/statuscategory/2", "id": 2, "key": "new", "colorName": "blue-gray", "name": "To Do" 

So now i would like to change the status with the following code:

from jira import JIRA JIRA_SERVER = "https://ies-valor-jira.ies.mentorg.com/" jira_user_name = "myuser" jira_password = "mypassword!" jira_connection = JIRA(basic_auth=(jira_user_name, jira_password), server=JIRA_SERVER) jira.Issue='SF-6831' jira_connection.add_comment(jira.Issue, body="Resubmit issues") jira_connection.transition_issue("SF-6831", "Resubmit") 

But i get an error message that indicate :customfield_10509":"You must define "Resubmit Note: before you moving to "CCB Review" state">

this error is expected because this field is mandatory and it must be filled with a reason for the status change so i need to know how to update this custom field in the Rest call to allow the issue to change status.

I tried to use add.command function but i don’t know where i should specify the field name.
or is there a different way to do it.

Источник

Читайте также:  Запуск байт кода python
Оцените статью