Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3005b3d

Browse files
committed
Updated few gitlab.py docstrings as an example about how to document api
1 parente822b0b commit3005b3d

File tree

1 file changed

+66
-25
lines changed

1 file changed

+66
-25
lines changed

‎gitlab.py

Lines changed: 66 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#
1515
# You should have received a copy of the GNU Lesser General Public License
1616
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17-
17+
""" Module for interfacing with GitLab-api """
1818
from __future__importprint_function,division,absolute_import
1919

2020
importsix
@@ -124,28 +124,33 @@ def _raiseErrorFromResponse(response, error):
124124

125125

126126
classGitlab(object):
127-
"""Represents a GitLab server connection"""
127+
""" Represents a GitLab server connection
128+
129+
Args:
130+
url (str): the URL of the Gitlab server
131+
private_token (str): the user private token
132+
email (str): the user email/login
133+
password (str): the user password (associated with email)
134+
ssl_verify (bool): (Passed to requests-library)
135+
timeout (float or tuple(float,float)): (Passed to
136+
requests-library). Timeout to use for requests to gitlab server
137+
"""
138+
128139
def__init__(self,url,private_token=None,
129140
email=None,password=None,ssl_verify=True,timeout=None):
130-
"""Stores informations about the server
131-
132-
url: the URL of the Gitlab server
133-
private_token: the user private token
134-
email: the user email/login
135-
password: the user password (associated with email)
136-
ssl_verify: (Passed to requests-library)
137-
timeout: (Passed to requests-library). Timeout to use for requests to
138-
gitlab server. Float or tuple(Float,Float).
139-
"""
141+
140142
self._url='%s/api/v3'%url
143+
#: Timeout to use for requests to gitlab server
141144
self.timeout=timeout
145+
#: Headers that will be used in request to GitLab
142146
self.headers= {}
143147
self.setToken(private_token)
148+
#: the user email
144149
self.email=email
150+
#: the user password (associated with email)
145151
self.password=password
152+
#: (Passed to requests-library)
146153
self.ssl_verify=ssl_verify
147-
# Gitlab should handle UTF-8
148-
self.gitlab_encoding='UTF-8'
149154

150155
defauth(self):
151156
"""Performs an authentication using either the private token, or the
@@ -497,16 +502,17 @@ def owned_projects(self, **kwargs):
497502
returnself._list_projects("/projects/owned",**kwargs)
498503

499504
defGroup(self,id=None,**kwargs):
500-
"""Creates/gets/lists group(s) known by the GitLab server.
501-
502-
If id is None, returns a list of groups.
503-
504-
If id is an integer, returns the matching group (or raises a
505-
GitlabGetError if not found)
506-
507-
If id is a dict, creates a new object using attributes provided. The
508-
object is NOT saved on the server. Use the save() method on the object
509-
to write it on the server.
505+
"""Creates/gets/lists group(s) known by the GitLab server
506+
507+
Args:
508+
id: If id is None, returns a list of groups.
509+
id: If id is an integer,
510+
returns the matching group (or raises a GitlabGetError if not
511+
found).
512+
id: If id is a dict, creates a new object using attributes
513+
provided. The object is NOT saved on the server. Use the
514+
save() method on the object to write it on the server.
515+
kwargs: Arbitrary keyword arguments
510516
"""
511517
returnGroup._getListOrObject(self,id,**kwargs)
512518

@@ -562,21 +568,43 @@ def _sanitize_dict(src):
562568

563569

564570
classGitlabObject(object):
571+
""" Baseclass for all classes that interface with GitLab
572+
573+
Args:
574+
gl (gitlab.Gitlab): GitLab server connection
575+
data: If data is integer or string type, get object from GitLab
576+
data: If data is dictionary, create new object locally. To save object
577+
in GitLab, call save-method
578+
kwargs: Arbitrary keyword arguments
579+
"""
580+
#: Url to use in GitLab for this object
565581
_url=None
566582
_returnClass=None
567583
_constructorTypes=None
568-
# Tells if _getListOrObject should return list or object when id is None
584+
#: Tells if _getListOrObject should return list or object when id is None
569585
getListWhenNoId=True
586+
587+
#: Tells if GitLab-api allows retrieving single objects
570588
canGet=True
589+
#: Tells if GitLab-api allows listing of objects
571590
canList=True
591+
#: Tells if GitLab-api allows creation of new objects
572592
canCreate=True
593+
#: Tells if GitLab-api allows updating object
573594
canUpdate=True
595+
#: Tells if GitLab-api allows deleting object
574596
canDelete=True
597+
#: Attributes that are required for constructing url
575598
requiredUrlAttrs= []
599+
#: Attributes that are required when retrieving list of objects
576600
requiredListAttrs= []
601+
#: Attributes that are required when retrieving single object
577602
requiredGetAttrs= []
603+
#: Attributes that are required when deleting object
578604
requiredDeleteAttrs= []
605+
#: Attributes that are required when creating a new object
579606
requiredCreateAttrs= []
607+
#: Attributes that are optional when creating a new object
580608
optionalCreateAttrs= []
581609
idAttr='id'
582610
shortPrintAttr=None
@@ -1199,6 +1227,19 @@ def archive(self, sha=None, **kwargs):
11991227
_raiseErrorFromResponse(r,GitlabGetError)
12001228

12011229
defcreate_file(self,path,branch,content,message,**kwargs):
1230+
""" Creates file in project repository
1231+
1232+
Args:
1233+
path (str): Full path to new file
1234+
branch (str): The name of branch
1235+
content (str): Content of the file
1236+
message (str): Commit message
1237+
kwargs: Arbitrary keyword arguments
1238+
1239+
Raises:
1240+
GitlabCreateError: Operation failed
1241+
GitlabConnectionError: Connection to GitLab-server failed
1242+
"""
12021243
url="/projects/%s/repository/files"%self.id
12031244
url+="?file_path=%s&branch_name=%s&content=%s&commit_message=%s"% \
12041245
(path,branch,content,message)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp