def _get_reviewers(ui, repo, token, reviewers=[]): folks = _slurp(_api("Person"), dict(token=token)) names = [] for person in reviewers: names += person.split(',') if len(names) == 0: names += [repo.ui.config("auth", "kiln.username")] reviewers = [[ p for p in folks if reviewer in p["sName"].lower() or reviewer in p["sEmail"].lower() ] for reviewer in names] actual_reviewers = [] for shortname, reviewer in zip(names, reviewers): if len(reviewer) > 1: choices = [ '%s. %s\n' % (x + 1, y['sName']) for (x, y) in enumerate(reviewer) ] ui.status('\nHmm... There are a couple folks named "%s"\n' % shortname) [ui.status('%s' % m) for m in choices] pick = ui.promptchoice('Which "%s" did you mean?' % shortname, ["&" + c for c in choices]) actual_reviewers += [reviewer[pick]] else: actual_reviewers += reviewer return actual_reviewers
def _get_reviewers(ui, repo, token, reviewers=[]): folks = _slurp(_api("Person"), dict(token=token)) names = [] for person in reviewers: names += person.split(',') if len(names) == 0: names += [repo.ui.config("auth","kiln.username")] reviewers = [[p for p in folks if reviewer in p["sName"].lower() or reviewer in p["sEmail"].lower()] for reviewer in names] actual_reviewers = [] for shortname, reviewer in zip(names,reviewers): if len(reviewer) > 1: choices = ['%s. %s\n' % (x+1, y['sName']) for (x,y) in enumerate(reviewer)] ui.status('\nHmm... There are a couple folks named "%s"\n' % shortname) [ui.status('%s' % m) for m in choices] pick = ui.promptchoice('Which "%s" did you mean?' % shortname, ["&"+c for c in choices]) actual_reviewers += [ reviewer[pick] ] else: actual_reviewers += reviewer return actual_reviewers
def checkChangeCtxDiff(ui, repo, changecontexts, testFunc, testDesc, fileEndings): '''Loop through each diff for each change and run the testFunc against each line''' ui.debug('Checking %s\n' % testDesc) for ctx in changecontexts: # Get the diff for each change and file for file in [f for f in ctx.files() if f.endswith(fileEndings)]: ui.debug('checking change: %s, file: %s\n' % (short(ctx.node()), file)) fmatch = matchfiles(repo, [file]) # diff from this nodes parent to current node diff = ''.join( patch.diff(repo, ctx.parents()[0].node(), ctx.node(), fmatch)).split('\n') for i in range(3, len(diff)): # start checking after diff header line = diff[i] if line.startswith('@@'): diffLocation = line # only check new lines added/modified in the file if line.startswith('+'): ui.debug('\nchecking line for %s: %s\n\n' % (testDesc, line)) testResult, errorLocation = testFunc(line) if testResult: ui.warn( '\n%s(s) found in %s for rev %s (change %s):\n' % (testDesc, file, ctx.rev(), short(ctx.node()))) ui.warn('%s\n' % diffLocation) ui.warn('%s\n' % line) ui.warn( '%s^\n' % (' ' * errorLocation, )) # show a pointer to error try: response = ui.promptchoice( '(n)o, (y)es, (a)llow %ss for current file\n' % testDesc + 'Are you sure you want to commit this change? [n]: ', (('&No'), ('&Yes'), ('&Allow')), 0) except AttributeError: ui.warn( 'This commit hook requires that you have mercurial 1.4+ installed. Please upgrade your hg installation.' ) response = 0 if response == 1: # next occurance in file continue elif response == 2: # next file break else: ui.warn('Aborting commit due to %s.\n' % testDesc) # error = True return True return False
def checkChangeCtxDiff(ui, repo, changecontexts, testFunc, testDesc, fileEndings): '''Loop through each diff for each change and run the testFunc against each line''' ui.debug('Checking %s\n' % testDesc) for ctx in changecontexts: # Get the diff for each change and file for file in [f for f in ctx.files() if f.endswith(fileEndings)]: ui.debug('checking change: %s, file: %s\n' % (short(ctx.node()), file)) fmatch = matchfiles(repo,[file]) # diff from this nodes parent to current node diff = ''.join(patch.diff(repo, ctx.parents()[0].node(), ctx.node(), fmatch)).split('\n') for i in range(3, len(diff)): # start checking after diff header line = diff[i] if line.startswith('@@'): diffLocation = line # only check new lines added/modified in the file if line.startswith('+'): ui.debug('\nchecking line for %s: %s\n\n' % (testDesc, line)) testResult, errorLocation = testFunc(line) if testResult: ui.warn('\n%s(s) found in %s for rev %s (change %s):\n' % (testDesc, file, ctx.rev(), short(ctx.node()))) ui.warn('%s\n' % diffLocation) ui.warn('%s\n' % line) ui.warn('%s^\n' % (' '*errorLocation,)) # show a pointer to error try: response = ui.promptchoice('(n)o, (y)es, (a)llow %ss for current file\n' % testDesc + 'Are you sure you want to commit this change? [n]: ' , (('&No'), ('&Yes'), ('&Allow')), 0) except AttributeError: ui.warn('This commit hook requires that you have mercurial 1.4+ installed. Please upgrade your hg installation.') response = 0 if response == 1: # next occurance in file continue elif response == 2: # next file break else: ui.warn('Aborting commit due to %s.\n' % testDesc) # error = True return True return False
def _get_reviewers(ui, auth_token, reviewers): """Given a list of desired reviewers, return a list of kiln people objects. The reviewers are specified as a list of 'names', where a name is a subset of either the perons's physical name as recorded on the kilnhg site, or their email address as recorded on the kilnhg site. This function downloads a list of all the kiln 'person records' that are visible to the current user, and for each specified reviewer, finds the corresponding 'person record' for it. In the case of ambiguity, it presents the user with a choice. Arguments: ui: the hg-to-console ui element auth_token: the token used to authenticate the user, from _get_authtoken reviewers: a list of reviewer-names, as described above. Each element of the list can also be a comma-separated list of names, for instance [ 'tom', 'dick,harry' ] Returns: A set of kiln people records, one for each reviewer specified in reviewers. A peopel record has an 'sName, 'sEmail', and 'ixPerson' field. Raises: Abort if no person-record is found for any of the reviewers. """ all_people = _slurp_from_kiln('Person', {'token': auth_token}) # Convert the list to a set, dealing with commas as we go. all_reviewers = set() for reviewer_entry in reviewers: for one_review in reviewer_entry.split(','): all_reviewers.add(one_review.strip().lower()) # For each asked-for reviewer, find the set of people records that # reviewer could be referring to. Hopefully it's exactly one! disambiguated_reviewers = {} # map from email (unique id) to person-record for reviewer in all_reviewers: candidate_reviewers = [] # all people whose name match 'reviewer' for person in all_people: if (reviewer in person["sName"].lower() or reviewer in person["sEmail"].lower()): candidate_reviewers.append(person) if not candidate_reviewers: # no person matched the reviewer raise mercurial.util.Abort('No reviewer found matching "%s"' % reviewer) elif len(candidate_reviewers) > 1: ui.status('\nHmm...There are a few folks matching "%s"\n' % reviewer) choices = ['%s. %s (%s)\n' % (i+1, p['sName'], p['sEmail']) for (i, p) in enumerate(candidate_reviewers)] for choice in choices: ui.status(choice) pick = ui.promptchoice('Which "%s" did you mean?' % reviewer, ["&" + c for c in choices]) picked_reviewer = candidate_reviewers[pick] else: picked_reviewer = candidate_reviewers[0] disambiguated_reviewers[picked_reviewer['sEmail']] = picked_reviewer return disambiguated_reviewers.values()
def prompt_yesno(ui, operation): return ui.promptchoice(('Continue %s (n)o, (y)es? [n]' % operation), (('&No'),('&Yes')), 0)
def prompt_yesno(ui, operation): return ui.promptchoice(('Continue %s (n)o, (y)es? [n]' % operation), (('&No'), ('&Yes')), 0)