| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | # |
|---|
| 3 | # Copyright (C) 2016 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 INavigationContributor, add_stylesheet |
|---|
| 14 | from trac.web.main import IRequestHandler |
|---|
| 15 | from .peerReviewMain import add_ctxt_nav_items |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | __author__ = 'Cinc' |
|---|
| 19 | __license__ = "BSD" |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | class PeerReviewReport(Component): |
|---|
| 23 | """Show a page with reports for getting data from code reviews. |
|---|
| 24 | |
|---|
| 25 | [[BR]] |
|---|
| 26 | Code review reports are normal Trac SQL reports. A report will be shown on the code review report page when the |
|---|
| 27 | report description starts with the following comment: |
|---|
| 28 | |
|---|
| 29 | {{{ |
|---|
| 30 | {{{ |
|---|
| 31 | #!comment |
|---|
| 32 | codereview=1 |
|---|
| 33 | }}} |
|---|
| 34 | }}} |
|---|
| 35 | """ |
|---|
| 36 | implements(INavigationContributor, IRequestHandler) |
|---|
| 37 | |
|---|
| 38 | # INavigationContributor methods |
|---|
| 39 | |
|---|
| 40 | def get_active_navigation_item(self, req): |
|---|
| 41 | return 'peerReviewMain' |
|---|
| 42 | |
|---|
| 43 | def get_navigation_items(self, req): |
|---|
| 44 | return |
|---|
| 45 | |
|---|
| 46 | # IRequestHandler methods |
|---|
| 47 | |
|---|
| 48 | def match_request(self, req): |
|---|
| 49 | return req.path_info == '/peerreviewreport' |
|---|
| 50 | |
|---|
| 51 | def process_request(self, req): |
|---|
| 52 | def is_codereview_report(desc): |
|---|
| 53 | """Check if wiki comment section holds 'codereview = 1' as first line.""" |
|---|
| 54 | lst = desc.splitlines() |
|---|
| 55 | if '{{{' not in lst or '}}}' not in lst or '#!comment' not in lst: |
|---|
| 56 | return False |
|---|
| 57 | lst = lst[lst.index('#!comment')+1:lst.index('}}}')] # contents of comment section |
|---|
| 58 | if ''.join(lst[0].split()) == 'codereview=1': |
|---|
| 59 | return True |
|---|
| 60 | return False |
|---|
| 61 | |
|---|
| 62 | req.perm.require('CODE_REVIEW_DEV') |
|---|
| 63 | |
|---|
| 64 | db = self.env.get_read_db() |
|---|
| 65 | cursor = db.cursor() |
|---|
| 66 | cursor.execute("SELECT id, title, description FROM report") |
|---|
| 67 | reports = [] |
|---|
| 68 | for row in cursor: |
|---|
| 69 | if is_codereview_report(row[2]): |
|---|
| 70 | reports.append({ |
|---|
| 71 | 'id': row[0], |
|---|
| 72 | 'title': row[1], |
|---|
| 73 | 'desc': row[2] |
|---|
| 74 | }) |
|---|
| 75 | |
|---|
| 76 | data = { |
|---|
| 77 | 'reports': reports |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | add_stylesheet(req, 'common/css/report.css') |
|---|
| 81 | |
|---|
| 82 | add_ctxt_nav_items(req) |
|---|
| 83 | return 'peerreview_report.html', data, None |
|---|