Created
May 14, 2016 19:48
-
-
Save PJB3005/879da17a122d60c08ca5924758ec0851 to your computer and use it in GitHub Desktop.
SS13 changelog bot for /vg/station
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Ran through https://github.com/carlos-jenkins/python-github-webhooks | |
# Uses gitpython | |
import sys, os, os.path, json, re, time | |
from git import Repo | |
starttime = int(time.time()) | |
print starttime | |
with open("time.txt", "w+") as timefile: | |
timefile.write(str(starttime)) | |
time.sleep(30) | |
with open("time.txt", "r") as timefile: | |
filetime = int(float(timefile.read())) | |
print filetime | |
if filetime != starttime: | |
timefile.close() | |
quit() | |
repo_path = "[REPO PATH]" | |
ssh_cmd = 'ssh -i [SSH KEY FILE]' | |
repo = Repo(repo_path) | |
git = repo.git | |
with repo.git.custom_environment(GIT_SSH_COMMAND=ssh_cmd): | |
repo.remotes.origin.pull() | |
# Use GitHub's JSON to check if any changelog files were modified. | |
with open(sys.argv[1], 'r') as jsf: | |
payload = json.loads(jsf.read()) | |
commits = payload.get('commits') | |
found = False | |
for commit in commits: | |
if found: | |
break | |
for filename in commit.get("added") + commit.get("modified"): # No need to check removed files. | |
if re.match("html\/changelogs\/[^.].*\.yml", filename): | |
found = True | |
break | |
if not found: | |
sys.exit() | |
os.system("python %s/tools/ss13_genchangelog.py %s/html/changelog.html %s/html/changelogs" % (repo_path, repo_path, repo_path)) | |
if repo.is_dirty(): | |
git.add(".", "-A") | |
git.commit("-m", "Automatic changelog update.") | |
with repo.git.custom_environment(GIT_SSH_COMMAND=ssh_cmd): | |
repo.remotes.origin.push() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment