Skip to content

Commit 8c9e2fc

Browse files
committed
v0.1.2
- added push support - checking necessary enviroment variables added - comments
1 parent 622dae0 commit 8c9e2fc

File tree

4 files changed

+44
-12
lines changed

4 files changed

+44
-12
lines changed

bot.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,16 @@ async def new_event():
99
if EVENT not in ['pull_request', 'push', 'release']:
1010
return
1111

12-
print(str(EVENT) == 'release')
13-
14-
if str(EVENT) in 'release':
12+
if EVENT == 'release':
1513
await event.new_release()
1614

17-
print(str(EVENT) == 'pull_request')
18-
19-
if str(EVENT) in 'pull_request':
15+
if EVENT == 'pull_request':
2016
await event.new_pull_request()
2117

22-
18+
if EVENT == 'push':
19+
await event.new_push()
2320

2421
if __name__ == '__main__':
25-
print(EVENT)
2622
executor.start(dp, new_event())
2723

2824

handlers/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
from handlers.release import *
22
from handlers.pull_request import *
3+
from handlers.push import *
4+

handlers/push.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from misc import bot
2+
from settings import CHAT_IDS, REPO, ACTOR, SHA, REF, PM
3+
4+
5+
async def new_push():
6+
emoji = '💡🍅🥑🥪🌭🍞☕🗽🍸🌎'[int(SHA, 16) % 10]
7+
msg_about = f"""
8+
🔀 NEW PUSH
9+
↪️ {REF}
10+
👨‍💻 {ACTOR}
11+
12+
#️⃣ [{SHA[:7]}](https://github.com/{REPO}/commit/{SHA}) {emoji}
13+
"""
14+
15+
for chat_id in CHAT_IDS:
16+
await bot.send_message(chat_id, msg_about, parse_mode=PM)

settings.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,50 @@
22
from aiogram.types import ParseMode
33
import os
44

5-
API_TOKEN = os.environ.get('secrets.WF_API_TOKEN')
6-
CHAT_IDS = os.environ.get('secrets.WF_CHAT_IDS').split()
5+
# Getting main environment variables
6+
API_TOKEN = os.environ.get('secrets.TG_API_TOKEN')
7+
CHAT_IDS = os.environ.get('secrets.TG_CHAT_IDS')
78

89
if not API_TOKEN:
9-
os.environ.get('secrets.TG_API_TOKEN')
10+
API_TOKEN = os.environ.get('secrets.WF_API_TOKEN')
1011

1112
if not CHAT_IDS:
12-
os.environ.get('secrets.TG_CHAT_IDS').split()
13+
CHAT_IDS = os.environ.get('secrets.WF_CHAT_IDS')
1314

1415

16+
# If main variables unset
17+
if not API_TOKEN:
18+
raise EnvironmentError(f"Environment variable secrets.API_TOKEN unset or empty: {API_TOKEN=}")
19+
if not CHAT_IDS:
20+
raise EnvironmentError(f"Environment variable secrets.CHAT_IDS unset or empty: {CHAT_IDS=}")
21+
22+
23+
# Getting secondary environment variables
24+
CHAT_IDS = CHAT_IDS.split()
1525
REPO = os.environ.get('GITHUB_REPOSITORY')
1626
ACTOR = os.environ.get('GITHUB_ACTOR')
1727
EVENT = os.environ.get('GITHUB_EVENT_NAME')
1828
REF = os.environ.get('GITHUB_REF')
1929
HEAD_REF = os.environ.get('GITHUB_HEAD_REF')
2030
BASE_REF = os.environ.get('GITHUB_BASE_REF')
31+
SHA = os.environ.get('GITHUB_SHA')
2132

33+
34+
# Logging results
2235
print(f"{REPO=}")
2336
print(f"{ACTOR=}")
2437
print(f"{EVENT=}")
2538
print(f"{REF=}")
2639
print(f"{HEAD_REF=}")
2740
print(f"{BASE_REF=}")
41+
print(f"{SHA=}")
42+
2843

44+
# Parser mode settings
2945
PM = ParseMode.MARKDOWN
3046

47+
48+
# Log settings
3149
LOG_FILE_NAME = "_bot.log"
3250
LOG_MODE = "DEBUG"
3351
MAX_LOG_FILE_SIZE = "10Mb"

0 commit comments

Comments
 (0)