-
Notifications
You must be signed in to change notification settings - Fork 0
/
upstream.py
33 lines (29 loc) · 1.13 KB
/
upstream.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
from logging import error as log_error, info as log_info
from os import path as ospath, environ,
from subprocess import run as srun
UPSTREAM_REPO = environ.get('UPSTREAM_REPO')
UPSTREAM_BRANCH = environ.get('UPSTREAM_BRANCH')
try:
if len(UPSTREAM_REPO) == 0:
raise TypeError
except:
UPSTREAM_REPO = "https://github.com/anasty17/mirror-leech-telegram-bot"
try:
if len(UPSTREAM_BRANCH) == 0:
raise TypeError
except:
UPSTREAM_BRANCH = 'main'
if ospath.exists('.git'):
srun(["rm", "-rf", ".git"])
update = srun([f"git init -q \
&& git config --global user.email [email protected] \
&& git config --global user.name frozen12 \
&& git add . \
&& git commit -sm update -q \
&& git remote add origin {UPSTREAM_REPO} \
&& git fetch origin -q \
&& git reset --hard origin/{UPSTREAM_BRANCH} -q"], shell=True)
if update.returncode == 0:
log_info('Successfully updated with latest commit from UPSTREAM_REPO')
else:
log_error('Something went wrong while updating, check UPSTREAM_REPO if valid or not!')