-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
94 lines (87 loc) · 4.25 KB
/
Jenkinsfile
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
pipeline {
agent any
triggers {
cron('H 1 * * *')
}
environment {
translate = '翻译'
original = '原创'
}
stages {
stage('notify') {
steps {
script {
genFile()
today = readFile('today').trim()
echo "today: ${today}"
tomorrow = readFile('tomorrow').trim()
echo "tomorrow: ${tomorrow}"
props = readJSON file: 'needReviewData.json'
echo "props: ${props}"
sh "pwd"
sh "ls -ahl |grep .json"
approveData = readJSON file: 'needMergeData.json'
echo "approveData: ${approveData}"
defaultValue = 0
content = ""
appValue = 0
contentData = ""
echo "props.total_count: ${props.total_count}"
if(props.total_count != 0){
for(i=0; i< props.items.size(); i++ ){
if((props.items[i].title.contains(env.translate) && props.items[i].title.contains(today)) || (props.items[i].title.contains(env.translate) && props.items[i].title.contains(tomorrow)) || (props.items[i].title.contains(env.original) && props.items[i].title.contains(today)) || (props.items[i].title.contains(env.original) && props.items[i].title.contains(tomorrow))) {
content += "${props.items[i].html_url} \n"
defaultValue++
}
}
}
echo "content: ${content}"
echo "approveData.total_count: ${approveData.total_count}"
if(approveData.total_count !=0){
for(i=0; i< approveData.items.size(); i++ ){
if((approveData.items[i].title.contains(env.translate) && approveData.items[i].title.contains(today)) || (approveData.items[i].title.contains(env.original) && approveData.items[i].title.contains(today)) ) {
contentData += "${approveData.items[i].html_url} \n"
appValue++
}
}
}
echo "contentData: ${contentData}"
sendEmail(defaultValue,content,today,appValue,contentData)
}
}
}
}
}
def genFile(){
sh "date +%Y-%m-%d > today"
sh "date +%Y-%m-%d --date='1 day' > tomorrow" //mac is `date -v +1d +%Y-%m-%d`
sh 'curl -s https://api.github.com/search/issues?q=repo:jenkins-zh/jenkins-zh+type:pr+is:open+team-review-requested:social-media-admin+review:none > needReviewData.json'
sh 'curl -s https://api.github.com/search/issues?q=repo:jenkins-zh/jenkins-zh+type:pr+is:open+team-review-requested:social-media-admin+review:approved > needMergeData.json'
}
def sendEmail(int defaultValue,String content,String today,int appValue,String contentData){
if(defaultValue != 0 && appValue != 0) {
mail bcc: '',
body: "共有${defaultValue}篇文章需要review,链接如下:\n${content}\n共有${appValue}篇文章需要merge,链接如下:\n${contentData}",
cc: '',
from: '[email protected]',
replyTo: '[email protected]',
subject: "jenkins-zh(${today})文章merge/review提醒",
to: '[email protected]'
} else if (defaultValue != 0) {
mail bcc: '',
body: "共有${defaultValue}篇文章需要review,链接如下:\n${content}",
cc: '',
from: '[email protected]',
replyTo: '[email protected]',
subject: "jenkins-zh(${today})文章merge/review提醒",
to: '[email protected]'
} else if (appValue != 0) {
mail bcc: '',
body: "共有${appValue}篇文章需要merge,链接如下:\n${contentData}",
cc: '',
from: '[email protected]',
replyTo: '[email protected]',
subject: "jenkins-zh(${today})文章merge/review提醒",
to: '[email protected]'
}
}