@@ -31,6 +31,13 @@ import gitlab
3131
3232camel_re = re .compile ('(.)([A-Z])' )
3333
34+ extra_actions = {
35+ gitlab .ProjectBranch : {
36+ 'protect' : { 'requiredAttrs' : ['id' , 'project-id' ] },
37+ 'unprotect' : { 'requiredAttrs' : ['id' , 'project-id' ] }
38+ },
39+ }
40+
3441def die (msg ):
3542 sys .stderr .write (msg + "\n " )
3643 sys .exit (1 )
@@ -74,6 +81,12 @@ def actionHelpList(cls):
7481 detail += " " .join (["[--%s=ARG]" % x .replace ('_' , '-' ) for x in cls .optionalCreateAttrs ])
7582 l .append ("%s %s" % (action , detail ))
7683
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+
7790 return (l )
7891
7992def usage ():
@@ -301,6 +314,20 @@ elif action == "delete":
301314elif action == "update" :
302315 o = do_update (cls , d )
303316
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+
304331else :
305332 die ("Unknown action: %s. Use \" gitlab %s help\" to get details." % (action , what ))
306333
0 commit comments