-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpush_changes.py
More file actions
executable file
·57 lines (50 loc) · 2.84 KB
/
push_changes.py
File metadata and controls
executable file
·57 lines (50 loc) · 2.84 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import annotations
from git.repo.base import Repo
import os
import shutil
import subprocess
CURRENT_DIR=os.path.dirname(os.path.realpath(__file__))
GIT_DIR=os.path.dirname(os.path.realpath(__file__))+"/git/"
SCRIPTS_DIR=os.path.dirname(os.path.realpath(__file__))+"/scripts/"
GENTOO_REPO_DIR=os.path.dirname(os.path.realpath(__file__))+"/gentoo_repository/"
LINUX_PATCHES_REPO_DIR=os.path.dirname(os.path.realpath(__file__))+"/linux-patches/"
IRC_DIR=os.path.dirname(os.path.realpath(__file__))+"/irc_bot/"
def check_git_push():
# run the git push command with the --dry-run option
process = subprocess.Popen(["git", "push", "--dry-run"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, error = process.communicate()
# check if there are any commits that need to be pushed
if "Everything up-to-date" in error.decode("utf-8"):
os.system('echo "No changes to push" > ' + IRC_DIR + '/irc.libera.chat/\#astat/in')
os.system('echo "'+ output.decode("utf-8").strip() +'" > ' + IRC_DIR + '/irc.libera.chat/\#astat/in')
os.system('echo "'+ error.decode("utf-8").strip() +'" > ' + IRC_DIR + '/irc.libera.chat/\#astat/in')
print("Nothing to push!")
return True
else:
os.system('echo "The following commits need to be pushed:" > ' + IRC_DIR + '/irc.libera.chat/\#astat/in')
os.system('echo "'+ output.decode("utf-8").strip() +'" > ' + IRC_DIR + '/irc.libera.chat/\#astat/in')
os.system('echo "'+ error.decode("utf-8").strip() +'" > ' + IRC_DIR + '/irc.libera.chat/\#astat/in')
# run the git push command
process = subprocess.Popen(["pkgdev", "push", "--pull"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, error = process.communicate()
# check if the command was successful
if process.returncode == 0:
print("Git push was successful!")
os.system('echo "'+ output.decode("utf-8").strip() +'" > ' + IRC_DIR + '/irc.libera.chat/\#astat/in')
os.system('echo "'+ error.decode("utf-8").strip() +'" > ' + IRC_DIR + '/irc.libera.chat/\#astat/in')
os.system('echo "pushed changes" > ' + IRC_DIR + '/irc.libera.chat/\#astat/in')
return True
else:
print("Error occurred during git push:")
print(error.decode("utf-8").strip())
os.system('echo "'+ output.decode("utf-8").strip() +'" > ' + IRC_DIR + '/irc.libera.chat/\#astat/in')
os.system('echo "'+ error.decode("utf-8").strip() +'" > ' + IRC_DIR + '/irc.libera.chat/\#astat/in')
os.system('echo "ERROR on pushing changes" > ' + IRC_DIR + '/irc.libera.chat/\#astat/in')
return False
# copy git configurations to gentoo repository
shutil.copyfile(GIT_DIR+'/gentoo_repository_config',GENTOO_REPO_DIR+"/.git/config")
os.chdir(GENTOO_REPO_DIR)
# send changes
check_git_push()