mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-23 06:31:18 +02:00
tracker/spreadsheet tool: Improve tracker to spreadsheet migration.
Migrate only issues that are open or that are already in the spreadsheet. This way, the spreadsheet doesn't get cluttered w/ closed tasks. Review URL: http://codereview.chromium.org/1734001
This commit is contained in:
parent
fb78b42940
commit
ba9af725d1
@ -28,19 +28,20 @@ import atom.core
|
|||||||
import getpass
|
import getpass
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
import pickle
|
import pickle
|
||||||
|
from sets import Set
|
||||||
|
|
||||||
# Settings
|
# Settings
|
||||||
credentials_store = 'creds.dat'
|
credentials_store = 'creds.dat'
|
||||||
|
|
||||||
class Merger(object):
|
class Merger(object):
|
||||||
def __init__(self, ss_key, ss_ws_key, tracker_message, tracker_project,
|
def __init__(self, ss_key, ss_ws_key, tracker_message, tracker_project,
|
||||||
debug):
|
debug, pretend):
|
||||||
self.ss_key = ss_key
|
self.ss_key = ss_key
|
||||||
self.ss_ws_key = ss_ws_key
|
self.ss_ws_key = ss_ws_key
|
||||||
self.tracker_message = tracker_message
|
self.tracker_message = tracker_message
|
||||||
self.tracker_project = tracker_project
|
self.tracker_project = tracker_project
|
||||||
self.debug_enabled = debug
|
self.debug_enabled = debug
|
||||||
|
self.pretend = pretend
|
||||||
self.user_agent = 'adlr-tracker-spreadsheet-merger'
|
self.user_agent = 'adlr-tracker-spreadsheet-merger'
|
||||||
self.it_keys = ['id', 'owner', 'status', 'title']
|
self.it_keys = ['id', 'owner', 'status', 'title']
|
||||||
|
|
||||||
@ -117,9 +118,35 @@ class Merger(object):
|
|||||||
issues.append(issue)
|
issues.append(issue)
|
||||||
return issues
|
return issues
|
||||||
|
|
||||||
def fetch_tracker_issues(self):
|
def ids_for_spreadsheet_issues(self, ss_issues):
|
||||||
"""Fetches all issues matching the query and returns them as an array
|
"""Returns a Set of strings, each string an id from ss_issues"""
|
||||||
of dictionaries."""
|
ret = Set()
|
||||||
|
for ss_issue in ss_issues:
|
||||||
|
ret.add(ss_issue['id'])
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def tracker_issues_for_query_feed(self, feed):
|
||||||
|
"""Converts a feed object from a query to a list of tracker issue
|
||||||
|
dictionaries."""
|
||||||
|
issues = []
|
||||||
|
for issue in feed.entry:
|
||||||
|
issue_dict = {}
|
||||||
|
issue_dict['labels'] = [label.text for label in issue.label]
|
||||||
|
issue_dict['id'] = issue.id.text.split('/')[-1]
|
||||||
|
issue_dict['title'] = issue.title.text
|
||||||
|
issue_dict['status'] = issue.status.text
|
||||||
|
if issue.owner:
|
||||||
|
issue_dict['owner'] = issue.owner.username.text
|
||||||
|
issues.append(issue_dict)
|
||||||
|
return issues
|
||||||
|
|
||||||
|
def fetch_tracker_issues(self, ss_issues):
|
||||||
|
"""Fetches all relevant issues from traacker and returns them as an array
|
||||||
|
of dictionaries. Relevance is:
|
||||||
|
- has an ID that's in ss_issues, OR
|
||||||
|
- (is Area=Installer AND status is open).
|
||||||
|
Open status is one of: Unconfirmed, Untriaged, Available, Assigned,
|
||||||
|
Started, Upstream"""
|
||||||
issues = []
|
issues = []
|
||||||
got_results = True
|
got_results = True
|
||||||
index = 1
|
index = 1
|
||||||
@ -131,15 +158,30 @@ class Merger(object):
|
|||||||
if not feed.entry:
|
if not feed.entry:
|
||||||
got_results = False
|
got_results = False
|
||||||
index = index + len(feed.entry)
|
index = index + len(feed.entry)
|
||||||
for issue in feed.entry:
|
issues.extend(self.tracker_issues_for_query_feed(feed))
|
||||||
issue_dict = {}
|
# Now, remove issues that are open or in ss_issues.
|
||||||
issue_dict['labels'] = [label.text for label in issue.label]
|
ss_ids = self.ids_for_spreadsheet_issues(ss_issues)
|
||||||
issue_dict['id'] = issue.id.text.split('/')[-1]
|
open_statuses = ['Unconfirmed', 'Untriaged', 'Available', 'Assigned',
|
||||||
issue_dict['title'] = issue.title.text
|
'Started', 'Upstream']
|
||||||
issue_dict['status'] = issue.status.text
|
new_issues = []
|
||||||
if issue.owner:
|
for issue in issues:
|
||||||
issue_dict['owner'] = issue.owner.username.text
|
if issue['status'] in open_statuses or issue['id'] in ss_ids:
|
||||||
issues.append(issue_dict)
|
new_issues.append(issue)
|
||||||
|
# Remove id from ss_ids, if it's there
|
||||||
|
ss_ids.discard(issue['id'])
|
||||||
|
issues = new_issues
|
||||||
|
|
||||||
|
# Now, for each ss_id that didn't turn up in the query, explicitly add it
|
||||||
|
for id_ in ss_ids:
|
||||||
|
query = gdata.projecthosting.client.Query(issue_id=id_,
|
||||||
|
max_results=50,
|
||||||
|
start_index=index)
|
||||||
|
feed = self.it_client.get_issues('chromium-os', query=query)
|
||||||
|
if not feed.entry:
|
||||||
|
print 'No result for id', id_
|
||||||
|
continue
|
||||||
|
issues.extend(self.tracker_issues_for_query_feed(feed))
|
||||||
|
|
||||||
return issues
|
return issues
|
||||||
|
|
||||||
def store_creds(self):
|
def store_creds(self):
|
||||||
@ -270,10 +312,12 @@ class Merger(object):
|
|||||||
# Nothing
|
# Nothing
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if (ss_label is None) or (ss_label != t_label):
|
if (t_label is not None) and \
|
||||||
|
((ss_label is None) or (ss_label != t_label)):
|
||||||
ret['labels'].append('-' + t_label)
|
ret['labels'].append('-' + t_label)
|
||||||
|
|
||||||
if (t_label is None) or (t_label != ss_label):
|
if (ss_label is not None) and \
|
||||||
|
((t_label is None) or (t_label != ss_label)):
|
||||||
ret['labels'].append(ss_label)
|
ret['labels'].append(ss_label)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
@ -322,12 +366,12 @@ class Merger(object):
|
|||||||
print 'Logging into Tracker...'
|
print 'Logging into Tracker...'
|
||||||
self.tracker_login()
|
self.tracker_login()
|
||||||
|
|
||||||
print 'Fetching tracker issues...'
|
|
||||||
t_issues = self.fetch_tracker_issues()
|
|
||||||
self.debug('Tracker issues: %s' % t_issues)
|
|
||||||
print 'Fetching spreadsheet issues...'
|
print 'Fetching spreadsheet issues...'
|
||||||
ss_issues = self.fetch_spreadsheet_issues()
|
ss_issues = self.fetch_spreadsheet_issues()
|
||||||
self.debug('Spreadsheet issues: %s' % ss_issues)
|
self.debug('Spreadsheet issues: %s' % ss_issues)
|
||||||
|
print 'Fetching tracker issues...'
|
||||||
|
t_issues = self.fetch_tracker_issues(ss_issues)
|
||||||
|
self.debug('Tracker issues: %s' % t_issues)
|
||||||
return (t_issues, ss_issues)
|
return (t_issues, ss_issues)
|
||||||
|
|
||||||
def spreadsheet_to_tracker(self):
|
def spreadsheet_to_tracker(self):
|
||||||
@ -349,6 +393,9 @@ class Merger(object):
|
|||||||
|
|
||||||
if commit['type'] == 'append':
|
if commit['type'] == 'append':
|
||||||
print 'Creating new tracker issue...'
|
print 'Creating new tracker issue...'
|
||||||
|
if self.pretend:
|
||||||
|
print '(Skipping because --pretend is set)'
|
||||||
|
continue
|
||||||
created = self.it_client.add_issue(self.tracker_project,
|
created = self.it_client.add_issue(self.tracker_project,
|
||||||
dic['title'],
|
dic['title'],
|
||||||
self.tracker_message,
|
self.tracker_message,
|
||||||
@ -367,6 +414,9 @@ class Merger(object):
|
|||||||
print 'Done.'
|
print 'Done.'
|
||||||
else:
|
else:
|
||||||
print 'Updating issue with id:', dic['id']
|
print 'Updating issue with id:', dic['id']
|
||||||
|
if self.pretend:
|
||||||
|
print '(Skipping because --pretend is set)'
|
||||||
|
continue
|
||||||
self.it_client.update_issue(self.tracker_project,
|
self.it_client.update_issue(self.tracker_project,
|
||||||
dic['id'],
|
dic['id'],
|
||||||
self.tracker_user,
|
self.tracker_user,
|
||||||
@ -465,10 +515,17 @@ class Merger(object):
|
|||||||
self.debug('Operating on commit: %s' % commit)
|
self.debug('Operating on commit: %s' % commit)
|
||||||
if commit['type'] == 'append':
|
if commit['type'] == 'append':
|
||||||
print 'Appending new row...'
|
print 'Appending new row...'
|
||||||
self.gd_client.InsertRow(commit['new_row'], self.ss_key, self.ss_ws_key)
|
if not self.pretend:
|
||||||
|
self.gd_client.InsertRow(commit['new_row'],
|
||||||
|
self.ss_key, self.ss_ws_key)
|
||||||
|
else:
|
||||||
|
print '(Skipped because --pretend set)'
|
||||||
if commit['type'] == 'update':
|
if commit['type'] == 'update':
|
||||||
print 'Updating row...'
|
print 'Updating row...'
|
||||||
|
if not self.pretend:
|
||||||
self.gd_client.UpdateRow(commit['__raw_entry'], commit['dict'])
|
self.gd_client.UpdateRow(commit['__raw_entry'], commit['dict'])
|
||||||
|
else:
|
||||||
|
print '(Skipped because --pretend set)'
|
||||||
print 'Done.'
|
print 'Done.'
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -483,6 +540,8 @@ def main():
|
|||||||
default=False, help='Print debug output.')
|
default=False, help='Print debug output.')
|
||||||
parser.add_option('-m', '--message', dest='message', metavar='TEXT',
|
parser.add_option('-m', '--message', dest='message', metavar='TEXT',
|
||||||
help='Log message when updating Tracker issues')
|
help='Log message when updating Tracker issues')
|
||||||
|
parser.add_option('-p', '--pretend', action='store_true', dest='pretend',
|
||||||
|
default=False, help="Don't commit anything.")
|
||||||
parser.add_option('--ss_key', dest='ss_key', metavar='KEY',
|
parser.add_option('--ss_key', dest='ss_key', metavar='KEY',
|
||||||
help='Spreadsheets key (find with browse action)')
|
help='Spreadsheets key (find with browse action)')
|
||||||
parser.add_option('--ss_ws_key', dest='ss_ws_key', metavar='KEY',
|
parser.add_option('--ss_ws_key', dest='ss_ws_key', metavar='KEY',
|
||||||
@ -546,7 +605,7 @@ a delta and update the tracker issue with the owner, which seems to succeed.
|
|||||||
|
|
||||||
merger = Merger(options.ss_key, options.ss_ws_key,
|
merger = Merger(options.ss_key, options.ss_ws_key,
|
||||||
options.message, options.tracker_project,
|
options.message, options.tracker_project,
|
||||||
options.debug)
|
options.debug, options.pretend)
|
||||||
if options.action == 'browse':
|
if options.action == 'browse':
|
||||||
merger.browse()
|
merger.browse()
|
||||||
elif options.action == 'ss_to_t':
|
elif options.action == 'ss_to_t':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user