Analysis of common methods of Python operation Jira library

Jira provides a complete RESTful API. If you don’t want to directly request the API interface, you can use the Python Jira library to operate Jira.

Jira Python documentation

installation method

pip install jira

Certification

Jira's access is authorized. When accessing the Jira project, you must first authenticate. The Jira Python library provides three authentication methods:

Only one authentication method needs to be selected. The following code uses Cookies for authentication.

form jira import JIRA
jira = JIRA('http://jira.***.com/', auth=('user name','login password')

The returned jira object can operate on Jira. The main operations include:

Project

jira.projects(): View a list of all projects

jira.project("Key of the project"): View a single project

The main attributes and methods of the project object are as follows:

Example

print(jira.projects()) # Print a list of all projects you have permission to access
project = jira.project('Key of a project')
print(project.key, project.name, project.lead)

Issue (Issue)

Issue is the core of Jira. The tasks, user stories, and bugs in Jira are essentially an issue.

A single issue object can be obtained through jira.issue ("the key of the issue"). The main attributes and methods of the issue are as follows:

Configure Fields (Fields)

The attributes in ields of general problems are divided into fixed attributes and custom attributes. The format of custom attributes is generally similar to customfield_10012. Fields of commonly used questions are:

Examples are as follows:

issue = jira.issue(‘JRA-1330’)
print(issue.key, issue.fields.summary, issue.fields.status)

Followers/comments/attachments

Examples are as follows:

issue = jira.issue('JRA-1330')print(jiaa.watchers(issue)) #All followers
jira.add_watcher(issue,'username') #Add followers

print(jira.comments(issue)) #All comments
comment = jira.comment(issue,'10234') #A comment
jira.add_comment(issue,'new comment') #Add comment
comment.update(body='update comment') #Update comment
comment.delete() #Delete this comment

print(issue.fields.attachment) #Question attachment
jira.add_attachment(issue=issue, attachment='/some/path/attachment.txt') #Add attachments

Create/Assign/Convert issues

Examples are as follows:

# Create question
issue_dict ={'project':{'id':123},'summary':'New issue from jira-python','description':'Look into this one','issuetype':{'name':'Bug'},}
new_issue = jira.create_issue(fields=issue_dict)

# Create questions in bulk
issue_list =[{'project':{'id':123},'summary':'First issue of many','description':'Look into this one','issuetype':{'name':'Bug'},},{'project':{'key':'FOO'},'summary':'Second issue','description':'Another one','issuetype':{'name':'Bug'},},{'project':{'name':'Bar'},'summary':'Last issue','description':'Final issue of batch.','issuetype':{'name':'Bug'},}]
issues = jira.create_issues(field_list=issue_list)

# Distribution problem
jira.assign_issue(issue,'newassignee')

# Conversion problem
jira.transition_issue(issue,'5', assignee={'name':'pm_user'}, resolution={'id':'3'})

search for

Jira's search is very powerful, and is equipped with a set of special search language called JQL (Jira Query Language). Jira's Python library is searched based on JQL syntax and returns a list of the searched questions.
The use statement is

jira.search_issues('JQL statement')

The default maximum number of results is not 1000, which can be configured through the maxResults parameter. When this parameter is -1, there is no limit to the number and all search results are returned.

jira.search_issues('project=PROJ and assignee = currentUser()', maxResults=-1)

The above is the whole content of this article, I hope it will be helpful to everyone's study.

Recommended Posts

Analysis of common methods of Python operation Jira library
Analysis of common methods of Python multi-process programming
Basic analysis of Python turtle library implementation
09. Common modules of Python3
Python analysis of wav files
Analysis of JS of Python crawler
Analysis of Python Sandbox Escape
Analysis of Python object-oriented programming
Collection of Python Common Modules
Analysis of usage examples of Python yield
Magic methods and uses of Python
Python preliminary implementation of word2vec operation
Python file operation basic process analysis
Implementation of python selenium operation cookie
Analysis of Python conditional control statements
Several common modes of Python functions
Some examples of python operation redis
​Full analysis of Python module knowledge
Example operation of python access Alipay
The operation of python access hdfs
Installation of python common libraries under windows
Detailed analysis of Python garbage collection mechanism
Summary of common operations of Python time module
The essence of Python language: Itertools library
The specific method of python import library
Python Automation (20) | Talk about several methods of Python operation PDF (merge, split, watermark, encryption)
Method analysis of Python calling C language program
Detailed explanation of python standard library OS module
Detailed explanation of how python supports concurrent methods
Python implementation of AI automatic matting example analysis
Example of feature extraction operation implemented in Python
7 features of Python3.9
Python file operation
Python data analysis
python operation kafka
Python drawing | A variety of typhoon path visualization methods
Detailed explanation of common tools for Python process control