Esempio n. 1
0
    def files_tab(self, request):
        # call by ajax
        user = request.user
        current_user = request.user
        ticket = self.ticket
        pullreq = self.pullreq
        project = self.project
        has_proj_perm = project.has_push_perm(user.name) if user else False
        show_merge_guide = (
            has_proj_perm or user.username == ticket.author) \
            if user and not ticket.closed else False

        # get line comments

        # commits = self.all_commits
        # last_commit_ref = commits[0].sha if commits else ''
        # linecomments = PullLineComment.gets_by_target_and_ref(
        #    self.ticket.id, last_commit_ref)
        linecomments = PullLineComment.gets_by_target(self.ticket.id)

        # get diff(patches)
        # FIXME: ignore_space,这是被ajax请求的,js那边没这逻辑。应该在前端加一个按钮
        whitespace = request.get_form_var('w', '0')
        if whitespace.isdigit() and int(whitespace) == 1:
            ignore = True
        else:
            ignore = False
        try:
            diff = pullreq.get_diff(ignore_space=ignore, rename_detection=True,
                                    linecomments=linecomments)
        except:
            # FIXME: diff 的默认值不该为 [],其他很多地方也是
            diff = []

        return st('/pull/diffs_pane.html', **locals())
Esempio n. 2
0
 def get_codereviews_group(self):
     # FIXME: refactor this
     # group = { linecomment_id: ... }
     group = {}
     codereviews = PullLineComment.gets_by_target(self.id)
     comparer = lambda x: (x.old_path +
                           (str(x.oids) if x.has_oids else x.from_sha) +
                           str(x.linenum if x.has_linenum else x.position))
     codereviews.sort(key=comparer)
     for k, v in groupby(codereviews, key=comparer):
         crs = list(v)
         codereview = crs[0]
         group[codereview.id] = crs  # 相当于缩点了
     return group
Esempio n. 3
0
 def get_codereviews_group(self):
     # FIXME: refactor this
     # group = { linecomment_id: ... }
     group = {}
     codereviews = PullLineComment.gets_by_target(self.id)
     comparer = lambda x: (x.old_path + (str(x.oids)
                                         if x.has_oids else x.from_sha) +
                           str(x.linenum if x.has_linenum else x.position))
     codereviews.sort(key=comparer)
     for k, v in groupby(codereviews, key=comparer):
         crs = list(v)
         codereview = crs[0]
         group[codereview.id] = crs  # 相当于缩点了
     return group
Esempio n. 4
0
    def _toggle_whitespace(self, request, project, paths, ignore_space,
                           **kwargs):
        # For pull/new
        from_proj = request.get_form_var('from_proj')
        from_ref = request.get_form_var('from_ref')
        to_ref = request.get_form_var('to_ref')
        to_proj = request.get_form_var('to_proj')

        sha1 = kwargs.get('sha1')
        context_lines = kwargs.get('context_lines')
        ref = sha1
        if ref is None:
            ref = project.default_branch
        if hasattr(self, 'ticket'):
            pullreq = PullRequest.get_by_proj_and_ticket(
                project.id, self.ticket.ticket_number)
            linecomments = PullLineComment.gets_by_target(self.ticket.id)
        else:
            from_proj = CodeDoubanProject.get_by_name(from_proj)
            parent_proj = from_proj.get_forked_from()
            if to_proj:
                to_proj = CodeDoubanProject.get_by_name(to_proj)
            elif parent_proj:
                to_proj = parent_proj
            else:
                to_proj = from_proj
            pullreq = PullRequest.open(from_proj, from_ref, to_proj, to_ref)
            linecomments = []

        kw = {
            'paths': paths,
            'rename_detection': True,
            'linecomments': linecomments
        }
        if context_lines is not None:
            kw.update({'context_lines': context_lines})
        diff = pullreq.get_diff(**kw)
        return diff
Esempio n. 5
0
    def _toggle_whitespace(self, request, project, paths, ignore_space,
                           **kwargs):
        # For pull/new
        from_proj = request.get_form_var('from_proj')
        from_ref = request.get_form_var('from_ref')
        to_ref = request.get_form_var('to_ref')
        to_proj = request.get_form_var('to_proj')

        sha1 = kwargs.get('sha1')
        context_lines = kwargs.get('context_lines')
        ref = sha1
        if ref is None:
            ref = project.default_branch
        if hasattr(self, 'ticket'):
            pullreq = PullRequest.get_by_proj_and_ticket(
                project.id, self.ticket.ticket_number)
            linecomments = PullLineComment.gets_by_target(self.ticket.id)
        else:
            from_proj = CodeDoubanProject.get_by_name(from_proj)
            parent_proj = from_proj.get_forked_from()
            if to_proj:
                to_proj = CodeDoubanProject.get_by_name(to_proj)
            elif parent_proj:
                to_proj = parent_proj
            else:
                to_proj = from_proj
            pullreq = PullRequest.open(from_proj, from_ref, to_proj, to_ref)
            linecomments = []

        kw = {
            'paths': paths,
            'rename_detection': True,
            'linecomments': linecomments
        }
        if context_lines is not None:
            kw.update({'context_lines': context_lines})
        diff = pullreq.get_diff(**kw)
        return diff
Esempio n. 6
0
    def files_tab(self, request):
        # call by ajax
        user = request.user
        current_user = request.user
        ticket = self.ticket
        pullreq = self.pullreq
        project = self.project
        has_proj_perm = project.has_push_perm(user.name) if user else False
        show_merge_guide = (
            has_proj_perm or user.username == ticket.author) \
            if user and not ticket.closed else False

        # get line comments

        # commits = self.all_commits
        # last_commit_ref = commits[0].sha if commits else ''
        # linecomments = PullLineComment.gets_by_target_and_ref(
        #    self.ticket.id, last_commit_ref)
        linecomments = PullLineComment.gets_by_target(self.ticket.id)

        # get diff(patches)
        # FIXME: ignore_space,这是被ajax请求的,js那边没这逻辑。应该在前端加一个按钮
        whitespace = request.get_form_var('w', '0')
        if whitespace.isdigit() and int(whitespace) == 1:
            ignore = True
        else:
            ignore = False
        try:
            diff = pullreq.get_diff(ignore_space=ignore,
                                    rename_detection=True,
                                    linecomments=linecomments)
        except:
            # FIXME: diff 的默认值不该为 [],其他很多地方也是
            diff = []

        return st('/pull/diffs_pane.html', **locals())
Esempio n. 7
0
 def get_codereviews(self):
     codereviews = PullLineComment.gets_by_target(self.id)
     return codereviews
Esempio n. 8
0
 def get_codereviews(self):
     codereviews = PullLineComment.gets_by_target(self.id)
     return codereviews