Last active
March 6, 2018 15:08
-
-
Save perfecto25/c69f6ee09dfeccb6c0a4e73a36a8ad35 to your computer and use it in GitHub Desktop.
k15 Jira backbone sync status search
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
| #!/usr/bin/env python | |
| # coding=utf-8 | |
| # searches an issue on Jira server for k15 Backbone Sync properties | |
| # 1. update Jira connection + project info below | |
| # 2. add issue range to search, either single issue or a range | |
| from __future__ import print_function | |
| from __future__ import unicode_literals | |
| import urllib2 | |
| import base64 | |
| import sys | |
| import ssl | |
| import json | |
| jira_server = "https://jira.instance.local" | |
| jira_user = "user.name" | |
| jira_pw = "spaceballs" | |
| project = "PROJ" | |
| # Range of Issues to search through | |
| # if searching for PROJ-1 through PROJ-66, use issue_range = "1-66" | |
| # if searching 1 ticket, PROJ-35, use issue_range = "35" | |
| issue_range = "1-1300" | |
| #------------------------------------------------------ | |
| def curl(url): | |
| ''' makes a GET request to a specificed URL ''' | |
| request = urllib2.Request(url) | |
| creds = base64.encodestring('%s:%s' % (jira_user, jira_pw)).replace('\n', '') | |
| request.add_header("Authorization", "Basic %s" % creds) | |
| response = urllib2.urlopen(request, context=ssl._create_unverified_context()) | |
| return json.load(response) | |
| #------------------------------------------------------ | |
| def get_backbone_info(start, end): | |
| ''' parses a Jira issue or a range of issues and gets Backbone data ''' | |
| for i in range(start, end): | |
| issue = project + '-' + str(i) | |
| url = jira_server + '/rest/api/2/issue/' + issue + '/properties' | |
| # get issue JSON, skip to next issue, if current issue doesnt exist | |
| try: | |
| data = curl(url) | |
| except urllib2.HTTPError, err: | |
| continue | |
| # check if Issue Property key exists | |
| try: | |
| data['keys'][0] | |
| except (KeyError, ValueError, IndexError, TypeError): | |
| continue | |
| # get URL for k15 Backbone Sync issue property | |
| try: | |
| issue_property_url = data['keys'][0]['self'] | |
| except IndexError as e: | |
| print('\n[ERROR] no issue property data for %s' % issue) | |
| continue | |
| # get all Backbone Sync information for this ticket | |
| try: | |
| data = curl(issue_property_url) | |
| except urllib2.HTTPError, err: | |
| continue | |
| # if issue property is not related to Backbone Sync, skip | |
| try: | |
| data['value']['sendStatus'] | |
| except (KeyError, ValueError, IndexError, TypeError): | |
| continue | |
| print(' >> ' + issue + ': sendStatus ' + str(data['value']['sendStatus']) + \ | |
| ', receiveStatus ' + str(data['value']['receiveStatus']) + \ | |
| ', localIssueKey ' + str(data['value']['localIssueKey']) + \ | |
| ', remoteIssueKey ' + str(data['value']['remoteIssueKey'])) | |
| #------------------------------------------------------ | |
| if __name__ == "__main__": | |
| ''' search Jira tickets for k15 Backbone Sync information ''' | |
| issue = [int(x) for x in issue_range.split('-')] | |
| try: | |
| # if 1 Jira issue | |
| if len(issue) < 2: | |
| print(get_backbone_info(issue[0], issue[0]+1)) | |
| # if multiple Jira issues | |
| else: | |
| print(get_backbone_info(issue[0], issue[1]+1)) | |
| except Exception as exc: | |
| print('[ERROR] %s ' % exc) | |
| finally: | |
| print('-------RUN COMPLETE-------') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment