1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
import json import sys
import requests import tablib from requests.auth import HTTPBasicAuth
import excel2Image
''' 执行方式:python jiraSearch.py webhook mobiles '''
WEBHOOK_TOKEN = str(sys.argv[1])
try: MOBILES = str(sys.argv[2]) except: MOBILES = None
mobiles = "" if MOBILES: atMobiles = MOBILES.split(',') for mobile in atMobiles: mobiles += "@" + mobile else: atMobiles = None
def getIssuesList(): issuesSearchUrl = "https://jira.shadow.com/rest/api/2/search" filterUrl = "https://jira.shadow.com/rest/api/2/filter/26517" auth = HTTPBasicAuth("taoyi", "XXXXXXXXXXXXXXXX") headers = { "Accept": "application/json" }
filterResp = requests.request( "GET", filterUrl, headers=headers, auth=auth )
jql = filterResp.json()['jql']
query = {'jql': jql}
response = requests.request( "GET", issuesSearchUrl, headers=headers, params=query, auth=auth ) issuesList = response.json()['issues'] return issuesList
def getShowWords(): issueWords = [] issuesList = getIssuesList() for issue in issuesList: issueWords.append({'类型': issue['fields']['issuetype']['name'], '关键字': issue['key'], '概要': issue['fields']['summary'], '报告人': issue['fields']['reporter']['displayName'], '经办人': issue['fields']['assignee']['displayName'], '优先级': issue['fields']['priority']['name'], '状态': issue['fields']['status']['name'], '创建时间': issue['fields']['created'].replace('T', ' ').split('.')[0], '更新时间': issue['fields']['updated'].replace('T', ' ').split('.')[0]})
print(issueWords) return issueWords
def json2Excel(): rows = getShowWords() header = tuple([i for i in rows[0].keys()]) data = [] for row in rows: body = [] for v in row.values(): body.append(v) data.append(tuple(body)) data = tablib.Dataset(*data, headers=header) print(data) open('data.xlsx', 'wb').write(data.xlsx)
def getBugImageUrl(): url = 'https://sm.ms/api/v2/upload' headers = {'Authorization': 'dq2u9BXgV2AzsZm7UUzxz8heTxl4ojmM'} file_obj = open('./0.png', 'rb') file = {'smfile': file_obj} response = requests.post(url, files=file, headers=headers) print(response.json()) if not response.json()['success']: bugImageUrl = response.json()['images'] else: bugImageUrl = response.json()['data']['url'] print(bugImageUrl) return bugImageUrl
def sendMarkdownDing(): webhook = "https://oapi.dingtalk.com/robot/send?access_token=" + WEBHOOK_TOKEN header = { "Content-Type": "application/json", "Charset": "UTF-8" } data = { "msgtype": "markdown", "markdown": { "title": "未解决BUG列表,请及时处理!", "text": '#### **未解决BUG列表,请及时处理!**\n\n' ' >https://jira.shadow.com/issues/?filter=26517\n\n' ' >%s\n\n' % mobiles + '![](' + getBugImageUrl() + ')' }, "at": { "atMobiles": atMobiles, "isAtAll": False } } print(data) sendData = json.dumps(data) sendData = sendData.encode("utf-8") resp = requests.post(url=webhook, data=sendData, headers=header) return resp.json()
if __name__ == '__main__': json2Excel() html_list = excel2Image.ReportImage.excel_html("data.xlsx", "./") excel2Image.ReportImage.html_image(html_list, "./") sendMarkdownDing()
|