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

A python wrapper for the GitLab API.

License

NotificationsYou must be signed in to change notification settings

python-gitlab/python-gitlab

Repository files navigation

python-gitlab is a Python package providing access to the GitLab server API.

It supports the v3 api of GitLab.

A CLI tool is also provided (calledgitlab).

Installation

Requirements

python-gitlab depends on:

Install with pip

pip install python-gitlab

State

python-gitlab is considered stable.

Bugs reports

Please report bugs and feature requests athttps://github.com/gpocentek/python-gitlab/issues

Documentation

Work In Progress:http://python-gitlab.readthedocs.org/en/latest/

Patches are welcome!

Code snippet

# See https://github.com/gitlabhq/gitlabhq/tree/master/doc/api for the source.fromgitlabimportGitlab# Register a connection to a gitlab instance, using its URL and a user private# tokengl=Gitlab('http://192.168.123.107','JVNSESs8EwWRx5yDxM5q')# Connect to get the current usergl.auth()# Print the user informationsprint(gl.user)# Get a list of projectsforpingl.Project():print(p.name)# get associated issuesissues=p.Issue()forissueinissues:closed=0ifnotissue.closedelse1print("  %d => %s (closed: %d)"% (issue.id,issue.title,closed))# and close them allissue.state_event="close"issue.save()# Get the first 10 groups (pagination)forgingl.Group(page=1,per_page=10):print(g)# To use pagination and retrieve all the itemsforgingl.Group(all=True):print(g)# Create a new project (as another_user)p=gl.Project({'name':'myCoolProject','wiki_enabled':False})p.save(sudo="another_user")print(p)

Command line use

To use the command line tool, you need to define which GitLab server(s) can beaccessed. this can be done in 2 files:

  • /etc/python-gitlab.cfg
  • ~/.python-gitlab.cfg

Here's an example of the syntax:

[global]# required settingdefault = local# optional settingsssl_verify = truetimeout = 5[local]url = http://10.0.3.2:8080# get the private token from the gitlab web interfaceprivate_token = vTbFeqJYCY3sibBP7BZM[remote]url = https://some.whe.reprivate_token = thisisaprivatetokenssl_verify = false

The [global] section defines which server is accessed by default.Each other section defines how to access a server. Only private tokenauthentication is supported (not user/password).

Thessl_verify option defines if the server SSL certificate should bevalidated (use false for self signed certificates, only useful with https).

Thetimeout option defines after how many seconds a request to the Gitlabserver should be abandonned.

Choosing a different server than the default one can be done at run time:

gitlab --gitlab=remote [command]

gitlab always requires 2 mandatory arguments.

The first argument is the object type on which we will act, the second one isthe action:

gitlab project list

Get help with:

# global helpgitlab --help# object helpgitlab project --help

Some examples:

# list all the projects:gitlab project list# limit to 5 items per request, display the 1st page onlygitlab project list --page=1 --per-page=5# get a specific project (id 2):gitlab project get --id=2# get a list of snippets for this project:gitlab project-issue list --project-id=2# delete a Snippet (id 3):gitlab project-snippet delete --id=3 --project-id=2# update a Snippet:gitlab project-snippet update --id=4 --project-id=2 --code="My New Code"# create a Snippet:gitlab project-snippet create --project-id=2Impossible to create object (Missing attribute(s): title, file-name, code)# oops, let's add the attributes:gitlab project-snippet create --project-id=2 --title="the title" --file-name="the name" --code="the code"

[8]ページ先頭

©2009-2025 Movatter.jp