Last active
May 15, 2017 14:18
-
-
Save winder/4bfecfb1471073b06eb0743f95ba251b to your computer and use it in GitHub Desktop.
This file contains 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
def validate_jira_id(jira_id, jira_username, jira_password): | |
""" Throw an exception if the jira_id is invalid. """ | |
request_url = JIRA_BASE_URL + '/rest/api/2/issue/' + jira_id | |
response = requests.get(request_url, auth=(jira_username, jira_password)) | |
if response.status_code == 404: | |
raise ValueError('Jira ticket not found.') | |
if response.status_code != 200: | |
raise ValueError('Unexpected status code during lookup: {}'.format(response.status_code)) | |
# parse response and check fields | |
issue_json = json.loads(response.text) | |
if issue_json['fields']['status']['name'] != 'Done': | |
message = "Invalid status, expected 'Done' found '{}'".format(issue_json['fields']['status']['name']) | |
raise ValueError(message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment