Skip to content

Instantly share code, notes, and snippets.

@bobby285271
Last active June 14, 2024 01:59
Show Gist options
  • Save bobby285271/9264b4b14bcb9eff58e3f190521dc564 to your computer and use it in GitHub Desktop.
Save bobby285271/9264b4b14bcb9eff58e3f190521dc564 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import os
import git
import re
import sys
import subprocess
sha = sys.argv[1]
pattern = r'(.*): (.*) -> (.*)'
nixpkgs = os.path.join(os.environ['HOME'], 'nixpkgs')
repo = git.Repo(nixpkgs)
repo.git.add(all=True)
commit = repo.commit(sha)
message = commit.message
msg_first_line = message.splitlines()[0]
msg_https_line = ''
for line in message.splitlines():
if line.startswith('https'):
msg_https_line = line
break
result = re.search(pattern, message.splitlines()[0])
pkg_attr = result.group(1)
org_from = result.group(2)
org_to = result.group(3)
new_to = subprocess.run(['nix', 'eval', f'{nixpkgs}#{pkg_attr}.version', '--raw'], stdout=subprocess.PIPE).stdout.decode()
print(new_to)
msg_https_line = msg_https_line.replace(f'{org_from}...{org_to}',f'{org_from}...{new_to}')
commit_message = f"""amend! {msg_first_line}
{pkg_attr}: {org_from} -> {new_to}
{msg_https_line}"""
index = repo.index
index.commit(commit_message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment