jira 邮件服务器 535,jira小工具与邮件发送

该博客介绍了一个使用Python实现的Jira自动化监控脚本,用于查询项目需求列表并检查项目的延期情况。如果发现延期,脚本会通过SMTP发送带有详细描述的邮件通知。主要涉及的技术包括Jira API、datetime模块、SMTP邮件发送等。
摘要由CSDN通过智能技术生成

代码示例

#!/usr/bin/python

# -*- coding: UTF-8 -*-

# coding:utf8

import requests

import datetime

import smtplib

from email.mime.text import MIMEText

from email.header import Header

class JiraTest(object):

# def __init__(self):

# pass

# 获取需求列表

def query_wf_project(param):

payload={

'jql': 'issuetype in (业务需求, 技术需求) AND 需求类型 = 项目 AND status not in (发布上线, Done, 不解决, 废弃) ORDER BY createdDate ASC',

'startAt': 0, 'expand': 'changelog'}

apiUrl = 'http://wf.vdian.net/rest/api/2/search'

r = requests.get(apiUrl, params=payload)

issues = r.json()["issues"]

total = r.json()["total"]

print(r.url)

return issues

def publish_delay(publistTime, testTime, created):

desc = ""

if testTime:

planTestTime = datetime.datetime.strptime(testTime, '%Y-%m-%d')

nowTimeStamp = datetime.datetime.now()

# 提测延期部分需要优化,跟状态流转记录比较

if nowTimeStamp > planTestTime:

desc = "提测延期" + str((nowTimeStamp - planTestTime).days) + "天;"

else:

desc = ""

else:

desc = "计划提测时间未填写;"

if publistTime:

planTimeStamp = datetime.datetime.strptime(publistTime, '%Y-%m-%d') #由字符串转为日期型的函数为:datetime.datetime.strptime()

nowTimeStamp = datetime.datetime.now()

# print(planTimeStamp)

# print(nowTimeStamp)

if nowTimeStamp > planTimeStamp:

desc = desc + "发布延期" + str((nowTimeStamp - planTimeStamp).days) + "天;"

else:

desc = desc + ""

else:

desc = desc + "计划发布时间未填写;"

##项目时间超过2个月

nowTimeStamp = datetime.datetime.now()

createdStamp = datetime.datetime.strptime(created, '%Y-%m-%d')

if (nowTimeStamp - createdStamp).days > 60:

desc = desc + "项目创建时间超过2个月;"

if desc.strip() == "":

return "项目进度正常"

return desc

# 发送邮件

def send_notify(email, key, title, res, subject):

# 第三方 SMTP 服务

mail_host = 'smtp.126.com' # 设置服务器

mail_user = '[email protected]' # 用户名

mail_pass ='126password' # 126邮箱对应的口令

sender = '[email protected]'

receivers = '[email protected]' # 接收邮件,可设置为你的QQ邮箱或者其他邮箱

mail_msg=''

mail_msg = mail_msg.replace("TEST-412", key)

mail_msg = mail_msg.replace("标题", title)

mail_msg = mail_msg.replace("项目描述", res)

message = MIMEText(mail_msg, 'html', 'utf-8')

message['From'] = '[email protected]'

message['to'] = '[email protected]'

message['Subject'] = Header(subject, 'utf-8')

smtpObj = smtplib.SMTP()

smtpObj.connect(mail_host) # 25 为 SMTP 端口号

smtpObj.login(mail_user, mail_pass)

smtpObj.sendmail(sender, receivers, message.as_string())

smtpObj.quit()

print('邮件发送成功')

issues=query_wf_project(0)

for issue in issues:

#url

url = "http://wf.vdian.net/browse/"+(issue["key"])

#标题

title = (issue["fields"]["summary"])

#报告人

reporter = (issue["fields"]["reporter"]["displayName"])

#创建日期

created = issue["fields"]["created"][0:10]

#产品

project = (issue["fields"]["project"]["name"])

#产品线

projectCategory = (issue["fields"]["project"]["projectCategory"]["name"])

#计划提测时间

testPlanTime = (issue["fields"]["customfield_10200"])

#计划上线时间

publistPlanTime = (issue["fields"]["customfield_10109"])

#进度

status = (issue["fields"]["status"]["name"])

#经办人

assignee = (issue["fields"]["assignee"]["displayName"])

#测试人员

if issue["fields"]["customfield_10108"]:

tester = (issue["fields"]["customfield_10108"][0]["displayName"])

else:

tester = ("无测试人员")

delay = publish_delay(publistPlanTime, testPlanTime, created)

print('延期信息打印',delay)

send_notify('[email protected]', 'WDAPP-8503', 'title', 'desc', 'subject')

原文:https://www.cnblogs.com/niuniumother/p/11287767.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值