-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_android_comment.py
62 lines (50 loc) · 1.56 KB
/
build_android_comment.py
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
#!python3
# -*- coding: utf-8 -*-
import os
import json
from common import retrieve_commits, group_by_issue
AUTHOR_NAME = 'CI_AUTHOR_NAME'
REPO_URL = 'CI_REPO_URL'
CUR_COMMIT = 'CI_COMMIT_SHA'
NUM_COMMITS = 'CI_NUM_COMMITS'
BRANCH_NAME = 'CI_COMMIT_REF_NAME'
PROJECT_NAME = 'CI_PROJECT_NAME'
PROJECT_DIR = 'CI_PROJECT_DIR'
JIRA_TICKET_ID = 'CI_JIRA_TICKET_ID'
ANDROID_URL = 'CI_ANDROID_URL'
ANDROID_QRCODE = 'CI_ANDROID_QRCODE'
def convert_to_comment(author_name, project_name, repo_url, branch_name,
android_url, android_qrcode):
return (f"(flag) *{author_name}* prepared an "
f"[*Android* test build|{android_url}] "
f"for [*{project_name}*|{repo_url}] "
f"on branch *{branch_name}*:\n\n"
f"!{android_qrcode}|width=100!")
def create_jira_comments():
env = os.environ
if env[JIRA_TICKET_ID]:
affected_issues = [env[JIRA_TICKET_ID]]
else:
all_commits = retrieve_commits(
env[PROJECT_DIR],
'HEAD~' + env[NUM_COMMITS],
env[CUR_COMMIT])
affected_issues = group_by_issue(all_commits).keys()
comment = convert_to_comment(
env[AUTHOR_NAME],
env[PROJECT_NAME],
env[REPO_URL],
env[BRANCH_NAME],
env[ANDROID_URL],
env[ANDROID_QRCODE],
)
return {
issue: {
"comment": comment,
"attachments": [env[ANDROID_QRCODE]],
} for issue in affected_issues
}
def main():
print(json.dumps(create_jira_comments()))
if __name__ == '__main__':
main()