用python编写的jira云api包装器
jira-cloud-python的Python项目详细描述
吉拉云Python
jira cloud python是用python编写的jira软件云的api包装器
安装
pip install jira-cloud-python
用法
客户端实例化
from jiracloud.client import Client
client = Client('CLIENT_ID', 'CLIENT_SECRET') # Host must have trailing slash
OAuth 2.0(3lo)
from jiracloud.client import Client
client = Client('CLIENT_ID', 'CLIENT_SECRET') # Host must have trailing slash
有关详细信息:https://developer.atlassian.com/cloud/jira/platform/oauth-2-authorization-code-grants-3lo-for-apps/
将用户指向授权URL以获取授权代码
刷新令牌可以与初始授权流中的访问令牌一起返回。 为此,请将脱机访问作用域添加到授权url的scope参数中。
scope_list = ['read:jira-user', 'read:jira-work', 'write:jira-work', 'offline_access']
url = client.authorization_url('REDIRECT_URI', scope_list, 'STATE')
交换访问令牌的授权码
response = client.exchange_code('REDIRECT_URI', 'CODE')
在库中设置访问令牌
client.set_access_token('ACCESS_TOKEN')
获取站点的cloudid
response = client.get_resource_list()
在库中设置cloudid
client.set_cloud_id('CLOUD_ID')
刷新令牌
response = client.refresh_token('REFRESH_TOKEN')
问题
获取问题
response = client.issues.get_issue('ISSUE_ID')
创建问题
data = {
"update": {},
"fields": {
"summary": "something's wrong",
"issuetype": {
"id": "10000"
},
"components": [
{
"id": "10000"
}
],
"customfield_20000": "06/Jul/19 3:25 PM",
"customfield_40000": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "this is a text field",
"type": "text"
}
]
}
]
},
"customfield_70000": [
"jira-administrators",
"jira-software-users"
],
"project": {
"id": "10000"
},
"description": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "description",
"type": "text"
}
]
}
]
},
"reporter": {
"id": "99:e2a16dd9-2ffb-4a4b-a9bd-bd1145a020ee"
},
"fixVersions": [
{
"id": "10001"
}
],
"customfield_10000": "09/Jun/19",
"priority": {
"id": "20000"
},
"labels": [
"bugfix",
"blitz_test"
],
"timetracking": {
"remainingEstimate": "5",
"originalEstimate": "10"
},
"customfield_30000": [
"10000",
"10002"
],
"customfield_80000": {
"value": "red"
},
"security": {
"id": "10000"
},
"environment": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "environment",
"type": "text"
}
]
}
]
},
"versions": [
{
"id": "10000"
}
],
"duedate": "2019-05-11T00:00:00.000Z",
"customfield_60000": "jira-software-users",
"customfield_50000": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "this is a text area. big text.",
"type": "text"
}
]
}
]
},
"assignee": {
"id": "e5:e1a16c14-1fe0-1c93-a2b1-ac4493ace0f1"
}
}
}
response = client.issues.create_issue(data)
删除问题
response = client.issues.delete_issue('ISSUE_ID')
获取创建问题元数据
response = client.issues.get_create_issue_metadata()
使用jql搜索问题
data = {
"expand": [
"names",
"schema",
"operations"
],
"jql": "project = HSP",
"maxResults": 15,
"fieldsByKeys": false,
"fields": [
"summary",
"status",
"assignee"
],
"startAt": 0
}
response = client.issues.search_for_issues_using_jql(data)
权限
获取我的权限
response = client.permissions.get_my_permissions()
项目
response = client.projects.get_projects_paginated()
用户
response = client.users.find_users_assignable_to_issues()
webhooks
client.set_access_token('ACCESS_TOKEN')
response = client.get_resource_list()
在库中设置cloudid
client.set_cloud_id('CLOUD_ID')
刷新令牌
response = client.refresh_token('REFRESH_TOKEN')
问题
获取问题
response = client.issues.get_issue('ISSUE_ID')
创建问题
data = {
"update": {},
"fields": {
"summary": "something's wrong",
"issuetype": {
"id": "10000"
},
"components": [
{
"id": "10000"
}
],
"customfield_20000": "06/Jul/19 3:25 PM",
"customfield_40000": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "this is a text field",
"type": "text"
}
]
}
]
},
"customfield_70000": [
"jira-administrators",
"jira-software-users"
],
"project": {
"id": "10000"
},
"description": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "description",
"type": "text"
}
]
}
]
},
"reporter": {
"id": "99:e2a16dd9-2ffb-4a4b-a9bd-bd1145a020ee"
},
"fixVersions": [
{
"id": "10001"
}
],
"customfield_10000": "09/Jun/19",
"priority": {
"id": "20000"
},
"labels": [
"bugfix",
"blitz_test"
],
"timetracking": {
"remainingEstimate": "5",
"originalEstimate": "10"
},
"customfield_30000": [
"10000",
"10002"
],
"customfield_80000": {
"value": "red"
},
"security": {
"id": "10000"
},
"environment": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "environment",
"type": "text"
}
]
}
]
},
"versions": [
{
"id": "10000"
}
],
"duedate": "2019-05-11T00:00:00.000Z",
"customfield_60000": "jira-software-users",
"customfield_50000": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "this is a text area. big text.",
"type": "text"
}
]
}
]
},
"assignee": {
"id": "e5:e1a16c14-1fe0-1c93-a2b1-ac4493ace0f1"
}
}
}
response = client.issues.create_issue(data)
删除问题
response = client.issues.delete_issue('ISSUE_ID')
获取创建问题元数据
response = client.issues.get_create_issue_metadata()
使用jql搜索问题
data = {
"expand": [
"names",
"schema",
"operations"
],
"jql": "project = HSP",
"maxResults": 15,
"fieldsByKeys": false,
"fields": [
"summary",
"status",
"assignee"
],
"startAt": 0
}
response = client.issues.search_for_issues_using_jql(data)
权限
获取我的权限
response = client.permissions.get_my_permissions()
项目
response = client.projects.get_projects_paginated()
用户
response = client.users.find_users_assignable_to_issues()
webhooks
client.set_cloud_id('CLOUD_ID')
response = client.refresh_token('REFRESH_TOKEN')
response = client.issues.get_issue('ISSUE_ID')
data = {
"update": {},
"fields": {
"summary": "something's wrong",
"issuetype": {
"id": "10000"
},
"components": [
{
"id": "10000"
}
],
"customfield_20000": "06/Jul/19 3:25 PM",
"customfield_40000": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "this is a text field",
"type": "text"
}
]
}
]
},
"customfield_70000": [
"jira-administrators",
"jira-software-users"
],
"project": {
"id": "10000"
},
"description": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "description",
"type": "text"
}
]
}
]
},
"reporter": {
"id": "99:e2a16dd9-2ffb-4a4b-a9bd-bd1145a020ee"
},
"fixVersions": [
{
"id": "10001"
}
],
"customfield_10000": "09/Jun/19",
"priority": {
"id": "20000"
},
"labels": [
"bugfix",
"blitz_test"
],
"timetracking": {
"remainingEstimate": "5",
"originalEstimate": "10"
},
"customfield_30000": [
"10000",
"10002"
],
"customfield_80000": {
"value": "red"
},
"security": {
"id": "10000"
},
"environment": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "environment",
"type": "text"
}
]
}
]
},
"versions": [
{
"id": "10000"
}
],
"duedate": "2019-05-11T00:00:00.000Z",
"customfield_60000": "jira-software-users",
"customfield_50000": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "this is a text area. big text.",
"type": "text"
}
]
}
]
},
"assignee": {
"id": "e5:e1a16c14-1fe0-1c93-a2b1-ac4493ace0f1"
}
}
}
response = client.issues.create_issue(data)
response = client.issues.delete_issue('ISSUE_ID')
response = client.issues.get_create_issue_metadata()
使用jql搜索问题
data = {
"expand": [
"names",
"schema",
"operations"
],
"jql": "project = HSP",
"maxResults": 15,
"fieldsByKeys": false,
"fields": [
"summary",
"status",
"assignee"
],
"startAt": 0
}
response = client.issues.search_for_issues_using_jql(data)
权限
获取我的权限
response = client.permissions.get_my_permissions()
项目
response = client.projects.get_projects_paginated()
用户
response = client.users.find_users_assignable_to_issues()
webhooks
data = {
"expand": [
"names",
"schema",
"operations"
],
"jql": "project = HSP",
"maxResults": 15,
"fieldsByKeys": false,
"fields": [
"summary",
"status",
"assignee"
],
"startAt": 0
}
response = client.issues.search_for_issues_using_jql(data)
response = client.permissions.get_my_permissions()
response = client.projects.get_projects_paginated()
用户
response = client.users.find_users_assignable_to_issues()
webhooks
目前,webhook不适用于oauth 2.0应用程序,有关详细信息:https://ecosystem.atlassian.net/browse/ACJIRA-1632
贡献
我们总是感谢任何形式的贡献,包括但不限于错误报告、代码增强、错误修复,甚至功能建议。
您可以报告您发现的任何错误,或使用新的issue建议新功能。
如果您想为包装添加一些功能:
- 用叉子叉(https://github.com/ingmferrer/jira-cloud-python)
- 创建您的功能分支(git checkout-b我的新功能)
- 提交更改(git commit-am'添加我的新功能')
- 推到分支(git push origin我的新功能)
- 创建新的拉取请求