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

Commit c5f99d5

Browse files
committed
#4 Content sync
Signed-off-by: Uilian Ries <uilianries@gmail.com>
1 parent 2f47a79 commit c5f99d5

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

bintray/bintray.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,3 +610,39 @@ def gpg_sign_file(self, subject, repo, file_path, key_subject=None, passphrase=N
610610

611611
self._logger.info("Sign successfully: {}".format(url))
612612
return response
613+
614+
# Content Sync
615+
616+
def sync_version_artifacts_to_maven_central(self, subject, repo, package, version, username,
617+
password, close="1"):
618+
""" Sync version files to a oss.sonatype.org staging repository to publish these files to
619+
Maven Central.
620+
621+
Once Sonatype oss credentials have been set in subject "Accounts" tab, user can send
622+
this rest call without specifying username and password (or use different
623+
username/password by specifying them in JSON body)
624+
625+
By default the staging repository is closed and artifacts are released to Maven Central.
626+
You can optionally turn this behaviour off and release the version manually.
627+
This is achieved by passing 0 in the 'close' field of the JSON passed to the call.
628+
629+
Security: Authenticated user with 'publish' permission.
630+
631+
:param subject: username or organization
632+
:param repo: repository name
633+
:param package: package name
634+
:param version: package version
635+
:param username: Sonatype OSS user token
636+
:param password: Sonatype OSS user password
637+
:param close: staging repository mode
638+
:return: request response
639+
"""
640+
url = "{}/maven_central_sync/{}/{}/{}/versions/{}".format(Bintray.BINTRAY_URL, subject,
641+
repo, package, version)
642+
body = {
643+
'username': username,
644+
'password': password,
645+
'close': close
646+
}
647+
648+
return self._requester.post(url, json=body)

tests/test_content_signing.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# -*- coding: utf-8 -*-
22

3-
import os
43
from bintray.bintray import Bintray
54

65

tests/test_content_sync.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from bintray.bintray import Bintray
4+
5+
6+
def test_sync_version_artifacts_to_maven_central():
7+
bintray = Bintray()
8+
error_message = ""
9+
try:
10+
bintray.sync_version_artifacts_to_maven_central("uilianries", "generic", "statistics",
11+
"test", "username", "password")
12+
except Exception as error:
13+
error_message = str(error)
14+
15+
assert "Could not POST (403): 403 Client Error: Forbidden for url: " \
16+
"https://api.bintray.com/maven_central_sync/uilianries/generic/statistics/versions/test"\
17+
== error_message

0 commit comments

Comments
 (0)