Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
#5 Create repository
Browse files Browse the repository at this point in the history
Signed-off-by: Uilian Ries <uilianries@gmail.com>
  • Loading branch information
uilianries committed Jul 13, 2019
1 parent 41131cf commit b45ad8f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
59 changes: 59 additions & 0 deletions bintray/bintray.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,3 +673,62 @@ def get_repository(self, subject, repo):
"""
url = "{}/repos/{}/{}".format(Bintray.BINTRAY_URL, subject, repo)
return self._requester.get(url)

def create_repository(self, subject, repo, type, description, private=False, labels=None,
gpg_sign_metadata=False, gpg_sign_files=False, gpg_use_owner_key=False,
business_unit=None, version_update_max_days=None):
""" Create a repository under to the specified subject.
The possible types for a repository are: maven, debian, conan, rpm, docker, npm, opkg,
nuget, vagrant and generic (default).
GPG auto sign flags - they let you specify whether GPG signing should be applied to this
repo. auto signing with gpg is disabled by default.
:param subject:
:param repo:
:param type:
:param private:
:param description:
:param labels:
:param gpg_sign_metadata: if set to true then the repo’s metadata will be automatically
signed with Bintray GPG key.
:param gpg_sign_files: if set to true then the repo’s files will be automatically signed
with Bintray GPG key.
:param gpg_use_owner_key: if set to true then the repo’s metadata and files will be signed
automatically with the owner’s GPG key. this flag cannot be set
true simultaneously with either of the bintray key falgs (files or
metadata). this flag can be set true only if the repo’s owner
supplied a private (and public) GPG key on his bintray profile.
:param business_unit: can be associated to repositories allowing you to monitor overall
usage per business unit.
:param version_update_max_days: Number of days after the version is published in which an
organization member can upload, override or delete files in
the version, delete the version or its package. After this
period these actions are not available to the member.
This does not apply to the Admin of the repository who can
make changes to the version at any time after it is published
:return: Request response
"""
assert isinstance(private, bool), "private must be a boolean value [True, False]"
url = "{}/repos/{}/{}".format(Bintray.BINTRAY_URL, subject, repo)
json_data = {
'name': repo,
'type': type,
'private': private,
'desc': description,
'gpg_sign_metadata': gpg_sign_metadata,
'gpg_sign_files': gpg_sign_files,
'gpg_use_owner_key': gpg_use_owner_key
}
if labels:
assert isinstance(labels, list), "labels must be a list e.g. ['label1', 'label2']"
json_data['labels'] = labels
if business_unit:
json_data['business_unit'] = business_unit
if isinstance(version_update_max_days, int) or version_update_max_days:
json_data['version_update_max_days'] = int(version_update_max_days)

response = self._requester.post(url, json=json_data)
self._logger.info("Repository {} created successfully".format(repo))
return response
11 changes: 11 additions & 0 deletions tests/test_repositories.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

import random
from bintray.bintray import Bintray


Expand All @@ -15,3 +16,13 @@ def test_get_repository():
assert response.get("error") == False
assert response.get("statusCode") == 200
assert response.get("owner") == "conan"


def test_create_repo():
bintray = Bintray()
repo = "test_{}".format(random.randint(1,100000))
response = bintray.create_repository("uilianries", repo, "generic", "only for test",
labels=["foo", "bar"], business_unit="foobar")
assert "created" in response.keys()
assert response.get("error") == False
assert response.get("name") == repo

0 comments on commit b45ad8f

Please sign in to comment.