Skip to content

Instantly share code, notes, and snippets.

@chadknight-wf
Last active December 30, 2015 00:59
Show Gist options
  • Save chadknight-wf/7753571 to your computer and use it in GitHub Desktop.
Save chadknight-wf/7753571 to your computer and use it in GitHub Desktop.
transplate - Translate Dustin's JIRA template into my GitHub template
"""
.. script:: transplate.py
:synopsis:
Translate a JIRA-templated comment to a GitHub-flavored Markdown format.
Requires [pyperclip](http://coffeeghost.net/src/pyperclip.py),
Usage:
1. Copy JIRA comment to your system clipboard.
1. Run `transplate ABC-123`
1. Paste into GitHub textbox.
"""
# system imports
import re
import sys
# library imports
import pyperclip # http://coffeeghost.net/src/pyperclip.py
headings = (
'Issue',
'Solution',
'Testing Suggestions',
'Testing Notes',
'Code Review',
'Security Review',
'Smithy',
'Deploy',
'Unit Test',
'Automated Test',
'Automation Run',
)
def format_match(match):
return '\n## {}\n'.format(match.group(1).upper())
def replace_headers(text):
for heading in headings:
text = re.sub('({}):\n'.format(heading), format_match, text)
return text
def translate_template(in_text, ticket_number):
out_text = replace_headers(in_text)
try:
ticket_info = '## JIRA TICKET\nhttps://jira.atl.workiva.net/browse/{}\n\n'.format(ticket_number)
insert_pos = out_text.index('## CODE REVIEW')
out_text = out_text[:insert_pos] + ticket_info + out_text[insert_pos:]
except IndexError:
print 'Ticket number not given; clipboard output does not include JIRA link.'
return out_text
if __name__ == '__main__':
# expects to be called with ticket number as first argument
ticket_number = sys.argv[1].upper()
in_text = pyperclip.paste()
out_text = translate_template(in_text, ticket_number)
pyperclip.copy(out_text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment