Source file review_mode.ml
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
open! Import
module T = struct
[@@@coverage off]
type t =
| Pull_request of
{ author : Vcs.User_handle.t
; base : Vcs.Rev.t option
}
| Revision
[@@deriving equal, sexp_of]
end
include T
module Name = struct
type t =
| Pull_request
| Revision
let to_string = function
| Pull_request -> "pull-request"
| Revision -> "revision"
;;
end
module Name_compatibility = struct
type t =
| Pull_request
| Commit
| Revision
[@@deriving enumerate]
let to_name : t -> Name.t = function
| Pull_request -> Pull_request
| Commit | Revision -> Revision
;;
let to_string = function
| Commit -> "commit"
| (Pull_request | Revision) as t -> Name.to_string (to_name t)
;;
end
let arg ~emit_github_annotations =
let open Command.Std in
let pull_request_author_switch = "pull-request-author" in
let pull_request_base_switch = "pull-request-base" in
let review_mode_switch = "review-mode" in
let+ name =
Arg.named_with_default
[ review_mode_switch ]
(Param.enumerated ~docv:"MODE" (module Name_compatibility))
~default:Revision
~doc:
"Specifies the review context in which this command is executed. Use \
$(b,pull-request) when running in the context of a pull request (requires \
$(b,--pull-request-{author,base})). Use $(b,revision) when running in the \
context of a push to a branch (default). This setting affects how CRs are \
assigned and annotated. As a compatibility transition, this command accepts the \
$(b,commit) parameter as an alias for $(b,revision), however this should not be \
used in new code."
and+ pull_request_author =
Arg.named_opt
[ pull_request_author_switch ]
(Param.validated_string ~docv:"AUTHOR" (module Vcs.User_handle))
~doc:
(Printf.sprintf
"When $(b,--%s) is a pull-request this argument must be supplied to set the \
PR author."
review_mode_switch)
and+ pull_request_base =
Arg.named_opt
[ pull_request_base_switch ]
(Param.validated_string ~docv:"REV" (module Vcs.Rev))
~doc:
(Printf.sprintf
"When $(b,--%s) is a pull-request this argument must be supplied to set the \
PR base."
review_mode_switch)
in
let () =
match name with
| Pull_request | Revision -> ()
| Commit ->
let messages =
Pp.O.
[ Pp.verbatim "Parameter "
++ Pp_tty.id (module Name_compatibility) Commit
++ Pp.verbatim " for "
++ Pp_tty.kwd (module String) ("--" ^ review_mode_switch)
++ Pp.verbatim " was renamed "
++ Pp_tty.id (module Name_compatibility) Revision
++ Pp.text "."
; Pp.verbatim "Please attend."
]
in
User_message.warning messages ~emit_github_annotations
in
match Name_compatibility.to_name name with
| Revision ->
let () =
if Option.is_some pull_request_author
then
Err.raise
~exit_code:Err.Exit_code.cli_error
Pp.O.
[ Pp_tty.kwd (module String) ("--" ^ pull_request_author_switch)
++ Pp.text " should not be set when review mode is "
++ Pp_tty.kwd (module Name) Revision
++ Pp.text "."
] [@coverage off];
if Option.is_some pull_request_base
then
Err.raise
~exit_code:Err.Exit_code.cli_error
Pp.O.
[ Pp_tty.kwd (module String) ("--" ^ pull_request_base_switch)
++ Pp.text " should not be set when review mode is "
++ Pp_tty.kwd (module Name) Revision
++ Pp.text "."
] [@coverage off];
()
in
Revision
| Pull_request ->
let author =
match pull_request_author with
| Some author -> author
| None ->
Err.raise
~exit_code:Err.Exit_code.cli_error
Pp.O.
[ Pp.text "Review mode "
++ Pp_tty.kwd (module String) "pull-request"
++ Pp.text " requires "
++ Pp_tty.kwd (module String) ("--" ^ pull_request_author_switch)
++ Pp.text "."
] [@coverage off]
in
let base =
(match pull_request_base with
| Some _ -> ()
| None ->
let messages =
Pp.O.
[ Pp.verbatim "Review mode "
++ Pp_tty.kwd (module String) "pull-request"
++ Pp.verbatim " requires "
++ Pp_tty.kwd (module String) ("--" ^ pull_request_base_switch)
++ Pp.verbatim "."
; Pp.verbatim "It will become mandatory in the future, please attend."
]
in
User_message.warning messages ~emit_github_annotations);
pull_request_base
in
Pull_request { author; base }
;;