インストールと紹介
$ conda activate env
$ (env) pip install python-gitlab
# test.py
import gitlab
入門
gitlab.Gitlab
はプライマリクラスであり、HTTPリクエストを処理します。GitLabのURLと認証情報を保持します
。APIを使用する前に、プロジェクト、グループ、ユーザー、コミット、CICDなどの概念を理解しておくことをお勧めします。
デモから始める
# git账户的token
private_token = "onlyidiotwilltrythistoken" # https://my.oschina.net/u/4308934/blog/3365888
# git地址
private_host = 'https://gitlab.com'
class Projects:
# 获取基本信息
def __init__(self, private_token):
self.gl = gitlab.Gitlab(private_host, private_token=private_token)
# 获取该用户的所有
self.projects = self.gl.projects.list(
membership=True,
all=True,
)
self.groups = self.gl.groups.list(
membership=True,
all=True,
)
詳細
事業
1.プロパティ
{
'id': 223753,
'description': '',
'name': 'test_project1',
'name_with_namespace': 'sjtu-biggie / test_project1',
'path': 'test_project1',
'path_with_namespace': 'sjtu-biggie/test_project1',
'created_at': '2021-01-20T03:30:44.015Z',
'default_branch': 'master',
'tag_list': [],
'ssh_url_to_repo': '[email protected]:sjtu-biggie/test_project1.git',
'http_url_to_repo': 'https://gitlab.com/sjtu-biggie/test_project1.git', 'web_url': 'https://gitlab.com/sjtu-biggie/test_project1', 'readme_url': 'https://gitlab.com/sjtu-biggie/test_project1/-/blob/master/README.md',
'last_activity_at': '2021-01-20T03:30:44.015Z',
'namespace': {
'id': 6122086, 'name': 'sjtu-biggie', 'path': 'sjtu-biggie', 'kind': 'user', 'full_path': 'sjtu-biggie', 'parent_id': None, 'avatar_url': 'https://secure.gravatar.com/avatar/6aasdsd5a758cc3e3f80a716ad8cb?s=80&d=identicon', 'web_url':'https://gitlab.com/sjtu-biggie'},
'empty_repo': False,
'archived': False,
'visibility': 'public',
'owner': {
'id': 4661627, 'name': 'sjtu-biggie', 'username': 'sjtu-biggie', 'state': 'active', 'avatar_url': 'https://secure.gravatar.com/avatar/6ac582asdds58cc3e3f80a716ad8cb?s=80&d=identicon', 'web_url': 'https://gitlab.com/sjtu-biggie'},
2.表示される操作
gl.project.list()
は公開プロジェクトであり
gl.project.list(membership=True,all=True)
、関連するすべてのプロジェクトが表示されます。インターングループに所属している場合は、プロジェクトメンバーでなくても、intern /の下にあるすべてのプロジェクトが一覧表示されます。 。
3.プロジェクトを作成します
project = myProject.gl.projects.create({
'name':'test_project2'})
インポート・エクスポート
export = project.exports.create()
export.refresh()
while export.export_status != 'finished':
time.sleep(1)
export.refresh()
# Download the result
with open('repo/export.tgz', 'wb') as f:
export.download(streamed=True, action=f.write)
コミット
1.プロパティ
{
'id': '6b1bbec7bbdfas7d6c7ce499ce714e2e71fa2eb',
'short_id': '6b1sdaec7',
'created_at': '2021-01-10T03:30:44.000+00:00',
'parent_ids': [],
'title': 'Initial commit',
'message': 'Initial commit',
'author_name': 'sjtu-biggie',
'author_email': '[email protected]',
'authored_date': '2021-01-10T03:30:44.000+00:00',
'committer_name': 'sjtu-biggie',
'committer_email': '[email protected]',
'committed_date': '2021-01-10T03:30:44.000+00:00',
'web_url': 'https://gitlab.com/sjtu-biggie/test_project1/-/commit/6b1bbec7bbbb7b1asdsd9ce714e2e71fa2eb'
}
ブランチ
1.プロパティ
{
'name': 'test_branch',
'commit': {
'id': '980b816c1129bb37ca58081bef484fec69d6ddd7',
'short_id': '980b816c', 'created_at': '2021-01-20T05:53:47.000+00:00',
'parent_ids': None,
'title': 'Add new file',
'message': 'Add new file',
'author_name': 'sjtu-biggie',
'author_email': '[email protected]',
'authored_date': '2021-01-20T05:53:47.000+00:00',
'committer_name': 'sjtu-biggie',
'committer_email': '[email protected]',
'committed_date': '2021-01-20T05:53:47.000+00:00',
'web_url': 'https://gitlab.com/sjtu-biggie/test_project1/-/commit/980b816c1129bb37ca58081bef484fec69d6ddd7'
}
メンバー
1.プロパティ
{
'id': 12345,
'name': 'sjtu',
'username': 'sjtu',
'state': 'active',
'avatar_url': 'https://secure.gravatar.com/avatar/6ac582858d5a758cc3e3f80a716ad8cb?s=80&d=identicon',
'web_url': 'https://gitlab.com/sjtu',
'access_level': 30,
'created_at': '2021-01-25T06:47:26.231Z',
'expires_at': None
}
memberはgroup.memberまたはproject.memberにすることができ、グループ/プロジェクトを終了するために
呼び出すことができますmember.delete()