Last active
March 6, 2018 19:41
-
-
Save rnwolf/418f3223225d823f084dbb75af44940a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from jira.client import JIRA | |
import argparse | |
import os | |
""" | |
In a Virtual Python Environment with jira package installed, | |
You can create subtasks for a given Jira Issue, based on a tab delimited file containing subtask details. | |
Environment variables for the Jira connections need to be set. | |
python createcppjirasubtasks.py --subtasks subtasks.tsv GPE-3238 | |
""" | |
""" | |
# Save this as subtasks.tsv | |
# Comments are prefixed by hash # | |
# Valid subtask rows contain two columns TAB separated. | |
# First column: Summary | |
# Second column: description | |
Kick-off Make sure Story Kick-off task is created against every user story (functional/ non-functional) | |
Dev and BA review Ensure story Kick-off task is played along with at least the developer assigned to the story/ task and a Business analyst | |
Unit and Integration Tests created or updated Every code change should have unit tests, integration tests and they should confirm to the platform requirements (for ex: at least 80% code coverage etc.) | |
API test created or updated Any cross-context code change should include API tests written to make sure code doesn't break other contexts | |
E2E and API test pass locally Any code change that has a contract change should also ensure neither API tests nor e2e tests will break as a result of the change. Did you run the e2e case creation, API tests locally? | |
Sonar tests pass Did Sonar review pass? | |
Exploratory testing done Did you do exploratory testing to play around with the new functionality so to be sure that regression features are not broken | |
Accessibility testing done Accessibility review and did you run Pa11y task on ui.app and that pass? | |
UI.App test pass Did you run test task on ui.app and that pass? Deploy this specific context where the change is made or just deploy ui.app (if its FE change) on a team specific test server and make sure API tests and e2e tests pass | |
Attached test evidence to ticket Have you seen and test evidence such as e2e test report, pa11y report, sonar report, test coverage report and everything is satisfactory? | |
POM version updated Make sure every change contains a new pom version so its reversible quickly without much impact to the pipeline and other teams | |
""" | |
def create_argument_parser(): | |
parser = argparse.ArgumentParser(description='Add CPP subtasks to Jira Issue. Assumes that Jira connections vars are loaded into ENV vars.') | |
parser.add_argument('issue', metavar='issue', help='Jira issue ID in format JIRA-12345') | |
parser.add_argument('--project', metavar='GPE', help='Jira Project that the sub-tasks should be created in. Could be different to the parent') | |
parser.add_argument('--subtasks', metavar='subtasks.tsv', default='subtasks.tsv', help='CSV Text file in which each non-comment row contains comma delimited summary and description values.') | |
return parser | |
def processline(line): | |
if line.startswith('#'): | |
return ('', '') | |
else: | |
summary, description = line.split('\t') | |
if summary is None: | |
return ('', '') | |
if description is None: | |
return (summary, '') | |
return (summary, description) | |
def main(): | |
parser = create_argument_parser() | |
args = parser.parse_args() | |
if args.issue is not None: | |
issue = args.issue | |
else: | |
print("No issue input!") | |
return 1 | |
if args.project is None: | |
project=issue.split('-')[0] # Assume Project is based on issue number | |
else: | |
project = args.project | |
subtasks = [] | |
if args.subtasks is not None: | |
with open(args.subtasks) as f: | |
for line in f: | |
summary,description = processline(line) | |
if len(summary)>1: | |
subtask = { | |
'project' : { 'key' : project }, | |
'summary' : summary, | |
'description': description, | |
'issuetype' : { 'name' : 'Sub-task' }, | |
'parent' : { 'id' : issue}, | |
} | |
subtasks.append(subtask) | |
try: | |
USERNAME = os.environ['JIRA_USERNAME'] | |
USER_PASSWORD = os.environ['JIRA_PASSWORD'] | |
SERVER_URL = os.environ['JIRA_DOMAIN'] | |
except KeyError as err: | |
print('Environment variables for JIRA not present: {0}'.format(err)) | |
return 1 | |
if len(USERNAME)<=1 : | |
raise ValueError('Environment JIRA_USERNAME not set.') | |
if len(USER_PASSWORD)<=1 : | |
raise ValueError('Environment JIRA_PASSWORD not set.') | |
if len(SERVER_URL)<=1 : | |
raise ValueError('Environment JIRA_DOMAIN not set.') | |
# Connect to JIRA | |
jira = JIRA(options={'server': SERVER_URL , 'verify': True}, basic_auth=(USERNAME, USER_PASSWORD)) | |
print('Getting data from Jira.. this could take a while!') | |
if len(issue) > 0 and len(issue) <= 10: # Basic validation | |
print(issue+" issue validated") | |
for task in subtasks: | |
child = jira.create_issue(fields=task) | |
print("created child subtask: " + child.key +" "+task['summary']) | |
elif len(issue) == 0: | |
print("the input was empty") | |
else: | |
print("The following input was not valid" + issue) | |
return 1 | |
return 0 | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment