-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtrollreviewerfromgit.py
85 lines (70 loc) · 2.94 KB
/
trollreviewerfromgit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import re
from trollreview import ReviewResult
from trollreview import ReviewType
from trollreviewergit import GitChangeReviewer
from trollstrings import ReviewStrings
class FromgitReviewStrings(ReviewStrings):
HASH_EXAMPLE='''
(cherry picked from commit <commit SHA>
<remote git url> <remote git branch>)
'''
INVALID_HASH_FOOTER='''
Please double check your commit hash is valid in the upstream tree, and please
fully specify the remote tree and branch for FROMGIT changes (see below):
'''
CLEAN_BACKPORT_FOOTER='''
Consider changing your subject prefix to FROMGIT to better reflect the
contents of this patch.
'''
PATCH_IN_MAINLINE='''
This patch is labeled as FROMGIT, however it seems like it's already been
applied to mainline. Please revise your patch subject to replace FROMGIT with
UPSTREAM.
'''
PATCH_IN_FORBIDDEN_TREE='''
The remote listed on this patch is in a forbidden tree. Integration and rebasing
trees are unacceptable sources of patches since their commit sha can change.
Please source either a non-rebasing maintainer tree or a mailing list post. See
the link below on backporting for more information.
'''
class FromgitChangeReviewer(GitChangeReviewer):
def __init__(self, project, reviewer, change, msg_limit, dry_run,
days_since_last_review):
super().__init__(project, reviewer, change, msg_limit, dry_run)
self.strings = FromgitReviewStrings()
self.review_result = ReviewResult(self.change, self.strings, self.dry_run)
self.days_since_last_review = days_since_last_review
@staticmethod
def can_review_change(project, change, days_since_last_review):
# Don't re-review for 14 days
if days_since_last_review != None and days_since_last_review < 14:
return False
return 'FROMGIT' in project.prefixes and 'FROMGIT' in change.subject
def add_patch_in_mainline_review(self):
self.review_result.add_review(ReviewType.IN_MAINLINE,
self.strings.PATCH_IN_MAINLINE, vote=-1,
notify=True)
def is_remote_in_blocked_repos(self):
if not self.upstream_ref:
return False
for b in self.project.blocked_repos:
if re.match(b, self.upstream_ref.remote, re.I):
return True
return False
def add_patch_in_forbidden_tree(self):
self.review_result.add_review(ReviewType.FORBIDDEN_TREE,
self.strings.PATCH_IN_FORBIDDEN_TREE, vote=-1,
notify=True)
def get_upstream_patch(self):
super().get_upstream_patch()
if self.is_sha_in_mainline():
self.add_patch_in_mainline_review()
elif self.is_remote_in_blocked_repos():
self.add_patch_in_forbidden_tree()
def review_patch(self):
result = super().review_patch()
# Only re-review patches if we're adding an IN_MAINLINE review
if (self.days_since_last_review != None and
ReviewType.IN_MAINLINE not in result.issues):
return None
return result