code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
url = self.api_url + uri
response = requests.post(
url, headers=self.headers, data=kwargs,
verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
return self.success_or_raise(response, default_response=default_response) | def post(self, uri, default_response=None, **kwargs) | Call POST on the Gitlab server
>>> gitlab = Gitlab(host='http://localhost:10080', verify_ssl=False)
>>> gitlab.login(user='root', password='5iveL!fe')
>>> password = 'MyTestPassword1'
>>> email = 'example@example.com'
>>> data = {'name': 'test', 'username': 'test1', 'password': ... | 2.695611 | 3.397969 | 0.793301 |
url = self.api_url + uri
response = requests.delete(
url, headers=self.headers, verify=self.verify_ssl,
auth=self.auth, timeout=self.timeout)
return self.success_or_raise(response, default_response=default_response) | def delete(self, uri, default_response=None) | Call DELETE on the Gitlab server
>>> gitlab = Gitlab(host='http://localhost:10080', verify_ssl=False)
>>> gitlab.login(user='root', password='5iveL!fe')
>>> gitlab.delete('/users/5')
:param uri: String with the URI you wish to delete
:param default_response: Return value if JSO... | 2.761772 | 3.304023 | 0.835881 |
if self.suppress_http_error and not response.ok:
return False
response_json = default_response
if response_json is None:
response_json = {}
response.raise_for_status()
try:
response_json = response.json()
except ValueError:
... | def success_or_raise(self, response, default_response=None) | Check if request was successful or raises an HttpError
:param response: Response Object to check
:param default_response: Return value if JSONDecodeError
:returns dict: Dictionary containing response data
:returns bool: :obj:`False` on failure when exceptions are suppressed
:rai... | 3.427866 | 3.448231 | 0.994094 |
if not page:
page = 1
while True:
results = fn(*args, page=page, **kwargs)
if not results:
break
for x in results:
yield x
page += 1 | def getall(fn, page=None, *args, **kwargs) | Auto-iterate over the paginated results of various methods of the API.
Pass the GitLabAPI method as the first argument, followed by the
other parameters as normal. Include `page` to determine first page to poll.
Remaining kwargs are passed on to the called method, including `per_page`.
... | 3.100811 | 3.720013 | 0.833549 |
if user is None:
try:
self.headers.pop('SUDO')
except KeyError:
pass
else:
self.headers['SUDO'] = user | def setsudo(self, user=None) | Set the subsequent API calls to the user provided
:param user: User id or username to change to, None to return to the logged user
:return: Nothing | 3.68197 | 4.214355 | 0.873674 |
project = format_string(project)
return self.get(
'/projects/{project}'.format(project=project)) | def get_project(self, project) | Get info for a project identified by id or namespace/project_name
:param project: The ID or URL-encoded path of the project
:return: Dictionary containing the Project
:raise: HttpError: If invalid response returned | 6.702017 | 10.5356 | 0.636131 |
data = {'name': name}
if kwargs:
data.update(kwargs)
request = requests.post(
self.projects_url, headers=self.headers, data=data,
verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
if request.status_code == 201:
retur... | def createproject(self, name, **kwargs) | Creates a new project owned by the authenticated user.
:param name: new project name
:param path: custom repository name for new project. By default generated based on name
:param namespace_id: namespace for the new project (defaults to user)
:param description: short project descriptio... | 2.761527 | 3.021188 | 0.914054 |
data = {"id": project_id}
if kwargs:
data.update(kwargs)
request = requests.put(
'{0}/{1}'.format(self.projects_url, project_id), headers=self.headers,
data=data, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
if request.stat... | def editproject(self, project_id, **kwargs) | Edit an existing project.
:param name: new project name
:param path: custom repository name for new project. By default generated based on name
:param default_branch: they default branch
:param description: short project description
:param issues_enabled:
:param merge_re... | 2.694951 | 2.970486 | 0.907242 |
data = {'id': project_id, 'group_id': group_id, 'group_access': group_access}
request = requests.post(
'{0}/{1}/share'.format(self.projects_url, project_id),
headers=self.headers, data=data, verify=self.verify_ssl)
return request.status_code == 201 | def shareproject(self, project_id, group_id, group_access) | Allow to share project with group.
:param project_id: The ID of a project
:param group_id: The ID of a group
:param group_access: Level of permissions for sharing
:return: True is success | 2.359222 | 2.665688 | 0.885033 |
url = '/projects/{id}'.format(id=id)
response = self.delete(url)
if response is True:
return {}
else:
return response | def delete_project(self, id) | Delete a project from the Gitlab server
Gitlab currently returns a Boolean True if the deleted and as such we return an
empty Dictionary
:param id: The ID of the project or NAMESPACE/PROJECT_NAME
:return: Dictionary
:raise: HttpError: If invalid response returned | 4.460208 | 4.258616 | 1.047337 |
data = {'name': name}
if kwargs:
data.update(kwargs)
request = requests.post(
'{0}/user/{1}'.format(self.projects_url, user_id), headers=self.headers,
data=data, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
if request.statu... | def createprojectuser(self, user_id, name, **kwargs) | Creates a new project owned by the specified user. Available only for admins.
:param user_id: user_id of owner
:param name: new project name
:param description: short project description
:param default_branch: 'master' by default
:param issues_enabled:
:param merge_reque... | 2.612257 | 2.851644 | 0.916053 |
# if isinstance(access_level, basestring):
if access_level.lower() == 'master':
access_level = 40
elif access_level.lower() == 'developer':
access_level = 30
elif access_level.lower() == 'reporter':
access_level = 20
else:
... | def addprojectmember(self, project_id, user_id, access_level) | Adds a project member to a project
:param project_id: project id
:param user_id: user id
:param access_level: access level, see gitlab help to know more
:return: True if success | 2.023596 | 1.925075 | 1.051177 |
request = requests.delete(
'{0}/{1}/members/{2}'.format(self.projects_url, project_id, user_id),
headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
if request.status_code == 200:
return True | def deleteprojectmember(self, project_id, user_id) | Delete a project member
:param project_id: project id
:param user_id: user id
:return: always true | 2.315345 | 2.469707 | 0.937498 |
data = {
'id': project_id,
'url': url,
'push_events': int(bool(push)),
'issues_events': int(bool(issues)),
'merge_requests_events': int(bool(merge_requests)),
'tag_push_events': int(bool(tag_push)),
}
request = req... | def addprojecthook(self, project_id, url, push=False, issues=False, merge_requests=False, tag_push=False) | add a hook to a project
:param project_id: project id
:param url: url of the hook
:return: True if success | 1.765099 | 1.98553 | 0.888981 |
data = {
"id": project_id,
"hook_id": hook_id,
"url": url,
'push_events': int(bool(push)),
'issues_events': int(bool(issues)),
'merge_requests_events': int(bool(merge_requests)),
'tag_push_events': int(bool(tag_push)),
... | def editprojecthook(self, project_id, hook_id, url, push=False, issues=False, merge_requests=False, tag_push=False) | edit an existing hook from a project
:param id_: project id
:param hook_id: hook id
:param url: the new url
:return: True if success | 1.736073 | 1.874631 | 0.926088 |
data = {'page': page, 'per_page': per_page}
request = requests.get(
self.hook_url, params=data, headers=self.headers,
verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
if request.status_code == 200:
return request.json()
else:
... | def getsystemhooks(self, page=1, per_page=20) | Get all system hooks
:param page: Page number
:param per_page: Records per page
:return: list of hooks | 2.354759 | 2.613657 | 0.900944 |
data = {"url": url}
request = requests.post(
self.hook_url, headers=self.headers, data=data,
verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
if request.status_code == 201:
return True
else:
return False | def addsystemhook(self, url) | Add a system hook
:param url: url of the hook
:return: True if success | 2.479781 | 2.831212 | 0.875872 |
data = {"id": hook_id}
request = requests.delete(
'{0}/{1}'.format(self.hook_url, hook_id), data=data,
headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
if request.status_code == 200:
return True
else:
... | def deletesystemhook(self, hook_id) | Delete a project hook
:param hook_id: hook id
:return: True if success | 2.367705 | 2.663544 | 0.88893 |
data = {"id": project_id, "branch_name": branch, "ref": ref}
request = requests.post(
'{0}/{1}/repository/branches'.format(self.projects_url, project_id),
headers=self.headers, data=data, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
if request.... | def createbranch(self, project_id, branch, ref) | Create branch from commit SHA or existing branch
:param project_id: The ID of a project
:param branch: The name of the branch
:param ref: Create branch from commit SHA or existing branch
:return: True if success, False if not | 2.441446 | 2.635753 | 0.92628 |
request = requests.put(
'{0}/{1}/repository/branches/{2}/protect'.format(self.projects_url, project_id, branch),
headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
if request.status_code == 200:
return True
else:
... | def protectbranch(self, project_id, branch) | Protect a branch from changes
:param project_id: project id
:param branch: branch id
:return: True if success | 2.403018 | 2.564164 | 0.937155 |
data = {'id': project_id, 'forked_from_id': from_project_id}
request = requests.post(
'{0}/{1}/fork/{2}'.format(self.projects_url, project_id, from_project_id),
headers=self.headers, data=data, verify=self.verify_ssl,
auth=self.auth, timeout=self.timeout)
... | def createforkrelation(self, project_id, from_project_id) | Create a fork relation.
This DO NOT create a fork but only adds a link as fork the relation between 2 repositories
:param project_id: project id
:param from_project_id: from id
:return: true if success | 2.263894 | 2.539655 | 0.891418 |
request = requests.delete(
'{0}/{1}/fork'.format(self.projects_url, project_id),
headers=self.headers, verify=self.verify_ssl,
auth=self.auth, timeout=self.timeout)
if request.status_code == 200:
return True
else:
return False | def removeforkrelation(self, project_id) | Remove an existing fork relation. this DO NOT remove the fork,only the relation between them
:param project_id: project id
:return: true if success | 2.465816 | 2.631082 | 0.937187 |
request = requests.post(
'{0}/fork/{1}'.format(self.projects_url, project_id),
timeout=self.timeout, verify=self.verify_ssl)
if request.status_code == 200:
return True
else:
return False | def createfork(self, project_id) | Forks a project into the user namespace of the authenticated user.
:param project_id: Project ID to fork
:return: True if succeed | 2.856539 | 2.799327 | 1.020437 |
data = {'id': id, 'title': title}
if kwargs:
data.update(kwargs)
request = requests.post(
'{0}/{1}/issues'.format(self.projects_url, project_id),
headers=self.headers, data=data, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
i... | def createissue(self, project_id, title, **kwargs) | Create a new issue
:param project_id: project id
:param title: title of the issue
:return: dict with the issue created | 2.411606 | 2.593473 | 0.929875 |
data = {'id': project_id, 'issue_id': issue_id}
if kwargs:
data.update(kwargs)
request = requests.put(
'{0}/{1}/issues/{2}'.format(self.projects_url, project_id, issue_id),
headers=self.headers, data=data, verify=self.verify_ssl, auth=self.auth, timeo... | def editissue(self, project_id, issue_id, **kwargs) | Edit an existing issue data
:param project_id: project id
:param issue_id: issue id
:return: true if success | 2.253027 | 2.484553 | 0.906814 |
url = '/projects/{project}/deploy_keys/{key_id}/enable'.format(
project=project, key_id=key_id)
return self.post(url, default_response={}) | def enable_deploy_key(self, project, key_id) | Enables a deploy key for a project.
>>> gitlab = Gitlab(host='http://localhost:10080', verify_ssl=False)
>>> gitlab.login(user='root', password='5iveL!fe')
>>> gitlab.enable_deploy_key(15, 5)
:param project: The ID or URL-encoded path of the project owned by the authenticated user
... | 3.431071 | 4.736834 | 0.724338 |
data = {'id': project_id, 'title': title, 'key': key}
request = requests.post(
'{0}/{1}/keys'.format(self.projects_url, project_id),
headers=self.headers, data=data, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
if request.status_code == 201:
... | def adddeploykey(self, project_id, title, key) | Creates a new deploy key for a project.
:param project_id: project id
:param title: title of the key
:param key: the key itself
:return: true if success, false if not | 2.309548 | 2.5735 | 0.897435 |
data = {'name': name, 'path': path}
if kwargs:
data.update(kwargs)
request = requests.post(
self.groups_url, data=data, headers=self.headers,
verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
if request.status_code == 201:
... | def creategroup(self, name, path, **kwargs) | Creates a new group
:param name: The name of the group
:param path: The path for the group
:param kwargs: Any param the the Gitlab API supports
:return: dict of the new group | 2.361163 | 2.523317 | 0.935738 |
request = requests.post(
'{0}/{1}/projects/{2}'.format(self.groups_url, group_id, project_id),
headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
if request.status_code == 201:
return request.json()
else:
... | def moveproject(self, group_id, project_id) | Move a given project into a given group
:param group_id: ID of the destination group
:param project_id: ID of the project to be moved
:return: dict of the updated project | 2.504956 | 2.51364 | 0.996545 |
data = {'page': page, 'per_page': per_page, 'state': state}
request = requests.get(
'{0}/{1}/merge_requests'.format(self.projects_url, project_id),
params=data, headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
if request.statu... | def getmergerequests(self, project_id, page=1, per_page=20, state=None) | Get all the merge requests for a project.
:param project_id: ID of the project to retrieve merge requests for
:param page: Page Number
:param per_page: Records per page
:param state: Passes merge request state to filter them by it
:return: list with all the merge requests | 2.114222 | 2.281485 | 0.926687 |
request = requests.get(
'{0}/{1}/merge_request/{2}'.format(self.projects_url, project_id, mergerequest_id),
headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
if request.status_code == 200:
return request.json()
else:... | def getmergerequest(self, project_id, mergerequest_id) | Get information about a specific merge request.
:param project_id: ID of the project
:param mergerequest_id: ID of the merge request
:return: dict of the merge request | 2.097011 | 2.260604 | 0.927633 |
data = {
'source_branch': sourcebranch,
'target_branch': targetbranch,
'title': title,
'assignee_id': assignee_id,
'target_project_id': target_project_id
}
request = requests.post(
'{0}/{1}/merge_requests'.format(s... | def createmergerequest(self, project_id, sourcebranch, targetbranch,
title, target_project_id=None, assignee_id=None) | Create a new merge request.
:param project_id: ID of the project originating the merge request
:param sourcebranch: name of the branch to merge from
:param targetbranch: name of the branch to merge to
:param title: Title of the merge request
:param assignee_id: Assignee user ID
... | 1.79439 | 1.991198 | 0.901161 |
data = {'merge_commit_message': merge_commit_message}
request = requests.put(
'{0}/{1}/merge_request/{2}/merge'.format(self.projects_url, project_id, mergerequest_id),
data=data, headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
... | def acceptmergerequest(self, project_id, mergerequest_id, merge_commit_message=None) | Update an existing merge request.
:param project_id: ID of the project originating the merge request
:param mergerequest_id: ID of the merge request to accept
:param merge_commit_message: Custom merge commit message
:return: dict of the modified merge request | 2.077243 | 2.205206 | 0.941972 |
request = requests.post(
'{0}/{1}/merge_request/{2}/comments'.format(self.projects_url, project_id, mergerequest_id),
data={'note': note}, headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
return request.status_code == 201 | def addcommenttomergerequest(self, project_id, mergerequest_id, note) | Add a comment to a merge request.
:param project_id: ID of the project originating the merge request
:param mergerequest_id: ID of the merge request to comment on
:param note: Text of comment
:return: True if success | 2.366572 | 2.569377 | 0.921069 |
data = {'id': project_id, 'title': title, 'file_name': file_name, 'code': code}
if visibility_level in [0, 10, 20]:
data['visibility_level'] = visibility_level
request = requests.post(
'{0}/{1}/snippets'.format(self.projects_url, project_id),
data=d... | def createsnippet(self, project_id, title, file_name, code, visibility_level=0) | Creates an snippet
:param project_id: project id to create the snippet under
:param title: title of the snippet
:param file_name: filename for the snippet
:param code: content of the snippet
:param visibility_level: snippets can be either private (0), internal(10) or public(20)
... | 2.084069 | 2.179679 | 0.956136 |
request = requests.delete(
'{0}/{1}/snippets/{2}'.format(self.projects_url, project_id, snippet_id),
headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
return request.status_code == 200 | def deletesnippet(self, project_id, snippet_id) | Deletes a given snippet
:param project_id: project_id
:param snippet_id: snippet id
:return: True if success | 2.410966 | 2.642106 | 0.912517 |
request = requests.put(
'{0}/{1}/repository/branches/{2}/unprotect'.format(self.projects_url, project_id, branch),
headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
if request.status_code == 200:
return request.json()
... | def unprotectrepositorybranch(self, project_id, branch) | Unprotects a single project repository branch. This is an idempotent function,
unprotecting an already unprotected repository branch still returns a 200 OK status code.
:param project_id: project id
:param branch: branch to unprotect
:return: dict with the branch | 2.220071 | 2.404924 | 0.923135 |
data = {'id': project_id, 'tag_name': tag_name, 'ref': ref, 'message': message}
request = requests.post(
'{0}/{1}/repository/tags'.format(self.projects_url, project_id), data=data,
verify=self.verify_ssl, auth=self.auth, headers=self.headers, timeout=self.timeout)
... | def createrepositorytag(self, project_id, tag_name, ref, message=None) | Creates new tag in the repository that points to the supplied ref
:param project_id: project id
:param tag_name: tag
:param ref: sha1 of the commit or branch to tag
:param message: message
:return: dict | 2.190845 | 2.458181 | 0.891246 |
return self.delete('/projects/{project_id}/repository/tags/{tag_name}'.format(
project_id=project_id, tag_name=tag_name)) | def delete_repository_tag(self, project_id, tag_name) | Deletes a tag of a repository with given name.
:param project_id: The ID of a project
:param tag_name: The name of a tag
:return: Dictionary containing delete tag
:raise: HttpError: If invalid response returned | 2.426795 | 3.195583 | 0.759422 |
data = {
'author': author,
'note': note,
'path': path,
'line': line,
'line_type': 'new'
}
request = requests.post(
'{0}/{1}/repository/commits/{2}/comments'.format(self.projects_url, project_id, sha),
... | def addcommenttocommit(self, project_id, author, sha, path, line, note) | Adds an inline comment to a specific commit
:param project_id: project id
:param author: The author info as returned by create mergerequest
:param sha: The name of a repository branch or tag or if not given the default branch
:param path: The file path
:param line: The line numb... | 2.398259 | 2.40812 | 0.995905 |
data = {}
if kwargs:
data.update(kwargs)
request = requests.get(
'{0}/{1}/repository/tree'.format(self.projects_url, project_id), params=data,
verify=self.verify_ssl, auth=self.auth, headers=self.headers, timeout=self.timeout)
if request.st... | def getrepositorytree(self, project_id, **kwargs) | Get a list of repository files and directories in a project.
:param project_id: The ID of a project
:param path: The path inside repository. Used to get contend of subdirectories
:param ref_name: The name of a repository branch or tag or if not given the default branch
:return: dict wit... | 2.571669 | 2.810597 | 0.91499 |
data = {'filepath': filepath}
request = requests.get(
'{0}/{1}/repository/blobs/{2}'.format(self.projects_url, project_id, sha1),
params=data, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout,
headers=self.headers)
if request.status_code... | def getrawfile(self, project_id, sha1, filepath) | Get the raw file contents for a file by commit SHA and path.
:param project_id: The ID of a project
:param sha1: The commit or branch name
:param filepath: The path the file
:return: raw file contents | 2.796144 | 3.015414 | 0.927284 |
request = requests.get(
'{0}/{1}/repository/raw_blobs/{2}'.format(self.projects_url, project_id, sha1),
verify=self.verify_ssl, auth=self.auth, headers=self.headers, timeout=self.timeout)
if request.status_code == 200:
return request.content
else:
... | def getrawblob(self, project_id, sha1) | Get the raw file contents for a blob by blob SHA.
:param project_id: The ID of a project
:param sha1: the commit sha
:return: raw blob | 2.525334 | 2.688462 | 0.939323 |
data = {'from': from_id, 'to': to_id}
request = requests.get(
'{0}/{1}/repository/compare'.format(self.projects_url, project_id),
params=data, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout,
headers=self.headers)
if request.status_code... | def compare_branches_tags_commits(self, project_id, from_id, to_id) | Compare branches, tags or commits
:param project_id: The ID of a project
:param from_id: the commit sha or branch name
:param to_id: the commit sha or branch name
:return: commit list and diff between two branches tags or commits provided by name
:raise: HttpError: If invalid re... | 2.446381 | 2.736549 | 0.893966 |
data = {'page': page, 'per_page': per_page}
request = requests.get("{0}/{1}".format(self.search_url, search), params=data,
verify=self.verify_ssl, auth=self.auth, headers=self.headers, timeout=self.timeout)
if request.status_code == 200:
retur... | def searchproject(self, search, page=1, per_page=20) | Search for projects by name which are accessible to the authenticated user
:param search: Query to search for
:param page: Page number
:param per_page: Records per page
:return: list of results | 2.421498 | 2.669531 | 0.907088 |
if not filepath:
filepath = ''
request = requests.get(
'{0}/{1}/repository/archive'.format(self.projects_url, project_id),
verify=self.verify_ssl, auth=self.auth, headers=self.headers, timeout=self.timeout)
if request.status_code == 200:
... | def getfilearchive(self, project_id, filepath=None) | Get an archive of the repository
:param project_id: project id
:param filepath: path to save the file to
:return: True if the file was saved to the filepath | 4.180363 | 4.077992 | 1.025103 |
request = requests.delete(
'{0}/{1}'.format(self.groups_url, group_id),
headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
return request.status_code == 200 | def deletegroup(self, group_id) | Deletes an group by ID
:param group_id: id of the group to delete
:return: True if it deleted, False if it couldn't. False could happen for several reasons, but there isn't a good way of differentiating them | 2.745933 | 2.964716 | 0.926204 |
data = {'page': page, 'per_page': per_page}
request = requests.get(
'{0}/{1}/members'.format(self.groups_url, group_id), params=data,
headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
if request.status_code == 200:
... | def getgroupmembers(self, group_id, page=1, per_page=20) | Lists the members of a given group id
:param group_id: the group id
:param page: which page to return (default is 1)
:param per_page: number of items to return per page (default is 20)
:return: the group's members | 2.264115 | 2.474436 | 0.915002 |
if not isinstance(access_level, int):
if access_level.lower() == 'owner':
access_level = 50
elif access_level.lower() == 'master':
access_level = 40
elif access_level.lower() == 'developer':
access_level = 30
... | def addgroupmember(self, group_id, user_id, access_level) | Adds a project member to a project
:param user_id: user id
:param access_level: access level, see gitlab help to know more
:return: True if success | 1.865311 | 1.780643 | 1.047549 |
request = requests.delete(
'{0}/{1}/members/{2}'.format(self.groups_url, group_id, user_id),
headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
if request.status_code == 200:
return True | def deletegroupmember(self, group_id, user_id) | Delete a group member
:param group_id: group id to remove the member from
:param user_id: user id
:return: always true | 2.349527 | 2.47296 | 0.950087 |
data = {'id': group_id, 'cn': cn, 'group_access': group_access, 'provider': provider}
request = requests.post(
'{0}/{1}/ldap_group_links'.format(self.groups_url, group_id),
headers=self.headers, data=data, verify=self.verify_ssl)
return request.status_code == 2... | def addldapgrouplink(self, group_id, cn, group_access, provider) | Add LDAP group link
:param id: The ID of a group
:param cn: The CN of a LDAP group
:param group_access: Minimum access level for members of the LDAP group
:param provider: LDAP provider for the LDAP group (when using several providers)
:return: True if success | 2.4251 | 2.590183 | 0.936266 |
url = '{base}/{gid}/ldap_group_links/{provider}{cn}'.format(
base=self.groups_url, gid=group_id, cn=cn,
provider=('{0}/'.format(provider) if provider else ''))
request = requests.delete(url, headers=self.headers, verify=self.verify_ssl)
return request.status_co... | def deleteldapgrouplink(self, group_id, cn, provider=None) | Deletes a LDAP group link (for a specific LDAP provider if given)
:param group_id: The ID of a group
:param cn: The CN of a LDAP group
:param provider: Name of a LDAP provider
:return: True if success | 3.277753 | 3.759727 | 0.871806 |
data = {'body': content}
request = requests.post(
'{0}/{1}/issues/{2}/notes'.format(self.projects_url, project_id, issue_id),
verify=self.verify_ssl, auth=self.auth, headers=self.headers, data=data, timeout=self.timeout)
if request.status_code == 201:
... | def createissuewallnote(self, project_id, issue_id, content) | Create a new note
:param project_id: Project ID
:param issue_id: Issue ID
:param content: Contents
:return: Json or False | 2.274569 | 2.290184 | 0.993182 |
data = {
'file_path': file_path,
'branch_name': branch_name,
'encoding': encoding,
'content': content,
'commit_message': commit_message
}
request = requests.post(
'{0}/{1}/repository/files'.format(self.projects_url... | def createfile(self, project_id, file_path, branch_name, encoding, content, commit_message) | Creates a new file in the repository
:param project_id: project id
:param file_path: Full path to new file. Ex. lib/class.rb
:param branch_name: The name of branch
:param content: File content
:param commit_message: Commit message
:return: true if success, false if not | 2.055499 | 2.274723 | 0.903626 |
data = {
'file_path': file_path,
'branch_name': branch_name,
'content': content,
'commit_message': commit_message
}
request = requests.put(
'{0}/{1}/repository/files'.format(self.projects_url, project_id),
headers=... | def updatefile(self, project_id, file_path, branch_name, content, commit_message) | Updates an existing file in the repository
:param project_id: project id
:param file_path: Full path to new file. Ex. lib/class.rb
:param branch_name: The name of branch
:param content: File content
:param commit_message: Commit message
:return: true if success, false if... | 2.155608 | 2.302346 | 0.936266 |
data = {'file_path': file_path, 'ref': ref}
request = requests.get(
'{0}/{1}/repository/files'.format(self.projects_url, project_id),
headers=self.headers, data=data, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
if request.status_code == 200:
... | def getfile(self, project_id, file_path, ref) | Allows you to receive information about file in repository like name, size, content.
Note that file content is Base64 encoded.
:param project_id: project_id
:param file_path: Full path to file. Ex. lib/class.rb
:param ref: The name of branch, tag or commit
:return: | 2.447299 | 2.493545 | 0.981454 |
data = {
'file_path': file_path,
'branch_name': branch_name,
'commit_message': commit_message
}
request = requests.delete(
'{0}/{1}/repository/files'.format(self.projects_url, project_id),
headers=self.headers, data=data, veri... | def deletefile(self, project_id, file_path, branch_name, commit_message) | Deletes existing file in the repository
:param project_id: project id
:param file_path: Full path to new file. Ex. lib/class.rb
:param branch_name: The name of branch
:param commit_message: Commit message
:return: true if success, false if not | 2.286067 | 2.479545 | 0.92197 |
data = {'token': token, 'project_url': project_url}
request = requests.put(
'{0}/{1}/services/gitlab-ci'.format(self.projects_url, project_id),
verify=self.verify_ssl, auth=self.auth, headers=self.headers, data=data, timeout=self.timeout)
return request.status_... | def setgitlabciservice(self, project_id, token, project_url) | Set GitLab CI service for project
:param project_id: project id
:param token: CI project token
:param project_url: CI project url
:return: true if success, false if not | 2.53165 | 2.761778 | 0.916674 |
request = requests.delete(
'{0}/{1}/services/gitlab-ci'.format(self.projects_url, project_id),
headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
return request.status_code == 200 | def deletegitlabciservice(self, project_id, token, project_url) | Delete GitLab CI service settings
:param project_id: Project ID
:param token: Token
:param project_url: Project URL
:return: true if success, false if not | 2.845792 | 3.053193 | 0.932071 |
data = {'name': name, 'color': color}
request = requests.post(
'{0}/{1}/labels'.format(self.projects_url, project_id), data=data,
verify=self.verify_ssl, auth=self.auth, headers=self.headers, timeout=self.timeout)
if request.status_code == 201:
retu... | def createlabel(self, project_id, name, color) | Creates a new label for given repository with given name and color.
:param project_id: The ID of a project
:param name: The name of the label
:param color: Color of the label given in 6-digit hex notation with leading '#' sign (e.g. #FFAABB)
:return: | 2.308869 | 2.523503 | 0.914946 |
data = {'name': name}
request = requests.delete(
'{0}/{1}/labels'.format(self.projects_url, project_id), data=data,
verify=self.verify_ssl, auth=self.auth, headers=self.headers, timeout=self.timeout)
return request.status_code == 200 | def deletelabel(self, project_id, name) | Deletes a label given by its name.
:param project_id: The ID of a project
:param name: The name of the label
:return: True if succeed | 2.782979 | 3.23216 | 0.861028 |
data = {'name': name, 'new_name': new_name, 'color': color}
request = requests.put(
'{0}/{1}/labels'.format(self.projects_url, project_id), data=data,
verify=self.verify_ssl, auth=self.auth, headers=self.headers, timeout=self.timeout)
if request.status_code == ... | def editlabel(self, project_id, name, new_name=None, color=None) | Updates an existing label with new name or now color.
At least one parameter is required, to update the label.
:param project_id: The ID of a project
:param name: The name of the label
:return: True if succeed | 2.277204 | 2.513353 | 0.906042 |
data = {'page': page, 'per_page': per_page}
if search:
data['search'] = search
request = requests.get(
self.namespaces_url, params=data, headers=self.headers, verify=self.verify_ssl)
if request.status_code == 200:
return request.json()
... | def getnamespaces(self, search=None, page=1, per_page=20) | Return a namespace list
:param search: Optional search query
:param page: Which page to return (default is 1)
:param per_page: Number of items to return per page (default is 20)
:return: returns a list of namespaces, false if there is an error | 2.232336 | 2.400307 | 0.930021 |
def deprecation_warning(*args, **kwargs):
warnings.warn('Call to deprecated function {name}. Please consult our documentation at '
'http://pyapi-gitlab.readthedocs.io/en/latest/#gitlab.Gitlab.{name}'.format(name=func.__name__),
category=DeprecationWarning)
... | def deprecated(func) | This is a decorator which can be used to mark functions as deprecated. It will result in a warning being emitted
when the function is used.
:param func: The function to run
:return: function | 2.717233 | 3.395061 | 0.800349 |
if inspect.ismethod(fun):
for cls in inspect.getmro(fun.__self__.__class__):
if cls.__dict__.get(fun.__name__) is fun:
return cls
fun = fun.__func__ # fallback to __qualname__ parsing
if inspect.isfunction(fun):
cls = getattr(inspect.getmodule(fun),
... | def get_class_that_defined_method(fun) | Tries to find the class that defined the specified method. Will not work for nested classes
(locals).
Args:
fun: Function / Method
Returns:
Returns the class which defines the given method / function. | 1.449999 | 1.815043 | 0.798878 |
res = set()
if hasattr(cls, '__mro__'):
for _class in inspect.getmro(cls):
values_ = getattr(_class, field_name, None)
if values_ is not None:
res = res.union(set(make_list(values_)))
return res | def get_field_mro(cls, field_name) | Goes up the mro and looks for the specified field. | 3.294892 | 3.150401 | 1.045864 |
if item_or_items is None:
return None
if isinstance(item_or_items, list):
return item_or_items
if hasattr(item_or_items, '__iter__') and not isinstance(item_or_items, str):
return list(item_or_items)
return [item_or_items] | def make_list(item_or_items) | Makes a list out of the given items.
Examples:
>>> make_list(1)
[1]
>>> make_list('str')
['str']
>>> make_list(('i', 'am', 'a', 'tuple'))
['i', 'am', 'a', 'tuple']
>>> print(make_list(None))
None
>>> # An instance of lists is unchanged
... | 1.567538 | 1.640435 | 0.955563 |
def _decorator(cls):
def __str__(self):
items = ["{name}={value}".format(
name=name,
value=vars(self)[name].__repr__()
) for name in [key for key in sorted(vars(self))]
if name not in get_field_mro(self.__class__, '__auto_str_ignor... | def auto_str(__repr__=False) | Use this decorator to auto implement __str__() and optionally __repr__() methods on classes.
Args:
__repr__ (bool): If set to true, the decorator will auto-implement the __repr__() method as
well.
Returns:
callable: Decorating function.
Note:
There are known issues wit... | 3.216005 | 3.474835 | 0.925513 |
def _decorator(cls):
ignored = make_list(ignore_list)
cls.__auto_str_ignore__ = ignored
return cls
return _decorator | def auto_str_ignore(ignore_list) | Use this decorator to suppress any fields that should not be part of the dynamically created
`__str__` or `__repr__` function of `auto_str`.
Args:
ignore_list: List or item of the fields to suppress by `auto_str`.
Returns:
Returns a decorator.
Example:
>>> @auto_str()
... | 4.415748 | 7.195015 | 0.613723 |
request_major_version = get_major_version(work_request.version)
local_major_version = get_major_version(local_version)
if request_major_version != local_major_version:
raise ValueError("Received major version mismatch. request:{} local:{}".format(
work_request.version, local_version... | def raise_on_major_version_mismatch(work_request, local_version) | Raises error if major version is different. Other wise logs the difference.
:param work_request: WorkRequest: request that had a different version
:param local_version: str: our version string that does not match message.version | 2.545496 | 2.55929 | 0.99461 |
logging.info("Connecting to {} with user {}.".format(self.host, self.username))
credentials = pika.PlainCredentials(self.username, self.password)
connection_params = pika.ConnectionParameters(host=self.host,
credentials=credentials,
... | def connect(self) | Create internal connection to AMQP service. | 2.292407 | 2.088607 | 1.097577 |
if self.connection:
logging.info("Closing connection to {}.".format(self.host))
self.connection.close()
self.connection = None | def close(self) | Close internal connection to AMQP if connected. | 3.718636 | 3.070153 | 1.211222 |
channel = self.connection.channel()
channel.queue_declare(queue=queue_name, durable=True)
return channel | def create_channel(self, queue_name) | Create a chanel named queue_name. Must be connected before calling this method.
:param queue_name: str: name of the queue to create
:return: pika.channel.Channel: channel we can send/receive messages to/from | 2.074667 | 2.273435 | 0.912569 |
self.connect()
channel = self.connection.channel()
channel.queue_delete(queue=queue_name)
self.close() | def delete_queue(self, queue_name) | Delete a queue with the specified name.
:param queue_name:
:return: | 2.839251 | 2.963605 | 0.958039 |
self.connect()
channel = self.create_channel(queue_name)
channel.basic_publish(exchange='',
routing_key=queue_name,
body=body,
properties=pika.BasicProperties(
deli... | def send_durable_message(self, queue_name, body) | Connect to queue_name, post a durable message with body, disconnect from queue_name.
:param queue_name: str: name of the queue we want to put a message on
:param body: content of the message we want to send | 2.015804 | 2.041258 | 0.98753 |
self.connect()
channel = self.connection.channel()
# Fanout will send message to multiple subscribers
channel.exchange_declare(exchange=exchange_name, type='fanout')
result = channel.basic_publish(exchange=exchange_name, routing_key='', body=body,
... | def send_durable_exchange_message(self, exchange_name, body) | Send a message with the specified body to an exchange.
:param exchange_name: str: name of the exchange to send the message into
:param body: str: contents of the message
:return Bool: True when delivery confirmed | 2.380969 | 2.34304 | 1.016188 |
self.connect()
channel = self.create_channel(queue_name)
channel.basic_qos(prefetch_count=1)
channel.basic_consume(callback, queue=queue_name)
channel.start_consuming() | def receive_loop_with_callback(self, queue_name, callback) | Process incoming messages with callback until close is called.
:param queue_name: str: name of the queue to poll
:param callback: func(ch, method, properties, body) called with data when data arrives
:return: | 2.129242 | 2.131561 | 0.998912 |
request = WorkRequest(command, payload)
logging.info("Sending {} message to queue {}.".format(request.command, self.queue_name))
# setting protocol to version 2 to be compatible with python2
self.connection.send_durable_message(self.queue_name, pickle.dumps(request, protocol=2))... | def send(self, command, payload) | Send a WorkRequest to containing command and payload to the queue specified in config.
:param command: str: name of the command we want run by WorkQueueProcessor
:param payload: object: pickable data to be used when running the command | 4.637219 | 4.312369 | 1.07533 |
func = getattr(obj, command)
if func and callable(func):
self.add_command(command, func)
else:
raise ValueError("Object missing {} method.".format(command)) | def add_command_by_method_name(self, command, obj) | Lookup method named command in obj and call that method when the command is received.
Raises ValueError if obj doesn't have a method named command
:param command: str: name of the comand to wait for
:param obj: object: must have a member function with the exact name of the command | 3.92064 | 3.635883 | 1.078319 |
logging.info("Work queue shutdown.")
self.connection.close()
self.receiving_messages = False | def shutdown(self, payload=None) | Close the connection/shutdown the messaging loop.
:param payload: None: not used. Here to allow using this method with add_command. | 14.379121 | 14.593481 | 0.985311 |
self.receiving_messages = True
try:
self.process_messages_loop_internal()
except pika.exceptions.ConnectionClosed as ex:
logging.error("Connection closed {}.".format(ex))
raise | def process_messages_loop(self) | Processes incoming WorkRequest messages one at a time via functions specified by add_command. | 4.971996 | 4.509669 | 1.102519 |
logging.info("Starting work queue loop.")
self.connection.receive_loop_with_callback(self.queue_name, self.process_message) | def process_messages_loop_internal(self) | Busy loop that processes incoming WorkRequest messages via functions specified by add_command.
Terminates if a command runs shutdown method | 10.873353 | 10.159943 | 1.070218 |
self.work_request = pickle.loads(body)
ch.basic_ack(delivery_tag=method.delivery_tag)
self.process_work_request() | def process_message(self, ch, method, properties, body) | Callback method that is fired for every message that comes in while we are in process_messages_loop.
:param ch: channel message was sent on
:param method: pika.Basic.Deliver
:param properties: pika.BasicProperties
:param body: str: payload of the message (picked WorkRequest) | 3.275855 | 2.702516 | 1.21215 |
while self.receiving_messages:
# connect to AMQP server and listen for 1 message then disconnect
self.work_request = None
self.connection.receive_loop_with_callback(self.queue_name, self.save_work_request_and_close)
if self.work_request:
s... | def process_messages_loop_internal(self) | Busy loop that processes incoming WorkRequest messages via functions specified by add_command.
Disconnects while servicing a message, reconnects once finished processing a message
Terminates if a command runs shutdown method | 8.178544 | 7.357777 | 1.111551 |
self.work_request = pickle.loads(body)
ch.basic_ack(delivery_tag=method.delivery_tag)
ch.stop_consuming()
self.connection.close() | def save_work_request_and_close(self, ch, method, properties, body) | Save message body and close connection | 2.363763 | 2.272537 | 1.040143 |
result = self.connection.send_durable_exchange_message(self.exchange_name, payload)
logging.info("Sent message to exchange.".format(self.exchange_name))
return result | def send(self, payload) | Send a payload to exchange to containing command and payload to the queue specified in config.
:param command: str: name of the command we want run by WorkQueueProcessor
:param payload: str: string data that will be put into the exchange's message body
:return Bool: True when delivery confirmed | 5.270658 | 6.159572 | 0.855686 |
# just get the first cat. If they assigned to more than one, tough
try:
cat = gallery.sections.all()[0]
related = cat.gallery_categories.filter(published=True).exclude(id=gallery.id).order_by('-id')[:count]
except:
related = None
return {'related': related, 'MEDIA_URL': sett... | def get_related_galleries(gallery, count=5) | Gets latest related galleries from same section as originating gallery.
Count defaults to five but can be overridden.
Usage: {% get_related_galleries gallery <10> %} | 5.998614 | 6.673367 | 0.898889 |
return MessageRouter(config, obj, queue_name, VM_LANDO_INCOMING_MESSAGES,
processor_constructor=WorkQueueProcessor) | def make_lando_router(config, obj, queue_name) | Makes MessageRouter which can listen to queue_name sending messages to the VM version of lando.
:param config: WorkerConfig/ServerConfig: settings for connecting to the queue
:param obj: object: implements lando specific methods
:param queue_name: str: name of the queue we will listen on.
... | 19.599886 | 20.358229 | 0.96275 |
return MessageRouter(config, obj, queue_name, K8S_LANDO_INCOMING_MESSAGES,
processor_constructor=WorkQueueProcessor) | def make_k8s_lando_router(config, obj, queue_name) | Makes MessageRouter which can listen to queue_name sending messages to the k8s version of lando.
:param config: WorkerConfig/ServerConfig: settings for connecting to the queue
:param obj: object: implements lando specific methods
:param queue_name: str: name of the queue we will listen on.
... | 14.860269 | 16.472963 | 0.902101 |
return MessageRouter(config, obj, queue_name, VM_LANDO_WORKER_INCOMING_MESSAGES,
processor_constructor=DisconnectingWorkQueueProcessor) | def make_worker_router(config, obj, queue_name) | Makes MessageRouter which can listen to queue_name sending lando_worker specific messages to obj.
:param config: WorkerConfig/ServerConfig: settings for connecting to the queue
:param obj: object: implements lando_worker specific methods
:param queue_name: str: name of the queue we will listen o... | 29.740351 | 20.709227 | 1.436092 |
self.load_default_healthchecks()
if getattr(settings, 'AUTODISCOVER_HEALTHCHECKS', True):
self.autodiscover_healthchecks()
self._registry_loaded = True | def load_healthchecks(self) | Loads healthchecks. | 4.696453 | 4.388276 | 1.070227 |
default_healthchecks = getattr(settings, 'HEALTHCHECKS', DEFAULT_HEALTHCHECKS)
for healthcheck in default_healthchecks:
healthcheck = import_string(healthcheck)
self.register_healthcheck(healthcheck) | def load_default_healthchecks(self) | Loads healthchecks specified in settings.HEALTHCHECKS as dotted import
paths to the classes. Defaults are listed in `DEFAULT_HEALTHCHECKS`. | 2.86092 | 1.987697 | 1.439314 |
if not self._registry_loaded:
self.load_healthchecks()
def get_healthcheck_name(hc):
if hasattr(hc, 'name'):
return hc.name
return hc.__name__
responses = []
for healthcheck in self._registry:
try:
... | def run_healthchecks(self) | Runs all registered healthchecks and returns a list of
HealthcheckResponse. | 2.268891 | 2.063101 | 1.099748 |
def actual_decorator(func):
return _cached_func(func, caches.RRCache, max_size)
return actual_decorator | def rr_cache(max_size=128) | Random Replacement cache decorator, implementing :class:`faste.caches.RRCache`
:keyword int max_size: max cache size | 7.988614 | 5.895175 | 1.355111 |
def actual_decorator(func):
return _cached_func(func, caches.LRUCache, max_size)
return actual_decorator | def lru_cache(max_size=128) | Least Recently Used cache decorator, implementing :class:`faste.caches.LRUCache`
:keyword max_size: max cache size | 6.566652 | 5.735821 | 1.14485 |
def actual_decorator(func):
return _cached_func(func, caches.LFUCache, max_size)
return actual_decorator | def lfu_cache(max_size=128) | Least Frequently Used cache decorator, implementing :class:`faste.caches.LFUCache`
:keyword max_size: max cache size | 7.057395 | 5.272836 | 1.338444 |
def actual_decorator(func):
return _cached_func(func, caches.TimeoutCache, timeout, max_size=max_size)
return actual_decorator | def timed_cache(timeout, max_size=128) | Time based decorator, implementing :class:`faste.caches.TimeoutCache`
:param int timeout: Cache key timeout
:param int max_size: (keyword) max size. | 7.133256 | 5.231358 | 1.363557 |
if amount < 0:
raise ValueError("cannot retreat time reference: amount {} < 0"
.format(amount))
self.__delta += amount | def advance_by(self, amount) | Advance the time reference by the given amount.
:param `float` amount: number of seconds to advance.
:raise `ValueError`: if *amount* is negative. | 12.698749 | 12.403062 | 1.02384 |
now = self.__original_time()
if timestamp < now:
raise ValueError("cannot retreat time reference: "
"target {} < now {}"
.format(timestamp, now))
self.__delta = timestamp - now | def advance_to(self, timestamp) | Advance the time reference so that now is the given timestamp.
:param `float` timestamp: the new current timestamp.
:raise `ValueError`: if *timestamp* is in the past. | 9.467162 | 9.072498 | 1.043501 |
if job_request_payload.success_command == JobCommands.STORE_JOB_OUTPUT_COMPLETE:
raise ValueError("Programmer error use use job_step_store_output_complete instead.")
payload = JobStepCompletePayload(job_request_payload)
self.send(job_request_payload.success_command, payload) | def job_step_complete(self, job_request_payload) | Send message that the job step is complete using payload data.
Raises ValueError if used for StoreJobOutputPayload message type.
:param job_request_payload: StageJobPayload|RunJobPayload payload from complete job | 8.392804 | 6.950955 | 1.207432 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.