def take_action(self, parsed_args): rev = reviews.Query(parsed_args.host, parsed_args.port) to_filter = [] if parsed_args.projects: pjs = parsed_args.projects projects = filters.OrFilter().add_items('project', pjs) to_filter.append(projects) other = filters.Items() other.add_items('is', ['open']) if parsed_args.limit is not None: other.add_items('limit', parsed_args.limit) to_filter.append(other) columns = ('Subject', 'Status', 'Project', 'Topic', 'Owner', 'Modified Time', 'Reviews', 'URL') data = [] for review in rev.filter(*to_filter): last_updated = datetime.fromtimestamp(review['lastUpdated']) crvw = self._get_review_votes(review['currentPatchSet']) data.append( (review['subject'][:50], review['status'], review['project'], review.get('topic'), review['owner']['name'], last_updated, crvw, review['url'])) return (columns, data)
def print_gerrit(self, pformat="", number=None, owner="", reviewer="", status=""): """ Print the complete review information for a review numeber and given owner or reviewer with status. The print detail can be summary or detailed. Args: pformat -- The format can be detail or summary. The default is detail. number -- Review number. If no review are supplied then all the reviews of a particualr owner, reviwer or status are printed. owner -- The review owner reviewer -- The reviewer. status -- Any valid gerrit status. """ slab_logger.debug('Extracting details of gerrit review(s)') other = filters.Items() if number: other.add_items('change', number) if owner: other.add_items('owner', owner) if reviewer: other.add_items('reviewer', reviewer) if self.prjname: other.add_items('project', self.prjname) if status: if status in GerritFns.status: other.add_items("status", status) else: raise ValueError("Invalid Status supplied") key = self.getkey() query = reviews.Query(self.hostname, self.port, self.user, key) for review in query.filter(other): if GerritFns.instrument_code: # if instrumenting code we only need to check the first review return review else: if pformat == "summary": GerritFns.summary(review) else: GerritFns.detail(review)
def code_review(self, number): """ Code review the given gerrit number Args: number -- Gerrit code review number Raises: GerritFnException -- If Unable to find the gerrit review number. """ slab_logger.debug('Pulling gerrit review %i for code review' % number) project = filters.OrFilter() project.add_items('project', [self.prjname]) other = filters.Items() other.add_items('change', number) key = self.getkey() query = reviews.Query(self.hostname, self.port, self.user, key) for review in query.filter(project, other): if 'type' in review.keys() and review['type'] == 'error': raise GerritFnException(review['message']) ref = review["currentPatchSet"]["ref"] tdir = "/tmp/{}".format(self.prjname) user = self.user host = self.hostname + ":" + str(self.port) # now do a git clone without checkout cmd = "rm -rf {};".format(tdir) pkey = "GIT_SSH_COMMAND=\"ssh -i {}\"".format(key) cmd += "{} git clone --no-checkout ssh://{}@{}/{} {};".format( pkey, self.user, host, self.prjname, tdir) cmd += "cd {};".format(tdir) cmd += "{} git fetch ssh://{}@{}/{} {}".format( pkey, user, host, self.prjname, ref) cmd += " && {} git format-patch -1 --stdout FETCH_HEAD".format( pkey) # now run the command and get output ret_code, ret_str = service_utils.run_this(cmd) if not ret_code: slab_logger.log(25, ret_str) else: raise GerritFnException(ret_str)
def change_review(self, number, rev_number, verify_number, msg=""): """ Change the review and verify numbers for a gerrit review number Args: number -- Gerrit review rev_number -- Review number can be anything from -2 to 2 verify_number -- Verification number can be anything from from -1 to 1 msg -- Commit message Raises: GerritFnException -- If Unable to find the gerrit review number. """ slab_logger.debug('Changing review for gerrit review %i' % number) project = filters.OrFilter() project.add_items('project', [self.prjname]) other = filters.Items() other.add_items('change', number) key = self.getkey() query = reviews.Query(self.hostname, self.port, self.user, key) for review in query.filter(project, other): revision = review["currentPatchSet"]["revision"] rev = reviews.Review(revision, self.hostname, self.port, self.user, key) rev.review(rev_number) rev.verify(verify_number) if not msg: msg = click.prompt(Format.message( 0, 0, Format.bld, "Commit Message for Review? "), default="") ret = rev.commit(msg) if not ret: raise GerritFnException("Unable to change the review and " "verification number on " + number) return raise GerritFnException("Unable to find the review " + number)
def code_state(self, number, state, msg=""): """ Change state of the Gerrit review number to the given state and message. Args: number -- Review number can be anything from -2 to 2 state -- The valid allowed state changes can be abondon restore or delete. msg -- Commit message Raises: GerritFnException -- If Unable to find the gerrit review number. """ slab_logger.debug('Changing the state of gerrit review to %i' % number) project = filters.OrFilter() project.add_items('project', [self.prjname]) other = filters.Items() other.add_items('change', number) key = self.getkey() query = reviews.Query(self.hostname, self.port, self.user, key) if state not in ['abandon', 'restore', 'delete']: raise GerritFnException("unknown state for change " + number) for review in query.filter(project, other): revision = review["currentPatchSet"]["revision"] rev = reviews.Review(revision, self.hostname, self.port, self.user, key) rev.status(state) if not msg: msg = click.prompt(Format.message(0, 0, Format.bld, "Message? "), default="") ret = rev.commit(msg) if not ret: raise GerritFnException("Unable to abondon changes on " + number) return raise GerritFnException("Unable to find the review " + number)