Skip to content

Commit

Permalink
snapshot: Include hostname in commit message
Browse files Browse the repository at this point in the history
So that the Portal can show a description such as "@user's uncommitted
changes on {hostname}".
  • Loading branch information
drothlis committed Mar 7, 2024
1 parent 90cf449 commit c45d343
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
14 changes: 12 additions & 2 deletions stbt_rig.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import re
import shutil
import signal
import socket
import subprocess
import sys
import tempfile
Expand Down Expand Up @@ -1660,9 +1661,12 @@ def take_snapshot(self):
else:
extra_env = {}

commit_message = "snapshot\n\nremoteref: %s\nhostname: %s" % (
remoteref, _gethostname())

commit_sha = self._git(
['commit-tree', write_tree, '-p', base_commit, '-m',
"snapshot\n\nremoteref: %s" % remoteref],
['commit-tree', write_tree, '-p', base_commit,
'-m', commit_message],
extra_env=extra_env).strip()

if no_workingdir_changes:
Expand Down Expand Up @@ -1691,6 +1695,12 @@ def push_git_snapshot(self, branch, interactive=True):
return run_sha


def _gethostname():
if "CI" in os.environ:
return "CI"
return socket.gethostname()


@contextmanager
def flock(filename):
with open(filename, "a+b") as f:
Expand Down
7 changes: 5 additions & 2 deletions test_stbt_rig.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ def test_testpack_snapshot_no_change_if_no_commits(test_pack):
commit_sha, run_sha = test_pack.take_snapshot()
assert rev_parse("HEAD") == run_sha
assert tree_sha(commit_sha) == tree_sha(run_sha)
assert commit_msg(commit_sha) == (
"snapshot\n\nremoteref: refs/heads/mybranch")
assert commit_msg(commit_sha) == dedent("""\
snapshot
remoteref: refs/heads/mybranch
hostname: CI""")

# Check that the SHA is deterministic:
time.sleep(1)
Expand Down

0 comments on commit c45d343

Please sign in to comment.