Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to count the bug of Jira and send email by Python

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article shows you how Python counts the bug of Jira and sends emails. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

1. First install using pip on pycharm

Pip install html-table pip install jira

two。 Initialize the sender's mailbox, account number, password

# sender mailbox account my_sender = 'user name of username@xxx.com.cn'# user login mailbox, password of password login mailbox (authorization code, that is, client password, non-web login password), but you can also log in successfully with the login password of Tencent mailbox my_pass =' xxxxx'# recipient mailbox account my_users= ['username@xxx.com.cn']

3. Log in to Jira

Class JiraTool:# initializes def _ _ init__ (self): self.server = 'http://ip:5500' / / Ip address of connecting Jira self.basic_auth = (' username', 'password') / / account and password of connecting Jira self.jiraClinet = None

4. Log in to Jira

Def login (self): self.jiraClinet = JIRA (server=self.server, basic_auth=self.basic_auth) if self.jiraClinet! = None: print ("login succeeded!") Return True else: return False

5. Get a list of Jira questions

Def get_issue_list_by_jql (self, jql): issue_list = [] issue_key_list = self.jiraClinet.search_issues (jql_str=jql,startAt=0,maxResults=1000) / / Jira default statistics 50 items MaxResults setting size for key_list in issue_key_list: issue = self.jiraClinet.issue (key_list.key) issue_list.append (issue) # print (issue.key) # keyword # print (issue.fields.summary) # bug description # print (issue.fields.status) bug status # print (issue.fields.assignee) # Manager # print (issue.fields.components [0] .name) # module # print (issue.fields.priority) # priority return issue_list

6. Create a table

Def gen_new_bug_caption_str (issue_list): dict = {} for issue in issue_list: dict [issue.fields.status.name] = dict.get (issue.fields.status.name, 0) + 1 # dict [issue.key.split ('-') [0]] = dict.get (issue.key.split ('-') [0]) 0) + 1 caption_str ='A total of bug' + str (len (issue_list)) + 'have been added in the past week. Closed:'+ str (dict.get ('closed') +'. Resolved to close:'+ str (dict.get ('resolved')) +'. Pending:'+ str (dict.get ('pending')) +'# print (caption_str) return caption_str

7. Generate html

# title style # table.caption.set_style ({'font-size':'15px','align':'left'}) table.caption.set_style ({' font-size':'15px'}) # Table style That is, label style table.set_style ({'border-collapse':'collapse',' word-break':'keep-all', 'white-space':'nowrap',' font-size':'14px'}) # sets the style of each cell Mainly specify the border style: table.set_cell_style ({'border-color':'#000',' border-width':'1px', 'border-style':'solid',' padding':'5px',}) # set the header cell style, specify the color, font size And fill size: # header style table.set_header_row_style ({'color':'#fff',' background-color':'#696969', 'font-size':'18px',}) # override form cell font style table.set_header_cell_style ({' padding':'15px',}) # traverse data rows Set background color for row in table.iter_data_rows (): if row [1] .value in "pending" according to different states: row [1] .set _ style ({'background-color':' # FFB6C1' }) if row [1] .value in "resolved": row [1] .set _ style ({'background-color':' # E1FFFFF,}) if row [1] .value in "closed": row [1] .set _ style ({'background-color':' # 90EE99' }) if row [1] .value in "reopen": row [1] .set _ style ({'background-color':' # DC143C',}) if row [1] .value in "under development": row [1] .set _ style ({'background-color':' # f7d7a7') }) # generate HTML text: html = table.to_html () # print (html) return html

8. Send an email

Def sendmail (html): ret=True try: # email content msg=MIMEText (html,'html','utf-8') # corresponding sender email nickname and sender email account number msg ['From'] = formataddr (["Zhang San") in parentheses My_sender]) # corresponding recipient email nickname, recipient email account # msg ['To'] = formataddr (["Li Si", my_user]) # subject msg [' Subject'] = "bug situation Statistics" server=smtplib.SMTP_SSL ("smtp.exmail.qq.com", 465) # Log in to the server Parentheses correspond to the sender's mailbox account number and mailbox password server.login (my_sender, my_pass) # send email The parentheses correspond to the sender's mailbox account, recipient's mailbox account, sending email server.sendmail (my_sender, my_users, msg.as_string ()) # close connection server.quit () # if the statement in try is not executed, the following ret=False except Exception: ret=False return ret will be executed

9. Debug

New_bug_jql = "project in (AAA, BBB, CCC) AND issuetype in (Bug, defect) AND created > =-1w ORDER BY component ASC, assignee ASC, priority DESC, updated DESC" old_bug_jql = "project in (AAA, BBB, CCC) AND issuetype in (Bug, defect) AND status in (pending, under development, Reopened) AND created", ">"). Replace ("", "\"). Replace ("

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report