@@ -96,14 +96,18 @@ def TEAMS(self, new):
96
96
self ._teams = new
97
97
98
98
# Ignore LineLengthBear, PycodestyleBear
99
- @re_botcmd (pattern = r'^(?:(?:welcome)|(?:inv)|(?:invite))\s+(?:(?:@?([\w-]+)(?:\s*(?:to)\s+(\w+))?)|(me))$' ,
99
+ @re_botcmd (pattern = r'^(?:(?:welcome)|(?:inv)|(?:invite))( \s+(?:(?:@?([\w-]+)(?:\s*(?:to)\s+(\w+))?)|(me)))? $' ,
100
100
re_cmd_name_help = 'invite [to team]' )
101
101
def invite_cmd (self , msg , match ):
102
102
"""
103
103
Invite given user to given team. By default it invites to
104
104
"newcomers" team.
105
105
"""
106
- invitee = match .group (1 )
106
+ if match .group (1 ) is None :
107
+ return ('Invalid command args. Usage: `{} (invite|inv) '
108
+ '((member|member to [team])|me)`' .format (
109
+ self .bot_config .BOT_PREFIX ))
110
+ invitee = match .group (2 )
107
111
inviter = msg .frm .nick
108
112
109
113
if invitee == 'me' :
@@ -113,7 +117,7 @@ def invite_cmd(self, msg, match):
113
117
self .invited_users .add (user )
114
118
return
115
119
116
- team = 'newcomers' if match .group (2 ) is None else match .group (2 )
120
+ team = 'newcomers' if match .group (3 ) is None else match .group (3 )
117
121
118
122
self .log .info ('{} invited {} to {}' .format (inviter , invitee , team ))
119
123
@@ -146,14 +150,17 @@ def callback_message(self, msg):
146
150
self .TEAMS [self .GH_ORG_NAME + ' newcomers' ].invite (user )
147
151
self .invited_users .add (user )
148
152
149
- @re_botcmd (pattern = r'(?:new|file) issue ([\w\-\.]+?)(?: |\n)(.+?)(?:$|\n((?:.|\n)*))' , # Ignore LineLengthBear, PyCodeStyleBear
153
+ @re_botcmd (pattern = r'(?:new|file) issue( ([\w\-\.]+?)(?: |\n)(.+?)(?:$|\n((?:.|\n)*)))? ' , # Ignore LineLengthBear, PyCodeStyleBear
150
154
re_cmd_name_help = 'new issue repo-name title\n [description]' ,
151
155
flags = re .IGNORECASE )
152
156
def create_issue_cmd (self , msg , match ):
153
157
"""Create issues on GitHub and GitLab repositories.""" # Ignore QuotesBear, LineLengthBear, PyCodeStyleBear
154
- repo_name = match .group (1 )
155
- iss_title = match .group (2 )
156
- iss_description = match .group (3 ) if match .group (3 ) is not None else ''
158
+ if match .group (1 ) is None :
159
+ return ('Invalid command args. Usage: `{} (new|file) issue repo-name'
160
+ ' title\n [description]`' .format (self .bot_config .BOT_PREFIX ))
161
+ repo_name = match .group (2 )
162
+ iss_title = match .group (3 )
163
+ iss_description = match .group (4 ) if match .group (4 ) is not None else ''
157
164
extra_msg = '\n Opened by @{username} at [{backend}]({msg_link})' .format (
158
165
username = msg .frm .nick ,
159
166
backend = self .bot_config .BACKEND ,
@@ -169,14 +176,17 @@ def create_issue_cmd(self, msg, match):
169
176
'exist. Please ensure that the repository is available '
170
177
'and owned by the org.' )
171
178
172
- @re_botcmd (pattern = r'^unassign\s+https://(github|gitlab)\.com/([^/]+)/([^/]+)/issues/(\d+)' , # Ignore LineLengthBear, PyCodeStyleBear
179
+ @re_botcmd (pattern = r'^unassign( \s+https://(github|gitlab)\.com/([^/]+)/([^/]+)/issues/(\d+))? ' , # Ignore LineLengthBear, PyCodeStyleBear
173
180
re_cmd_name_help = 'unassign <complete-issue-URL>' ,
174
181
flags = re .IGNORECASE )
175
182
def unassign_cmd (self , msg , match ):
176
183
"""Unassign from an issue.""" # Ignore QuotesBear
177
- org = match .group (2 )
178
- repo_name = match .group (3 )
179
- issue_number = match .group (4 )
184
+ if match .group (1 ) is None :
185
+ return ('Invalid command args. Usage: `{} unassign '
186
+ '<complete-issue-URL>`' .format (self .bot_config .BOT_PREFIX ))
187
+ org = match .group (3 )
188
+ repo_name = match .group (4 )
189
+ issue_number = match .group (5 )
180
190
181
191
user = msg .frm .nick
182
192
@@ -196,13 +206,15 @@ def unassign_cmd(self, msg, match):
196
206
else :
197
207
return 'You are not an assignee on the issue.'
198
208
199
- @re_botcmd (pattern = r'mark\s+(wip|pending(?:(?:-|\s+)review)?\b)\s+https://(github|gitlab)\.com/([^/]+)/([^/]+)/(pull|merge_requests)/(\d+)' , # Ignore LineLengthBear, PyCodeStyleBear
209
+ @re_botcmd (pattern = r'mark( \s+(wip|pending(?:(?:-|\s+)review)?\b)\s+https://(github|gitlab)\.com/([^/]+)/([^/]+)/(pull|merge_requests)/(\d+))? ' , # Ignore LineLengthBear, PyCodeStyleBear
200
210
re_cmd_name_help = 'mark (wip|pending) <complete-PR-URL>' ,
201
211
flags = re .IGNORECASE )
202
212
def mark_cmd (self , msg , match ):
203
213
"""Mark a given PR/MR with status labels.""" # Ignore QuotesBear
204
- state , host , org , repo_name , xr , number = match .groups ()
205
-
214
+ arg , state , host , org , repo_name , xr , number = match .groups ()
215
+ if arg is None :
216
+ return ('Invalid command args. Usage: `{} mark (wip|pending) '
217
+ '<complete-PR-URL>`' .format (self .bot_config .BOT_PREFIX ))
206
218
if host .lower () == 'github' :
207
219
assert xr .lower () == 'pull'
208
220
elif host .lower () == 'gitlab' :
@@ -251,14 +263,17 @@ def mark_cmd(self, msg, match):
251
263
bot_prefix = self .bot_config .BOT_PREFIX )
252
264
)
253
265
254
- @re_botcmd (pattern = r'^assign\s+https://(github|gitlab)\.com/([^/]+)/([^/]+/)+issues/(\d+)' , # Ignore LineLengthBear, PyCodeStyleBear
266
+ @re_botcmd (pattern = r'^assign( \s+https://(github|gitlab)\.com/([^/]+)/([^/]+/)+issues/(\d+))? ' , # Ignore LineLengthBear, PyCodeStyleBear
255
267
re_cmd_name_help = 'assign <complete-issue-URL>' ,
256
268
flags = re .IGNORECASE )
257
269
def assign_cmd (self , msg , match ):
258
270
"""Assign to GitLab and GitHub issues.""" # Ignore QuotesBear
259
- org = match .group (2 )
260
- repo_name = match .group (3 )[:- 1 ]
261
- iss_number = match .group (4 )
271
+ if match .group (1 ) is None :
272
+ return ('Invalid command args. Usage: `{} assign '
273
+ '<complete-issue-URL>`' .format (self .bot_config .BOT_PREFIX ))
274
+ org = match .group (3 )
275
+ repo_name = match .group (4 )[:- 1 ]
276
+ iss_number = match .group (5 )
262
277
263
278
user = msg .frm .nick
264
279
@@ -353,9 +368,12 @@ def community_state(pr_count: dict):
353
368
else :
354
369
return 'dead'
355
370
356
- @re_botcmd (pattern = r'pr\s+stats\s+(\d+)(?:hours|hrs)' )
371
+ @re_botcmd (pattern = r'pr\s+stats( \s+(\d+)(?:hours|hrs))? ' )
357
372
def pr_stats (self , msg , match ):
358
- hours = match .group (1 )
373
+ if match .group (1 ) is None :
374
+ return ('Invalid command args. Usage: `{} pr stats <number-of-hours>'
375
+ '(hours|hrs)`' .format (self .bot_config .BOT_PREFIX ))
376
+ hours = match .group (2 )
359
377
pr_count = dict ()
360
378
start = time .time ()
361
379
for count , (name , repo ) in enumerate (self .gh_repos .items (), 1 ):
0 commit comments