From 845148fd2cb792211d2461daf2abc2679897b3f2 Mon Sep 17 00:00:00 2001
From: Pavel Vorobyov
Date: Wed, 15 Apr 2020 16:45:14 +0300
Subject: [PATCH] icqnotify
---
.gitlab-ci.yml | 4 ++--
Dockerfile | 5 +++++
icqnotify.py | 24 ++++++++++++++++++++++++
3 files changed, 31 insertions(+), 2 deletions(-)
create mode 100644 Dockerfile
create mode 100755 icqnotify.py
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 07bc834..97a377a 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -2,7 +2,7 @@ stages:
- build
- push
-image: golang:1.13
+image: registry-gitlab.corp.mail.ru/mntdev/xc
.build:
stage: build
@@ -30,7 +30,7 @@ push:
stage: push
script:
- filename=$(curl --upload-file ./xc-linux-amd64 https://t.bk.ru/xc)
- - echo $filename > release.txt
+ - icqnotify.py "a new release of XC is out:\n$filename"
artifacts:
name: release
paths:
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..89ac517
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,5 @@
+FROM golang:1.13
+RUN apt update
+RUN apt install -y python3 python3-pip
+RUN pip3 install mailru-im-bot
+ADD icqnotify.py /bin/icqnotify.py
diff --git a/icqnotify.py b/icqnotify.py
new file mode 100755
index 0000000..5fd862b
--- /dev/null
+++ b/icqnotify.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+import os
+import sys
+from bot.bot import Bot
+
+ICQ_TOKEN = os.environ.get("ICQ_TOKEN")
+ICQ_CHAT_ID = os.environ.get("ICQ_CHAT_ID")
+
+
+def send(message):
+ if not ICQ_TOKEN:
+ raise RuntimeError("No ICQ_TOKEN variable defined")
+ if not ICQ_CHAT_ID:
+ raise RuntimeError("No ICQ_CHAT_ID variable defined")
+ if not message:
+ raise ValueError("message is empty")
+
+ bot = Bot(token=ICQ_TOKEN)
+ bot.send_text(chat_id=ICQ_CHAT_ID, text=message)
+
+
+if __name__ == '__main__':
+ message = ' '.join(sys.argv[1:]).strip().replace("\\n", "\n")
+ send(message)
\ No newline at end of file