Skip to content

Commit

Permalink
Replace sp.Popen with sp.check_output --autopull
Browse files Browse the repository at this point in the history
  • Loading branch information
iBug committed Aug 2, 2018
1 parent aabaa8a commit 59e507e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
17 changes: 9 additions & 8 deletions globalvars.py
Expand Up @@ -16,18 +16,19 @@


def git_commit_info():
data = sp.Popen(['git', 'log', '-1', '--pretty=%h%n%H%n%an%n%s'], stdout=sp.PIPE, stderr=sp.PIPE).communicate()
if data[1]:
raise OSError("Git error:\n" + data[1].decode('utf-8'))
short_id, full_id, author, message = data[0].decode('utf-8').strip().split("\n")
try:
data = sp.check_output(['git', 'log', '-1', '--pretty=%h%n%H%n%an%n%s'], stderr=sp.STDOUT, encoding='utf-8')
except sp.CalledProcessError as e:
raise OSError("Git error:\n" + e.output) from e
short_id, full_id, author, message = data.strip().split("\n")
return {'id': short_id, 'id_full': full_id, 'author': author, 'message': message}


def git_status():
data = sp.Popen(['git', 'status'], stdout=sp.PIPE, stderr=sp.PIPE).communicate()
if data[1]:
raise OSError("Git error:\n" + data[1].decode('utf-8'))
return data[0].decode('utf-8').strip('\n')
try:
return sp.check_output(['git', 'status'], stderr=sp.STDOUT, encoding='utf-8').strip()
except sp.CalledProcessError as e:
raise OSError("Git error:\n" + e.output) from e


# This is needed later on for properly 'stripping' unicode weirdness out of git log data.
Expand Down
4 changes: 2 additions & 2 deletions metasmoke.py
Expand Up @@ -140,7 +140,7 @@ def handle_websocket_data(data):
why=why)
elif "deploy_updated" in message:
sha = message["deploy_updated"]["head_commit"]["id"]
if sha != os.popen('git log --pretty=format:"%H" -n 1').read():
if sha != os.popen('git log -1 --pretty="%H"').read():
if "autopull" in message["deploy_updated"]["head_commit"]["message"]:
if only_blacklists_changed(GitManager.get_remote_diff()):
commit_md = "[`{0}`](https://github.com/Charcoal-SE/SmokeDetector/commit/{0})" \
Expand Down Expand Up @@ -173,7 +173,7 @@ def handle_websocket_data(data):
elif "commit_status" in message:
c = message["commit_status"]
sha = c["commit_sha"][:7]
if c["commit_sha"] != os.popen('git log --pretty=format:"%H" -n 1').read():
if c["commit_sha"] != os.popen('git log -1 --pretty="%H"').read():
if c["status"] == "success":
if "autopull" in c["commit_message"]:
s = "[CI]({ci_link}) on [`{commit_sha}`](https://github.com/Charcoal-SE/SmokeDetector/" \
Expand Down

0 comments on commit 59e507e

Please sign in to comment.