Created
April 13, 2020 07:10
-
-
Save smd877/b9ddbc47160348755af6cccd2b3d03e8 to your computer and use it in GitHub Desktop.
Backlogのチケット更新状況から、前日以降更新されて自社メンバーが担当になっているものをメールで通知する。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding: UTF-8 | |
import os | |
import json | |
import boto3 | |
import urllib.request, urllib.parse | |
from datetime import date, timedelta | |
SPACE_URL = os.environ['SPACE_URL'] | |
API_URL = SPACE_URL + '/api/v2/issues?apiKey=' + os.environ['API_KEY'] | |
STATUS_FINISH = 4 | |
MEMBERS = [int(tmp) for tmp in os.environ['MEMBERS'].split(',')] | |
def lambda_handler(event, context): | |
body = get_body() | |
send_data(body) | |
def get_body(): | |
# 日付の絞り込み 前日以降を対象とし、更新日時の昇順で取得する | |
dateFrom = date.today() - timedelta(1) | |
data = { | |
'updatedSince' : dateFrom.strftime('%Y-%m-%d'), | |
'sort' : 'updated', | |
'order' : 'asc' | |
} | |
req = urllib.request.Request(API_URL,data=urllib.parse.urlencode(data).encode("utf-8"),method='GET') | |
res = urllib.request.urlopen(req) | |
content = json.loads(res.read().decode('utf-8')) | |
messages = [] | |
for row in content: | |
# 完了は除外 | |
if row['status']['id'] == STATUS_FINISH: | |
continue | |
# 担当が自社メンバー以外は除外 | |
if row['assignee']['id'] not in MEMBERS: | |
continue | |
# メッセージに追記する | |
messages.append('サマリ : {}'.format(row['summary'])) | |
messages.append('URL : {}{}{}'.format(SPACE_URL, '/view/', row['issueKey'])) | |
messages.append('更新日 : {}'.format(row['updated'])) | |
messages.append('更新者 : {}'.format(row['updatedUser']['name'])) | |
messages.append('担当者 : {}'.format(row['assignee']['name'])) | |
messages.append('----') | |
return '\n'.join(messages) | |
def send_data(body): | |
subject = '日次報告 BackLog対応漏れがないかチェック' | |
# チェックした内容をメールを使って送信する | |
to_addr = os.environ['TO_ADDR'] | |
msg = { | |
'to_addr' : to_addr, | |
'subject' : subject, | |
'body' : body | |
} | |
# メール送信処理自体は別のlambdaで実行 | |
boto3.client('lambda').invoke( | |
FunctionName='sendMailSes', | |
InvocationType='RequestResponse', | |
Payload=json.dumps(msg) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment