예제 #1
0
    def show(self, repo_name, pull_request_id):
        pull_request_id = safe_int(pull_request_id)
        c.pull_request = PullRequest.get_or_404(pull_request_id)

        # pull_requests repo_name we opened it against
        # ie. target_repo must match
        if repo_name != c.pull_request.target_repo.repo_name:
            raise HTTPNotFound

        c.allowed_to_change_status = PullRequestModel(). \
            check_user_change_status(c.pull_request, c.rhodecode_user)
        c.allowed_to_update = PullRequestModel().check_user_update(
            c.pull_request,
            c.rhodecode_user) and not c.pull_request.is_closed()
        c.allowed_to_merge = PullRequestModel().check_user_merge(
            c.pull_request,
            c.rhodecode_user) and not c.pull_request.is_closed()

        cc_model = ChangesetCommentsModel()

        c.pull_request_reviewers = c.pull_request.reviewers_statuses()

        c.pull_request_review_status = c.pull_request.calculated_review_status(
        )
        c.pr_merge_status, c.pr_merge_msg = PullRequestModel().merge_status(
            c.pull_request)
        c.approval_msg = None
        if c.pull_request_review_status != ChangesetStatus.STATUS_APPROVED:
            c.approval_msg = _('Reviewer approval is pending.')
            c.pr_merge_status = False
        # load compare data into template context
        enable_comments = not c.pull_request.is_closed()
        self._load_compare_data(c.pull_request,
                                enable_comments=enable_comments)

        # this is a hack to properly display links, when creating PR, the
        # compare view and others uses different notation, and
        # compare_commits.html renders links based on the target_repo.
        # We need to swap that here to generate it properly on the html side
        c.target_repo = c.source_repo

        # inline comments
        c.inline_cnt = 0
        c.inline_comments = cc_model.get_inline_comments(
            c.rhodecode_db_repo.repo_id, pull_request=pull_request_id).items()
        # count inline comments
        for __, lines in c.inline_comments:
            for comments in lines.values():
                c.inline_cnt += len(comments)

        # outdated comments
        c.outdated_cnt = 0
        if ChangesetCommentsModel.use_outdated_comments(c.pull_request):
            c.outdated_comments = cc_model.get_outdated_comments(
                c.rhodecode_db_repo.repo_id, pull_request=c.pull_request)
            # Count outdated comments and check for deleted files
            for file_name, lines in c.outdated_comments.iteritems():
                for comments in lines.values():
                    c.outdated_cnt += len(comments)
                if file_name not in c.included_files:
                    c.deleted_files.append(file_name)
        else:
            c.outdated_comments = {}

        # comments
        c.comments = cc_model.get_comments(c.rhodecode_db_repo.repo_id,
                                           pull_request=pull_request_id)

        if c.allowed_to_update:
            force_close = ('forced_closed', _('Close Pull Request'))
            statuses = ChangesetStatus.STATUSES + [force_close]
        else:
            statuses = ChangesetStatus.STATUSES
        c.commit_statuses = statuses

        c.ancestor = None  # TODO: add ancestor here

        return render('/pullrequests/pullrequest_show.html')