Skip to content

Commit 53562b3

Browse files
author
Gauvain Pocentek
committed
manage project branch protection with the cmd line
1 parent 33c771d commit 53562b3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

gitlab

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ import gitlab
3131

3232
camel_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+
3441
def 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

7992
def usage():
@@ -301,6 +314,20 @@ elif action == "delete":
301314
elif 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+
304331
else:
305332
die("Unknown action: %s. Use \"gitlab %s help\" to get details." % (action, what))
306333

0 commit comments

Comments
 (0)