forked from atseanpaul/review-o-matic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrollreviewerfromgit.py
61 lines (52 loc) · 2.27 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
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.
'''
class FromgitChangeReviewer(GitChangeReviewer):
def __init__(self, reviewer, change, dry_run, days_since_last_review):
super().__init__(reviewer, change, 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(change, days_since_last_review):
return ('FROMGIT' in change.subject and
(days_since_last_review == None or days_since_last_review >= 14))
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 get_upstream_patch(self):
super().get_upstream_patch()
if self.upstream_patch and self.upstream_sha:
remote = self.DEFAULT_REMOTE
remote_name = self.reviewer.generate_remote_name(remote)
self.reviewer.fetch_remote(remote_name, remote, self.DEFAULT_BRANCH)
if self.reviewer.is_sha_in_branch(self.upstream_sha['sha'], remote_name,
self.DEFAULT_BRANCH):
self.add_patch_in_mainline_review()
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