-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·77 lines (67 loc) · 2 KB
/
main.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python3
import slackmessage
import bitbucketmonitor
import json
import sys
import schedule
import time
import os
def main():
# get configuration parameters from config.json
workspaces = []
channel = ""
jobTime = ""
isEnvConfigPresent = os.environ.get("BITBUCKET_WORKSPACES") and os.environ.get("SLACK_CHANNEL") and os.environ.get("POST_TIME")
# Get config from environment vars or config.json
if isEnvConfigPresent:
workspaces = os.environ.get("BITBUCKET_WORKSPACES").split(",")
channel = os.environ.get("SLACK_CHANNEL")
jobTime = os.environ.get("POST_TIME")
else:
try:
f = open("config.json")
configText = f.read()
configJson = json.loads(configText)
workspaces = configJson['bitbucket_workspaces']
channel = configJson['slack_channel']
jobTime = configJson['post_time']
finally:
f.close()
if (len(workspaces) == 0) or (channel == "") or (jobTime == ""):
sys.exit(1)
# set up the scheduler
schedule.every().day.at(jobTime).do(jobIteration, workspaces, channel)
# loop endlessly
while True:
schedule.run_pending()
time.sleep(60)
def jobIteration(workspaces, channel):
x = monitorPass(workspaces)
y = generateMarkdownMessages(x)
z = slackmessage.SlackMessage()
z.sendBitbucketMarkdownBlock(channel, y)
def monitorPass(workspaces):
# support multiple bitbucket workspaces if necessary
monitors = []
results = []
# Let's make a BitBucketMonitor for each workspace
for i in workspaces:
x = bitbucketmonitor.BitBucketMonitor(i)
monitors.append(x)
# Now let's run each monitor
for i in monitors:
i.unrespondedCommentsPipeline()
i.preparePullRequestListForOutput()
x = i.getFinalPullRequestList()
for j in x:
results.append(j)
# return the monitor results
return results
def generateMarkdownMessages(monitorresults):
markdownStrings = []
for i in monitorresults:
markdownStrings.append("<{0}|{1} has {2} unanswered comments(s) in BitBucket.>".format(i[0], i[2], i[3]))
return markdownStrings
if __name__ == "__main__":
main()
sys.exit(0)