Skip to content

Commit 9c58013

Browse files
author
Gauvain Pocentek
committed
Fix GET/POST for project files
1 parent 3270865 commit 9c58013

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

gitlab/__init__.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,8 @@ class GitlabObject(object):
675675
requiredUpdateAttrs = None
676676
#: Attributes that are optional when updating an object
677677
optionalUpdateAttrs = None
678+
#: Whether the object ID is required in the GET url
679+
getRequiresId = True
678680

679681
idAttr = 'id'
680682
shortPrintAttr = None
@@ -1134,7 +1136,8 @@ class ProjectFile(GitlabObject):
11341136
optionalCreateAttrs = ['encoding']
11351137
requiredDeleteAttrs = ['branch_name', 'commit_message']
11361138
getListWhenNoId = False
1137-
shortPrintAttr = 'name'
1139+
shortPrintAttr = 'file_path'
1140+
getRequiresId = False
11381141

11391142

11401143
class ProjectSnippetNote(GitlabObject):

gitlab/cli.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ def populate_sub_parser_by_class(cls, sub_parser):
8282

8383
elif action_name in [GET, DELETE]:
8484
if cls not in [gitlab.CurrentUser]:
85-
id_attr = cls.idAttr.replace('_', '-')
86-
sub_parser_action.add_argument("--%s" % id_attr,
87-
required=True)
85+
if cls.getRequiresId:
86+
id_attr = cls.idAttr.replace('_', '-')
87+
sub_parser_action.add_argument("--%s" % id_attr,
88+
required=True)
8889
[sub_parser_action.add_argument("--%s" % x.replace('_', '-'),
8990
required=True)
9091
for x in cls.requiredGetAttrs]
@@ -172,7 +173,7 @@ def do_get(cls, gl, what, args):
172173
die("%s objects can't be retrieved" % what)
173174

174175
id = None
175-
if cls not in [gitlab.CurrentUser]:
176+
if cls not in [gitlab.CurrentUser] and cls.getRequiresId:
176177
id = get_id(cls, args)
177178

178179
try:

0 commit comments

Comments
 (0)