def GetAdjacentIssue(we, issue, hotlist=None, next_issue=False): """Compute next or previous issue given params of current issue. Args: we: A WorkEnv instance. issue: The current issue (from which to compute prev/next). hotlist (optional): The current hotlist. next_issue (bool): If True, return next, issue, else return previous issue. Returns: The adjacent issue. Raises: NoSuchIssueException when there is no adjacent issue in the list. """ if hotlist: (prev_iid, _cur_index, next_iid, _total_count) = we.GetIssuePositionInHotlist(issue, hotlist) else: (prev_iid, _cur_index, next_iid, _total_count) = we.FindIssuePositionInSearch(issue) iid = next_iid if next_issue else prev_iid if iid is None: raise exceptions.NoSuchIssueException() return we.GetIssue(iid)
def testProcessException(self): """Expected exceptions are converted to pRPC codes, expected not.""" self.CheckExceptionStatus( exceptions.NoSuchUserException(), codes.StatusCode.NOT_FOUND) self.CheckExceptionStatus( exceptions.NoSuchProjectException(), codes.StatusCode.NOT_FOUND) self.CheckExceptionStatus( exceptions.NoSuchIssueException(), codes.StatusCode.NOT_FOUND) self.CheckExceptionStatus( exceptions.NoSuchComponentException(), codes.StatusCode.NOT_FOUND) self.CheckExceptionStatus( permissions.BannedUserException(), codes.StatusCode.PERMISSION_DENIED) self.CheckExceptionStatus( permissions.PermissionException(), codes.StatusCode.PERMISSION_DENIED) self.CheckExceptionStatus( exceptions.GroupExistsException(), codes.StatusCode.INVALID_ARGUMENT) self.CheckExceptionStatus( exceptions.InvalidComponentNameException(), codes.StatusCode.INVALID_ARGUMENT) self.CheckExceptionStatus( ratelimiter.ApiRateLimitExceeded('client_id', 'email'), codes.StatusCode.PERMISSION_DENIED) self.CheckExceptionStatus( features_svc.HotlistAlreadyExists(), codes.StatusCode.INVALID_ARGUMENT) self.CheckExceptionStatus(NotImplementedError(), None)
def GetIssue(self, mc, request): """Return the specified issue in a response proto.""" issue_ref = request.issue_ref project, issue, config = self._GetProjectIssueAndConfig( mc, issue_ref, view_deleted=True, issue_required=False) # Code for getting where a moved issue was moved to. if issue is None: moved_to_ref = self.services.issue.GetCurrentLocationOfMovedIssue( mc.cnxn, project.project_id, issue_ref.local_id) moved_to_project_id, moved_to_id = moved_to_ref moved_to_project_name = None if moved_to_project_id is not None: with work_env.WorkEnv(mc, self.services) as we: moved_to_project = we.GetProject(moved_to_project_id) moved_to_project_name = moved_to_project.project_name return issues_pb2.IssueResponse( moved_to_ref=converters.ConvertIssueRef(( moved_to_project_name, moved_to_id))) raise exceptions.NoSuchIssueException() if issue.deleted: return issues_pb2.IssueResponse(issue=issue_objects_pb2.Issue( is_deleted=True)) with work_env.WorkEnv(mc, self.services) as we: related_refs = we.GetRelatedIssueRefs([issue]) with mc.profiler.Phase('making user views'): users_involved_in_issue = tracker_bizobj.UsersInvolvedInIssues( [issue]) users_by_id = framework_views.MakeAllUserViews( mc.cnxn, self.services.user, users_involved_in_issue) framework_views.RevealAllEmailsToMembers(mc.auth, project, users_by_id) with mc.profiler.Phase('converting to response objects'): response = issues_pb2.IssueResponse() response.issue.CopyFrom( converters.ConvertIssue(issue, users_by_id, related_refs, config)) return response
def IngestIssueRefs(cnxn, issue_refs, services): """Look up issue IDs for the specified issues.""" project_names = set(ref.project_name for ref in issue_refs) project_names_to_id = services.project.LookupProjectIDs( cnxn, project_names) project_local_id_pairs = [] for ref in issue_refs: if ref.ext_identifier: # TODO(jeffcarp): For external tracker refs, once we have the classes # set up, validate that the tracker for this specific ref is supported # and store the external ref in the issue properly. if '/' not in ref.ext_identifier: raise exceptions.InvalidExternalIssueReference() continue if ref.project_name in project_names_to_id: pair = (project_names_to_id[ref.project_name], ref.local_id) project_local_id_pairs.append(pair) else: raise exceptions.NoSuchProjectException() issue_ids, misses = services.issue.LookupIssueIDs(cnxn, project_local_id_pairs) if misses: raise exceptions.NoSuchIssueException() return issue_ids