| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | # |
|---|
| 3 | # Copyright (C) 2016-2021 Cinc |
|---|
| 4 | # All rights reserved. |
|---|
| 5 | # |
|---|
| 6 | # This software is licensed as described in the file COPYING.txt, which |
|---|
| 7 | # you should have received as part of this distribution. |
|---|
| 8 | # |
|---|
| 9 | # Author: Cinc |
|---|
| 10 | # |
|---|
| 11 | |
|---|
| 12 | from trac.core import Component, implements |
|---|
| 13 | from trac.web.chrome import add_stylesheet, Chrome, INavigationContributor |
|---|
| 14 | from trac.web.main import IRequestHandler |
|---|
| 15 | from codereview.peerReviewMain import add_ctxt_nav_items |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | class PeerReviewReport(Component): |
|---|
| 19 | """Show a page with reports for getting data from code reviews. |
|---|
| 20 | |
|---|
| 21 | [[BR]] |
|---|
| 22 | Code review reports are normal Trac SQL reports. A report will be shown on the code review report page when the |
|---|
| 23 | report description starts with the following comment: |
|---|
| 24 | |
|---|
| 25 | {{{ |
|---|
| 26 | {{{ |
|---|
| 27 | #!comment |
|---|
| 28 | codereview=1 |
|---|
| 29 | }}} |
|---|
| 30 | }}} |
|---|
| 31 | """ |
|---|
| 32 | implements(INavigationContributor, IRequestHandler) |
|---|
| 33 | |
|---|
| 34 | # INavigationContributor methods |
|---|
| 35 | |
|---|
| 36 | def get_active_navigation_item(self, req): |
|---|
| 37 | return 'peerreviewmain' |
|---|
| 38 | |
|---|
| 39 | def get_navigation_items(self, req): |
|---|
| 40 | return |
|---|
| 41 | |
|---|
| 42 | # IRequestHandler methods |
|---|
| 43 | |
|---|
| 44 | def match_request(self, req): |
|---|
| 45 | return req.path_info == '/peerreviewreport' |
|---|
| 46 | |
|---|
| 47 | def process_request(self, req): |
|---|
| 48 | def is_codereview_report(desc): |
|---|
| 49 | """Check if wiki comment section holds 'codereview = 1' as first line.""" |
|---|
| 50 | lst = desc.splitlines() |
|---|
| 51 | if '{{{' not in lst or '}}}' not in lst or '#!comment' not in lst: |
|---|
| 52 | return False |
|---|
| 53 | lst = lst[lst.index('#!comment') + 1: lst.index('}}}')] # contents of comment section |
|---|
| 54 | if ''.join(lst[0].split()) == 'codereview=1': |
|---|
| 55 | return True |
|---|
| 56 | return False |
|---|
| 57 | |
|---|
| 58 | req.perm.require('CODE_REVIEW_DEV') |
|---|
| 59 | |
|---|
| 60 | reports = [] |
|---|
| 61 | for row in self.env.db_query("SELECT id, title, description FROM report"): |
|---|
| 62 | if is_codereview_report(row[2]): |
|---|
| 63 | reports.append({ |
|---|
| 64 | 'id': row[0], |
|---|
| 65 | 'title': row[1], |
|---|
| 66 | 'desc': row[2] |
|---|
| 67 | }) |
|---|
| 68 | |
|---|
| 69 | data = { |
|---|
| 70 | 'reports': reports |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | add_stylesheet(req, 'common/css/report.css') |
|---|
| 74 | add_ctxt_nav_items(req) |
|---|
| 75 | |
|---|
| 76 | if hasattr(Chrome, 'jenv'): |
|---|
| 77 | return 'peerreview_report_jinja.html', data |
|---|
| 78 | else: |
|---|
| 79 | return 'peerreview_report.html', data, None |
|---|