吉拉问题提醒 [英] Jira issue reminder

查看:65
本文介绍了吉拉问题提醒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当问题开放24/36/48小时后,如何通过电子邮件创建到预定义邮件组的通知.

How to create a notification via emails to a pre-defined mail group when an issue is open for 24/36/48 hrs.

对于任何一种类型(24/36/48),都应该有一个提醒,如果重新打开问题,则应该重新开始计数.

There should be one reminder for any of those types (24/36/48) , and if an issue was re-opened the count should be restarted.

推荐答案

经过大量搜索,我已经解决了这个问题:

After lot's of searching I've solved it like this:

  • 创建了一个名为自此之后开始"的自定义字段-一个日期时间"字段,用于保存问题的打开时间.
  • 创建了一个名为通知"的自定义字段-只读文本字段.
  • 使用 Jira脚本套件,我创建了一个后功能将其置于每次转为打开"状态的过渡中.这是为了保持问题的开放时间.
  • Created a custom field called "Open since" - a 'Date Time' field to hold the time the issue has been opened.
  • Created a custom field called "Notification" - a read only text field.
  • Using the Jira Scripting Suite, I've created a post-function and placed it on every transition going to the 'Open' status. This is to keep the issue opening time.

代码:

from com.atlassian.jira import ComponentManager
from datetime import datetime

opend_since_field = "customfield_10001"

# get opened since custom field:
cfm = ComponentManager.getInstance().getCustomFieldManager()
# get current time
currentTime = datetime.today()
# save current time
issue.setCustomFieldValue(cfm.getCustomFieldObject(opend_since_field),currentTime)

  • 我创建了一个新的过滤器,以获取开放时间超过24小时的问题列表:
  • JQL:

    project = XXX AND status= Open ORDER BY updated ASC, key DESC
    

    • 最后-我使用了 Jira远程API - XML-RPC 方法来编写python脚本计划每5分钟运行一次.剧本 从过滤器读取所有发出的消息,将所有处于打开"状态的消息拉出24小时/36小时/48小时以上,发送提醒电子邮件,并将其标记为已通知,因此将仅发送每种类型的提醒.
      • Lastly - I've used the Jira remote API - the XML-RPC method to write a python script scheduled to run every 5 minutes. The script reads all the issued from the filter, pulls all of them that have an 'Open' status for over 24h/36h/48h, send a reminder email, and mark them as notified, so only one reminder of each type will be sent.
      • python代码:

        #!/usr/bin/python
        
        # Refer to the XML-RPC Javadoc to see what calls are available:
        # http://docs.atlassian.com/software/jira/docs/api/rpc-jira-plugin/latest/com/atlassian/jira/rpc/xmlrpc/XmlRpcService.html
        # /home/issues_reminder.py
        
        import xmlrpclib
        import time
        from time import mktime
        from datetime import datetime
        from datetime import timedelta
        import smtplib,email
        from smtplib import SMTP 
        from email.MIMEMultipart import MIMEMultipart
        from email.MIMEBase import MIMEBase
        from email.MIMEText import MIMEText
        from email import Encoders
        
        # Jira connction info
        server = 'https://your.jira.com/rpc/xmlrpc'
        user = 'user'
        password = 'password'
        filter = '10302' # Filter ID
        # Email definitions 
        smtpserver = 'mail.server.com'
        fromAddr = 'support@your.jira.com'
        mail_user = 'jira_admin@your.domain.com'
        mail_password = 'password'
        toAddr = 'support@your.domain.com'
        mysubject = "hrs Issue notification!!!"
        opend_since_field = "customfield_10101"
        
        
        COMMASPACE = ', '
        def email_issue(issue,esc_time):
            # create html email
            subject = '['+issue+'] '+esc_time+mysubject
            html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" '
            html +='"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">'
            html +='<body style="font-size:12px;font-family:Verdana">'
            html +='<p align="center"><img src="your_logo.jpg" alt="logo" height="43" width="198"></p> '
            html +='<p> The issue ['+issue+'] is open for over '+esc_time+' hours.</p>'
            html +='<p> A link to view the issue: https://your.jira.com/browse/'+issue+'.</p>'
            html +='<BR><p> This is an automated email sent from Jira.</p>'
            html +='</body></html>'
            emailMsg = email.MIMEMultipart.MIMEMultipart('alternative')
            emailMsg['Subject'] = subject
            emailMsg['From'] = fromAddr
            emailMsg['To'] = toAddr
            emailMsg.attach(MIMEText(html, 'html'))
            # Send the email
            emailserver = SMTP(smtpserver) # ip or domain name of smtp server
            emailserver.login(mail_user, mail_password)
            emailserver.sendmail(fromAddr, [toAddr], emailMsg.as_string())
            emailserver.quit()
            return
        
        
        s = xmlrpclib.ServerProxy(server)
        auth = s.jira1.login(user, password)
        
        esc12List = []
        esc24List = []
        esc48List = []
        
        
        issues = s.jira1.getIssuesFromFilter(auth, filter)
        print "Modifying issue..."
        for issue in issues:
                creation = 0;
                # get open since time
                for customFields in issue['customFieldValues']:
                        if customFields['customfieldId'] == opend_since_field :
                                print "found field!"+  customFields['values']
                                creation = customFields['values']
                if (creation == 0):
                        creation = issue['created']
                        print "field not found"
            creationTime = datetime.fromtimestamp(mktime(time.strptime(creation, '%d/%b/%y %I:%M %p')))
            currentTime = datetime.fromtimestamp(mktime(time.gmtime()))
            delta = currentTime - creationTime
            esc12 = timedelta(hours=12)
            esc24 = timedelta(hours=24)
            esc48 = timedelta(hours=48)
            print "\nchecking issue "+issue['key']
            if (delta < esc12):
                print "less than 12 hours"
                print "not updating"
                continue
            if (delta < esc24):
                print "less than 24 hours"
                for customFields in issue['customFieldValues']:
                    if customFields['customfieldId'] == 'customfield_10412':
                        if customFields['values'] == '12h':
                            print "not updating"
                            break
                        else:
                            print "updating !!!"
                            s.jira1.updateIssue(auth, issue['key'], {"customfield_10412": ["12h"]})
                            esc12List.append(issue['key'])
                            break
                continue
            if (delta < esc48):
                print "less than 48 hours"
                for customFields in issue['customFieldValues']:
                    if customFields['customfieldId'] == 'customfield_10412':
                        if customFields['values'] == '24h':
                            print "not updating"
                            break
                        else:
                            print "updating !!!"
                            s.jira1.updateIssue(auth, issue['key'], {"customfield_10412": ["24h"]})
                            esc24List.append(issue['key'])
                            break
                continue
            print "more than 48 hours"
            for customFields in issue['customFieldValues']:
                if customFields['customfieldId'] == 'customfield_10412':
                    if customFields['values'] == '48h':
                        print "not updating"
                        break
                    else:
                        print "updating !!!"
                        s.jira1.updateIssue(auth, issue['key'], {"customfield_10412": ["48h"]})
                        esc48List.append(issue['key'])
                        break
        
        for key in esc12List:
            email_issue(key,'12')
        for key in esc24List:
            email_issue(key,'24')
        for key in esc48List:
            email_issue(key,'48')
        

        此方法的主要优点是高度可自定义,并且通过将数据保存到自定义字段,可以轻松创建过滤器和报告以显示已存在很长时间的问题.

        The main pros of this method is that it's highly customizable, and by saving the data to custom fields it's easy to create filters and reports to show issues that have been opened for a long time.

        这篇关于吉拉问题提醒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆