python-gitlab | A python wrapper for the GitLab API | REST library
kandi X-RAY | python-gitlab Summary
kandi X-RAY | python-gitlab Summary
A python wrapper for the GitLab API.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Create a new package
- Build the url
- Make a HTTP request
- Make a HTTP PUT request
- Parses the config file
- Decode the message
- Gets values from helper
- Create a Gitlab instance
- Merge auth options
- Create a new commit status
- Get an object by id
- Extend argument parser
- Return an argument parser
- Share a group
- Download files from Gitlab
- Get the content of the object
- Merge this branch
- Get the content of the snippet
- Set a feature
- Upload a file
- Get the raw artifact at the given path
- Download a file from Gitlab
- Returns a list of configuration files
- Get the status of the object
- Get the contents of the artifact
- Update an object
python-gitlab Key Features
python-gitlab Examples and Code Snippets
import gitlab
gl = gitlab.Gitlab.from_config()
# list all users.
for user in gl.users.list(all=True):
print(f'{user.id}\t{user.name}\t{user.email}')
# list all groups and projects.
for group in gl.groups.list(all=True):
print(f'{group.id}\
default:
image:
name: registry.gitlab.com/gitlabracadabra/gitlabracadabra:v1.2.0
entrypoint: [""]
before_script:
- |
cat << EOF > ~/.python-gitlab.cfg
[global]
default = gitlab
[gitlab]
[global]
default = gitlab
[gitlab]
url = https://gitlab.com
private_token = T0K3N
Community Discussions
Trending Discussions on python-gitlab
QUESTION
I'm writing a python module to create projects in gitlab, but I can't figure out how to change the default project settings, like remove_source_branch_after_merge
.
I've tried passing the argument to the projects.create()
call, but it seems to be ignored.
ANSWER
Answered 2022-Mar-09 at 12:34To answer your question, modifying attributes after an object has been created can be done with save()
:
QUESTION
I found https://github.com/python-gitlab/python-gitlab, but I was unable to understand the examples in the doc.
...ANSWER
Answered 2021-Dec-15 at 17:58Looking at python-gitlab
, I don't see some of the things you are looking for. In that case, I suggest you break it apart and do the individual steps using more basic tools and libraries.
The first two parts you don't need to use Gitlab API to do. You can basically use Python to do the clone, branch, edit, and commit calls using git.exe
and against your disk. In some ways, that is easier since you can duplicate the calls yourself. You could use GitPython.
I'd recommend you do that through one of these methods instead of trying to do it via Gitlab API. It's easier to understand, debug, and investigate if you do the branch work locally (or even inside a CI).
Once you push up the code into a branch, you can use Gitlab's API to create a merge request via REST (such as the requests
library). The description for creating the MR is at https://docs.gitlab.com/ee/api/merge_requests.html#create-mr and most of the fields are optional so the minimum looks like:
QUESTION
I try to download build artifacts from a CI/CD pipeline by using the GitLab API for Python. I took a look at the documentation and wrote the following example:
...ANSWER
Answered 2021-Nov-13 at 21:26The distinction here is subtle. Using pipeline.jobs.list
doesn't use the same underlying API as project.jobs.list
(or .get
)
In terms of the Python-Gitlab library, when you do pipeline.jobs.list()
you get a list of gitlab.v4.objects.ProjectPipelineJob
objects. The .artifacts
attribute of this type of object is not a method -- it's an a list containing information about the artifacts, like file type, size file name, etc -- which is what you're seeing in your image.
This is different from a gitlab.v4.objects.ProjectJob
object, which is what is shown in the documentation. You obtain this kind of object from project.jobs.get
or project.jobs.list
.
So, to correct this error you can edit the tail end of your code as follows:
QUESTION
ANSWER
Answered 2021-Nov-07 at 00:40The first argument to gitlab.Gitlab()
is the base URL of the instance not the full path to your project. e.g. https://gitlab.example.com
. You should also use the keyword private_token
So, unless your instance lives at a relative path, you should have:
QUESTION
I'm tasked with migrating repos to gitlab and I decided to automate the process using python-gitlab. Everything works fine except for binary or considered-binary files like compiled object files ( .o ) or .zip files. (I know that repositories are not place for binaries. I work with what I got and what I'm told to do.)
I'm able to upload them using:
...ANSWER
Answered 2021-Nov-03 at 18:46The problem is that Python's base64.b64encode
function will provide you with a bytes object, but REST APIs (specifically, JSON serialization) want strings. Also the argument you want is encoding
not encode
.
Here's the full example to use:
QUESTION
My end goal is to have an offline, updateable copy of my snippets (including title & description) such that I can search and use them easily. How can I get all my snippets from Gitlab to my local machine?
I'm using Gitlab version is 13.12.10-ee
.
It's possible to clone snippet contents in Gitlab, but this only includes the file associated with the snippet. The title and description are excluded.
E.g. when I do git clone git@company.gitlab.com:snippets/$snippet_id.git
I only receive the files associated with the snippet, not the title and the description:
I've checked the documentation but could not find any mention of interacting with the description through git.
Gitlab APII found that the Gitlab API has a snippets endpoint. However, when I use the python-gitlab CLI tool and request a single snippet with gitlab snippet get --id 123
I only get the ID and the title.
When I do gitlab snippet content --id 123
I only get the contents of the file associated with the snippet.
ANSWER
Answered 2021-Oct-25 at 22:32QUESTION
My goal is to upload a small layer for an aws lambda function using the python 3.7 runtime that stores python dependencies, but I cannot seem to get it to recognize the modules.
I created a Makefile to generate the zip file
...ANSWER
Answered 2021-Sep-09 at 21:59I had this SAME problem and it took me a week to solve. I think this answer can help you: Import libraries in lambda layers
Here is the key stuff:
You want to make sure your .zip follows this folder structure when unzipped
python/lib/python3.6/site-packages/{LibrariesGoHere}.
Upload that zip, make sure the layer is added to the Lambda function and you should be good to go.
Also, I think your question would get better attention if you update your tag to "aws-lambda-layers"
QUESTION
I'm trying to add a gitlab group to a project after the project is created. I can see in the Gitlab API documentation that it's possible to invite a MEMBER to a group to or a project (https://docs.gitlab.com/ee/api/invitations.html)
It's however possible to invite a group to a project from the Gitlab Dashboard when navigating the Members menu, under Project information.
How would I go about adding a group to a project after it is created using the python-gitlab API?
...ANSWER
Answered 2021-Jul-28 at 17:01I found the solution at https://python-gitlab.readthedocs.io/en/stable/gl_objects/projects.html#project-members
It is important to note the Gitlab have two types for projects as stated in https://python-gitlab.readthedocs.io/en/stable/gl_objects/groups.html#group-members
GroupProject objects returned by this API call are very limited, and do not provide all the features of Project objects. If you need to manipulate projects, create a new Project object:
QUESTION
Im using https://github.com/python-gitlab/python-gitlab to automate several tasks over multiple Gitlab repositories / projects. This worked fine up until now: I have a Gitlab project and want to get its parent group. According to https://docs.gitlab.com/13.12/ee/api/projects.html#list-a-projects-groups this should be possible, but I cannot find that functionality in the Python bindings.
Am I missing something? Is that feature missing in the Python bindings? Does anybody know a workaround, that does not force me to got to "pure" REST?
...ANSWER
Answered 2021-Jun-22 at 16:57After reading the code it looks like the feature is just missing, but I figured out a workaround:
QUESTION
I use the python-gitlab module to retrieve the project statistics for a number of projects in Gitlab via its API. One of the values I want to get is the CI status and the code coverage. While the status is easy:
...ANSWER
Answered 2021-Jun-07 at 08:48This is in the pipeline
object:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install python-gitlab
You can use python-gitlab like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page