blob: 18e8a73fd602e4d8067cd6200de3d801940bdfcd [file] [log] [blame]
Chih-Hung Hsiehbde955c2019-04-01 20:05:54 -07001% A simplified and mocked AOSP rules.pl
2
3%%%%% wrapper functions for unit tests
4
5change_branch(X) :- gerrit:change_branch(X).
6change_project(X) :- gerrit:change_project(X).
7commit_author(U,N,M) :- gerrit:commit_author(U,N,M).
8commit_delta(X) :- gerrit:commit_delta(X).
9commit_label(L,U) :- gerrit:commit_label(L,U).
10uploader(X) :- gerrit:uploader(X).
11
12%%%%% true/false conditions
13
14% Special auto-merger accounts.
15is_exempt_uploader :-
16 uploader(user(Id)),
17 memberchk(Id, [104, 106]).
18
19% Build cop overrides everything.
20has_build_cop_override :-
21 commit_label(label('Build-Cop-Override', 1), _).
22
23is_exempt_from_reviews :-
24 or(is_exempt_uploader, has_build_cop_override).
25
26% Some files in selected projects need API review.
27needs_api_review :-
28 commit_delta('^(.*/)?api/|^(system-api/)'),
29 change_project(Project),
30 memberchk(Project, [
31 'platform/external/apache-http',
32 'platform/frameworks/base',
33 'platform/frameworks/support',
34 'platform/packages/services/Car',
35 'platform/prebuilts/sdk'
36 ]).
37
38% Some branches need DrNo review.
39needs_drno_review :-
40 change_branch(Branch),
41 memberchk(Branch, [
42 'refs/heads/my-alpha-dev',
43 'refs/heads/my-beta-dev'
44 ]).
45
46% Some author email addresses need Qualcomm-Review.
47needs_qualcomm_review :-
48 commit_author(_, _, M),
49 regex_matches(
50'.*@(qti.qualcomm.com|qca.qualcomm.com|quicinc.com|qualcomm.com)', M).
51
52% Special projects, branches, user accounts
53% can opt out owners review.
54opt_out_find_owners :-
55 change_branch(Branch),
56 memberchk(Branch, [
57 'refs/heads/my-beta-testing',
58 'refs/heads/my-testing'
59 ]).
60
61% Special projects, branches, user accounts
62% can opt in owners review.
63% Note that opt_out overrides opt_in.
64opt_in_find_owners :- true.
65
66
67%%%%% Simple list filters.
68
69remove_label(X, In, Out) :-
70 gerrit:remove_label(In, label(X, _), Out).
71
72% Slow but simple for short input list.
73remove_review_categories(In, Out) :-
74 remove_label('API-Review', In, L1),
75 remove_label('Code-Review', L1, L2),
76 remove_label('DrNo-Review', L2, L3),
77 remove_label('Owner-Review-Vote', L3, L4),
78 remove_label('Qualcomm-Review', L4, L5),
79 remove_label('Verified', L5, Out).
80
81
82%%%%% Missing rules in Gerrit Prolog Cafe.
83
84or(InA, InB) :- once((A;B)).
85
86not(Goal) :- Goal -> false ; true.
87
88% memberchk(+Element, +List)
89memberchk(X, [H|T]) :-
90 (X = H -> true ; memberchk(X, T)).
91
92maplist(Functor, In, Out) :-
93 (In = []
94 -> Out = []
95 ; (In = [X1|T1],
96 Out = [X2|T2],
97 Goal =.. [Functor, X1, X2],
98 once(Goal),
99 maplist(Functor, T1, T2)
100 )
101 ).
102
103
104%%%%% Conditional rules and filters.
105
106submit_filter(In, Out) :-
107 (is_exempt_from_reviews
108 -> remove_review_categories(In, Out)
109 ; (check_review(needs_api_review,
110 'API_Review', In, L1),
111 check_review(needs_drno_review,
112 'DrNo-Review', L1, L2),
113 check_review(needs_qualcomm_review,
114 'Qualcomm-Review', L2, L3),
115 check_find_owners(L3, Out)
116 )
117 ).
118
119check_review(NeedReview, Label, In, Out) :-
120 (NeedReview
121 -> Out = In
122 ; remove_label(Label, In, Out)
123 ).
124
125% If opt_out_find_owners is true,
126% remove all 'Owner-Review-Vote' label;
127% else if opt_in_find_owners is true,
128% call find_owners:submit_filter;
129% else default to no find_owners filter.
130check_find_owners(In, Out) :-
131 (opt_out_find_owners
132 -> remove_label('Owner-Review-Vote', In, Temp)
133 ; (opt_in_find_owners
134 -> find_owners:submit_filter(In, Temp)
135 ; In = Temp
136 )
137 ),
138 Temp =.. [submit | L1],
139 remove_label('Owner-Approved', L1, L2),
140 maplist(owner_may_to_need, L2, L3),
141 Out =.. [submit | L3].
142
143% change may(_) to need(_) to block submit.
144owner_may_to_need(In, Out) :-
145 (In = label('Owner-Review-Vote', may(_))
146 -> Out = label('Owner-Review-Vote', need(_))
147 ; Out = In
148 ).