-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommit-bell.py
54 lines (42 loc) · 1.62 KB
/
commit-bell.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
from slacker import Slacker
import github3
import datetime
import pytz
import os
from apscheduler.schedulers.blocking import BlockingScheduler
sched = BlockingScheduler()
local_tz = pytz.timezone('Asia/Seoul')
token = os.environ.get('SLACK_BOT_COMMIT_BELL_TOKEN')
slack = Slacker(token)
channels = ['#study_unity', '#bot_test']
def post_to_channel(message):
slack.chat.post_message(channels[0], message, as_user=True)
def get_repo_last_commit_delta_time(owner, repo):
repo = github3.repository(owner, repo)
return repo.pushed_at.astimezone(local_tz)
def get_delta_time(last_commit):
now = datetime.datetime.now(local_tz)
delta = now - last_commit
return delta.days
@sched.scheduled_job('cron', day_of_week='mon-sun', hour=14)
def main():
members = (
('eunsooJeon', 'unity', '전은수'),
('net9keep', 'unity', '함태영'),
('Oeno', 'tcpBird', '이송열'),
('janpro0706', 'tcp-unity-study', '장현동'),
('mommy79', 'TCP_Unity', '서바울'),
('KUvH', 'tcp_study_unity', '김현욱')
)
reports = []
for owner, repo, name in members:
last_commit = get_repo_last_commit_delta_time(owner, repo)
delta_time = get_delta_time(last_commit)
if(delta_time == 0):
reports.append('*%s* 님은 오늘 커밋을 하셨어요!' % (name))
else:
reports.append('*%s* 님은 *%s* 일이나 커밋을 안하셨어요!' % (name, delta_time))
post_to_channel('\n 안녕 친구들! <!here> 과제 점검하는 커밋벨이에요 호호 \n' + '\n'.join(reports))
sched.start()
# if __name__ == '__main__':
# main()