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

Commit

Permalink
#4 Content sync (#31)
Browse files Browse the repository at this point in the history
#4 Content sync
  • Loading branch information
uilianries committed Jul 12, 2019
2 parents 2f47a79 + c5f99d5 commit 8c19a94
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
36 changes: 36 additions & 0 deletions bintray/bintray.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,3 +610,39 @@ def gpg_sign_file(self, subject, repo, file_path, key_subject=None, passphrase=N

self._logger.info("Sign successfully: {}".format(url))
return response

# Content Sync

def sync_version_artifacts_to_maven_central(self, subject, repo, package, version, username,
password, close="1"):
""" Sync version files to a oss.sonatype.org staging repository to publish these files to
Maven Central.
Once Sonatype oss credentials have been set in subject "Accounts" tab, user can send
this rest call without specifying username and password (or use different
username/password by specifying them in JSON body)
By default the staging repository is closed and artifacts are released to Maven Central.
You can optionally turn this behaviour off and release the version manually.
This is achieved by passing 0 in the 'close' field of the JSON passed to the call.
Security: Authenticated user with 'publish' permission.
:param subject: username or organization
:param repo: repository name
:param package: package name
:param version: package version
:param username: Sonatype OSS user token
:param password: Sonatype OSS user password
:param close: staging repository mode
:return: request response
"""
url = "{}/maven_central_sync/{}/{}/{}/versions/{}".format(Bintray.BINTRAY_URL, subject,
repo, package, version)
body = {
'username': username,
'password': password,
'close': close
}

return self._requester.post(url, json=body)
1 change: 0 additions & 1 deletion tests/test_content_signing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-

import os
from bintray.bintray import Bintray


Expand Down
17 changes: 17 additions & 0 deletions tests/test_content_sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-

from bintray.bintray import Bintray


def test_sync_version_artifacts_to_maven_central():
bintray = Bintray()
error_message = ""
try:
bintray.sync_version_artifacts_to_maven_central("uilianries", "generic", "statistics",
"test", "username", "password")
except Exception as error:
error_message = str(error)

assert "Could not POST (403): 403 Client Error: Forbidden for url: " \
"https://api.bintray.com/maven_central_sync/uilianries/generic/statistics/versions/test"\
== error_message

0 comments on commit 8c19a94

Please sign in to comment.