Skip to content

Instantly share code, notes, and snippets.

@john-kurkowski
Created October 25, 2015 20:15
Show Gist options
  • Save john-kurkowski/2e6b6fcf17b5d57ce9a9 to your computer and use it in GitHub Desktop.
Save john-kurkowski/2e6b6fcf17b5d57ce9a9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
'''Convert tags with no leading "v" to NPM's default tag format.'''
import re
import subprocess
OLD_TAG_RE = re.compile(r'^\d+\.\d+')
def tag2npmtag(tag):
dot_count = tag.count('.')
if dot_count == 1:
new_tag = 'v{}.0'.format(tag)
else:
new_tag = 'v{}'.format(tag)
git_show_cmd = ('git', 'show', '-s', '--pretty=format:%ci%n%H')
git_show = subprocess.check_output(git_show_cmd + (tag,)).splitlines()
annotation = git_show[3:-2]
date = git_show[-2]
ref = git_show[-1]
git_tag_cmd = ('git', 'tag', '-f', new_tag, ref, '-m', '\n'.join(annotation))
env = {
'GIT_COMMITTER_DATE': date,
}
subprocess.check_call(git_tag_cmd, env=env)
def main():
all_tags = subprocess.check_output(('git', 'tag')).splitlines()
old_tags = [line for line in all_tags if OLD_TAG_RE.match(line)]
for old_tag in old_tags:
tag2npmtag(old_tag)
if __name__ == '__main__':
main()
# vi:syntax=python
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment