@@ -31,6 +31,13 @@ import gitlab
31
31
32
32
camel_re = re .compile ('(.)([A-Z])' )
33
33
34
+ extra_actions = {
35
+ gitlab .ProjectBranch : {
36
+ 'protect' : { 'requiredAttrs' : ['id' , 'project-id' ] },
37
+ 'unprotect' : { 'requiredAttrs' : ['id' , 'project-id' ] }
38
+ },
39
+ }
40
+
34
41
def die (msg ):
35
42
sys .stderr .write (msg + "\n " )
36
43
sys .exit (1 )
@@ -74,6 +81,12 @@ def actionHelpList(cls):
74
81
detail += " " .join (["[--%s=ARG]" % x .replace ('_' , '-' ) for x in cls .optionalCreateAttrs ])
75
82
l .append ("%s %s" % (action , detail ))
76
83
84
+ if extra_actions .has_key (cls ):
85
+ for action in sorted (extra_actions [cls ]):
86
+ d = extra_actions [cls ][action ]
87
+ detail = " " .join (["--%s=ARG" % arg for arg in d ['requiredAttrs' ]])
88
+ l .append ("%s %s" % (action , detail ))
89
+
77
90
return (l )
78
91
79
92
def usage ():
@@ -301,6 +314,20 @@ elif action == "delete":
301
314
elif action == "update" :
302
315
o = do_update (cls , d )
303
316
317
+ elif action == "protect" :
318
+ if cls != gitlab .ProjectBranch :
319
+ die ("%s objects can't be protected" % what )
320
+
321
+ o = do_get (cls , d )
322
+ o .protect ()
323
+
324
+ elif action == "unprotect" :
325
+ if cls != gitlab .ProjectBranch :
326
+ die ("%s objects can't be protected" % what )
327
+
328
+ o = do_get (cls , d )
329
+ o .unprotect ()
330
+
304
331
else :
305
332
die ("Unknown action: %s. Use \" gitlab %s help\" to get details." % (action , what ))
306
333
0 commit comments