{"id":990,"date":"2021-02-25T10:14:12","date_gmt":"2021-02-25T02:14:12","guid":{"rendered":"http:\/\/blog.5danyuan.com\/?p=990"},"modified":"2021-02-25T10:14:12","modified_gmt":"2021-02-25T02:14:12","slug":"python-%e6%93%8d%e4%bd%9cjira","status":"publish","type":"post","link":"https:\/\/blog.5danyuan.com\/?p=990","title":{"rendered":"Python \u64cd\u4f5cJIRA"},"content":{"rendered":"\n<p>\u6700\u8fd1\u88ab\u5404\u79cd\u7edf\u8ba1\u548c\u5f52\u603b\u7ea0\u7ed3\u7740\uff0c\u4ece\u7cfb\u7edf\u91cc\u67e5\u8be2\u7136\u540e\u5728 Excel \u91cc\u586b\u6570\u636e\u3002\u5c31\u5bfb\u601d\u7740\u662f\u5426\u6709\u65b9\u5f0f\u53ef\u4ee5\u52a0\u901f\uff0c\u7f51\u4e0a\u68c0\u7d22\u4e0b\uff0c\u679c\u7136\u627e\u5230\u6709\u8bbf\u95ee JIRA \u73b0\u6210\u7684\u5e93\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip3 install jira<\/code><\/pre>\n\n\n\n<p><strong>\u8ba4\u8bc1<\/strong><br>JIRA\u7684\u8bbf\u95ee\u662f\u6709\u6743\u9650\u7684\uff0c\u5728\u8bbf\u95eeJira\u9879\u76ee\u65f6\u9996\u5148\u8981\u8fdb\u884c\u8ba4\u8bc1\uff0cJIRA Python\u5e93\u63d0\u4f9b\u4e863\u79cd\u8ba4\u8bc1\u65b9\u5f0f\uff1a<\/p>\n\n\n\n<p>\u901a\u8fc7Cookis\u65b9\u5f0f\u8ba4\u8bc1\uff08\u7528\u6237\u540d\uff0c\u5bc6\u7801\uff09<br>\u901a\u8fc7Basic Auth\u65b9\u5f0f\u8ba4\u8bc1\uff08\u7528\u6237\u540d\uff0c\u5bc6\u7801\uff09<br>\u901a\u8fc7OAuth\u65b9\u5f0f\u8ba4\u8bc1<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>form jira import JIRA\n\njira = JIRA('http:\/\/jira.***.com\/', auth=('\u7528\u6237\u540d', '\u767b\u5f55\u5bc6\u7801')<\/code><\/pre>\n\n\n\n<p>\u8fd4\u56de\u7684jira\u5bf9\u8c61\u4fbf\u53ef\u4ee5\u5bf9Jira\u8fdb\u884c\u64cd\u4f5c\u3002\u4e3b\u8981\u7684\u64cd\u4f5c\u5305\u62ec\uff1a<\/p>\n\n\n\n<ul><li>\u9879\u76ee<\/li><li>\u95ee\u9898<\/li><li>\u641c\u7d22<\/li><li>\u5173\u6ce8\u8005<\/li><li>\u8bc4\u8bba<\/li><li>\u9644\u4ef6<\/li><\/ul>\n\n\n\n<p><strong>\u9879\u76ee\uff08Project\uff09<\/strong><br>jira.projects(): \u67e5\u770b\u6240\u6709\u9879\u76ee\u5217\u8868<br>jira.project(&#8220;\u9879\u76ee\u7684Key&#8221;): \u67e5\u770b\u5355\u4e2a\u9879\u76ee<\/p>\n\n\n\n<p><br>\u9879\u76ee\u5bf9\u8c61\u7684\u4e3b\u8981\u5c5e\u6027\u53ca\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul><li>key: \u9879\u76ee\u7684Key<\/li><li>name: \u9879\u76ee\u540d\u79f0<\/li><li>description: \u9879\u76ee\u63cf\u8ff0<\/li><li>lead: \u9879\u76ee\u8d1f\u8d23\u4eba<\/li><li>projectCategory: \u9879\u76ee\u5206\u7c7b<\/li><li>components: \u9879\u76ee\u7ec4\u4ef6<\/li><li>versions: \u9879\u76ee\u4e2d\u7684\u7248\u672c<\/li><li>raw: \u9879\u76ee\u7684\u539f\u59cbAPI\u6570\u636e<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>print(jira.projects()) # \u6253\u5370\u6240\u6709\u4f60\u6709\u6743\u9650\u8bbf\u95ee\u7684\u9879\u76ee\u5217\u8868\nproject = jira.project('\u67d0\u4e2a\u9879\u76ee\u7684Key')\nprint(project.key, project.name, project.lead)<\/code><\/pre>\n\n\n\n<p><strong>\u95ee\u9898\uff08Issue\uff09<\/strong><br>Issue\u662f JIRA \u7684\u6838\u5fc3\uff0cJIRA \u4e2d\u7684\u4efb\u52a1\uff0c\u7528\u6237Story\uff0cBug\u5b9e\u8d28\u4e0a\u90fd\u662f\u4e00\u4e2aIssue\u3002<br>\u5355\u4e2a\u95ee\u9898\u5bf9\u8c61\u53ef\u4ee5\u901a\u8fc7jira.issue(&#8220;\u95ee\u9898\u7684Key&#8221;)\u5f97\u5230\uff0c\u95ee\u9898\u7684\u4e3b\u8981\u5c5e\u6027\u548c\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul><li>id: \u95ee\u9898\u7684id<\/li><li>key: \u95ee\u9898\u7684Key<\/li><li>permalink(): \u83b7\u53d6\u95ee\u9898\u8fde\u63a5<\/li><li>fields: \u95ee\u9898\u7684\u63cf\u8ff0\uff0c\u521b\u5efa\u65f6\u95f4\u7b49\u6240\u6709\u7684\u914d\u7f6e\u57df<\/li><li>raw: \u95ee\u9898\u7684\u539f\u59cbAPI\u6570\u636e<\/li><\/ul>\n\n\n\n<p><br><strong>\u914d\u7f6e\u57df\uff08Fields\uff09<\/strong><br>\u4e00\u822c\u95ee\u9898\u7684ields\u4e2d\u7684\u5c5e\u6027\u5206\u4e3a\u56fa\u5b9a\u5c5e\u6027\u548c\u81ea\u5b9a\u4e49\u5c5e\u6027\uff0c\u81ea\u5b9a\u4e49\u5c5e\u6027\u683c\u5f0f\u4e00\u822c\u4e3a\u7c7b\u4f3ccustomfield_10012\u8fd9\u79cd\u3002\u5e38\u7528\u7684\u95ee\u9898\u7684Fields\u6709\uff1a<\/p>\n\n\n\n<ul><li>assignee\uff1a\u7ecf\u529e\u4eba<\/li><li>created: \u521b\u5efa\u65f6\u95f4<\/li><li>creator: \u521b\u5efa\u4eba<\/li><li>labels: \u6807\u7b7e<\/li><li>priorit: \u4f18\u5148\u7ea7<\/li><li>progress:<\/li><li>project: \u6240\u793a\u9879\u76ee<\/li><li>reporter: \u62a5\u544a\u4eba<\/li><li>status: \u72b6\u6001<\/li><li>summary: \u95ee\u9898\u63cf\u8ff0<\/li><li>worklog: \u6d3b\u52a8\u65e5\u5fd7<\/li><li>updated: \u66f4\u65b0\u65f6\u95f4<\/li><li>watches: \u5173\u6ce8\u8005<\/li><li>comments: \u8bc4\u8bba<\/li><li>resolution: \u89e3\u51b3\u65b9\u6848<\/li><li>subtasks: \u5b50\u4efb\u52a1<\/li><li>issuelinks: \u8fde\u63a5\u95ee\u9898<\/li><li>lastViewed: \u6700\u8fd1\u67e5\u770b\u65f6\u95f4<\/li><li>attachment<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>issue = jira.issue('JRA-1330')\nprint(issue.key, issue.fields.summary, issue.fields.status)<\/code><\/pre>\n\n\n\n<p><strong>\u5173\u6ce8\u8005\/\u8bc4\u8bba\/\u9644\u4ef6<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>jira.watchers(): \u95ee\u9898\u7684\u5173\u6ce8\u8005<\/li><li>jira.add_watcher(): \u6dfb\u52a0\u5173\u6ce8\u8005<\/li><li>jira.remove_watcher(): \u79fb\u9664\u5173\u6ce8\u8005<\/li><li>jira.comments(): \u95ee\u9898\u7684\u6240\u6709\u8bc4\u8bba<\/li><li>jira.comment(): \u67d0\u6761\u8bc4\u8bba<\/li><li>jira.add_comment()\uff1a\u6dfb\u52a0\u8bc4\u8bba<\/li><li>comment.update()\/delete(): \u66f4\u65b0\/\u5220\u9664\u8bc4\u8bba<\/li><li>jira.add_attachment(): \u6dfb\u52a0\u9644\u4ef6<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>issue = jira.issue('JRA-1330')\n\nprint(jiaa.watchers(issue)) # \u6240\u6709\u5173\u6ce8\u8005\njira.add_watcher(issue, 'username') # \u6dfb\u52a0\u5173\u6ce8\u8005\n\nprint(jira.comments(issue)) # \u6240\u6709\u8bc4\u8bba\ncomment = jira.comment(issue, '10234') # \u67d0\u6761\u8bc4\u8bba\njira.add_comment(issue, 'new comment') # \u65b0\u589e\u8bc4\u8bba\ncomment.update(body='update comment') # \u66f4\u65b0\u8bc4\u8bba\ncomment.delete() # \u5220\u9664\u8be5\u8bc4\u8bba\n\nprint(issue.fields.attachment) # \u95ee\u9898\u9644\u4ef6\njira.add_attachment(issue=issue, attachment='\/some\/path\/attachment.txt') # \u6dfb\u52a0\u9644\u4ef6<\/code><\/pre>\n\n\n\n<p><br><strong>\u521b\u5efa\/\u5206\u914d\/\u8f6c\u6362\u95ee\u9898<\/strong><br>jira.create_issue(): \u521b\u5efa\u95ee\u9898<br>jira.create_issues(): \u6279\u91cf\u521b\u5efa\u95ee\u9898<br>jira.assign_issue(): \u5206\u914d\u95ee\u9898<br>jira.transitions(): \u83b7\u53d6\u95ee\u9898\u7684\u5de5\u4f5c\u6d41<br>jira.transition_issue(): \u8f6c\u6362\u95ee\u9898<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u521b\u5efa\u95ee\u9898\nissue_dict = {\n    'project': {'id': 123},\n    'summary': 'New issue from jira-python',\n    'description': 'Look into this one',\n    'issuetype': {'name': 'Bug'},\n}\nnew_issue = jira.create_issue(fields=issue_dict)\n\n# \u6279\u91cf\u521b\u5efa\u95ee\u9898\nissue_list = &#91;\n{\n    'project': {'id': 123},\n    'summary': 'First issue of many',\n    'description': 'Look into this one',\n    'issuetype': {'name': 'Bug'},\n},\n{\n    'project': {'key': 'FOO'},\n    'summary': 'Second issue',\n    'description': 'Another one',\n    'issuetype': {'name': 'Bug'},\n},\n{\n    'project': {'name': 'Bar'},\n    'summary': 'Last issue',\n    'description': 'Final issue of batch.',\n    'issuetype': {'name': 'Bug'},\n}]\nissues = jira.create_issues(field_list=issue_list)\n\n# \u5206\u914d\u95ee\u9898\njira.assign_issue(issue, 'newassignee')\n\n# \u8f6c\u6362\u95ee\u9898\njira.transition_issue(issue, '5', assignee={'name': 'pm_user'}, resolution={'id': '3'})<\/code><\/pre>\n\n\n\n<p><strong>\u641c\u7d22<\/strong><br>JIRA \u7684\u641c\u7d22\u975e\u5e38\u5f3a\u5927\uff0c\u5e76\u914d\u6709\u4e00\u5957\u4e13\u95e8\u7684\u641c\u7d22\u8bed\u8a00\uff0c\u79f0\u4e3aJQL(Jira Query Language)\uff0cJIRA \u7684Python\u5e93\u4fbf\u662f\u57fa\u4e8eJQL\u8bed\u6cd5\u8fdb\u884c\u641c\u7d22\u7684\uff0c\u8fd4\u56de\u7684\u662f\u641c\u7d22\u5230\u7684\u95ee\u9898\u5217\u8868\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>jira.search_issues('JQL\u8bed\u53e5')\n#\u9ed8\u8ba4\u6700\u5927\u7ed3\u679c\u6570\u672a1000\uff0c\u53ef\u4ee5\u901a\u8fc7maxResults\u53c2\u6570\u914d\u7f6e\uff0c\u8be5\u53c2\u6570\u4e3a-1\u65f6\u4e0d\u9650\u5236\u6570\u91cf\uff0c\u8fd4\u56de\u6240\u6709\u641c\u7d22\u7ed3\u679c\u3002\n\njira.search_issues('project=PROJ and assignee = currentUser()', maxResults=-1)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u88ab\u5404\u79cd\u7edf\u8ba1\u548c\u5f52\u603b\u7ea0\u7ed3\u7740\uff0c\u4ece\u7cfb\u7edf\u91cc\u67e5\u8be2\u7136\u540e\u5728 Excel \u91cc\u586b\u6570\u636e\u3002\u5c31\u5bfb\u601d\u7740\u662f\u5426\u6709\u65b9\u5f0f\u53ef\u4ee5\u52a0\u901f\uff0c\u7f51\u4e0a\u68c0\u7d22\u4e0b\uff0c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-990","post","type-post","status-publish","format-standard","hentry","category-daily"],"_links":{"self":[{"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/posts\/990","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=990"}],"version-history":[{"count":0,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=\/wp\/v2\/posts\/990\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=990"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=990"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.5danyuan.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=990"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}