def count_commits(qapp): ''' Return the total number of (unique) commits in a repo ''' counted = set() repo = Repo(qualitas.file_for(qapp)) for c in repo.iter_commits(): if not c in counted: #print(c.binsha, c.committed_date) counted.add(c.binsha) return len(counted)
def categorise_commits(pyvers, qapp): ''' Return cumulative number of commits on-or-after each Python version''' repo = Repo(qualitas.file_for(qapp)) pd = CategoriseDates(pyvers, qapp) counted = set() for c in repo.iter_commits(): if not c in counted: pd.add_date(date.fromtimestamp(c.committed_date)) counted.add(c) return (pd.count_cumulative(), pd.get_counted())
def restore_one(qapp, old_head): ''' Put the GIT repo for an app back the way you found it. Specifically, restore HEAD to master, and delete rollback branch. ''' try: repo = Repo(qualitas.file_for(qapp)) with repo.config_writer(): repo.head.reference = old_head repo.head.reset(index=True, working_tree=True) repo.git.branch('-D', TEMP_BRANCH_NAME) # delete the temp branch except (Exception) as err: print('### Unable to restore', qapp) print(err)
def test_at_commit(pyvers, qapp, acommit): percs = [] repo = Repo(qualitas.file_for(qapp)) old_head = repo.heads[0] # Mostly 'master' but not always repo.head.reset(commit=acommit, index=True, working_tree=True) try: percs = qualitas_test.test_all(pyvers, [qapp]) except: # Want to make sure I do 'restore_one' no matter what... print('Exception running test harness', file=sys.stderr) # Now, put it back the way you found it: repo.head.reference = old_head repo.head.reset(index=True, working_tree=True) repo.close() return percs[0] # One entry for each Python version we tried
def get_tag_date(qapp, tagname): ''' Return a date corresponding to this tagged release. If not found, return a list of possible alternatives. ''' # Open the GIT repo if it's there: try: repo = Repo(qualitas.file_for(qapp)) except InvalidGitRepositoryError as err: return (False, []) alternatives = [] for tagref in repo.refs: refname, refdate = git_query.tagref2namedate(repo, tagref) if refname == tagname: return (True, refdate) else: if refdate.year in [2014, 2015]: alternatives.append((refname, refdate)) return (False, alternatives)
def rollback_all(pyversion, qualapps): ''' Roll-back all the apps in qualapps to the date of pyversion. Silently ignore an app if it has no release for pyversion. Return a list of what you did, so we can restore them later. ''' rolledback = [] # List of (app, head-name) pairs for qapp in qualapps: latest = git_query.get_latest_for(qapp, pyversion) if not latest: # App was not released back then continue try: repo = Repo(qualitas.file_for(qapp)) print('Roll', qapp, 'back to version', latest[0], 'of', latest[1]) old_head = rollback_one(repo, qapp, latest[0]) if old_head: details = '%s & %s & %s' % (qapp, latest[0], latest[1]) rolledback.append((qapp, old_head, details)) except (Exception) as err: print('### Unable to rollback', qapp) return rolledback
def get_tag_dates(qapp): ''' Return (name,date) pairs for this application's tagged releases ''' repo = Repo(qualitas.file_for(qapp)) # Now collect the data from the 'tagged' commits: ndlist = [tagref2namedate(repo, tagref) for tagref in repo.tags] return [nd for nd in ndlist if nd] # Filter out any blanks
def get_tagged_commits(qapp): ''' Return (commit,name) pairs for this application's tagged releases ''' repo = Repo(qualitas.file_for(qapp)) ct_dict = {tr.commit: tr for tr in repo.tags} return ct_dict