示例#1
0
def check_repo_exists(username, password, workspace, slug):

    bitbucket_cloud = Cloud(url='https://api.bitbucket.org/',
                            username=username,
                            password=password,
                            cloud=True)
    exists = False
    while True:
        try:
            bitbucket_cloud.workspaces.get(workspace).repositories.get(slug)
            exists = True
        except requests.HTTPError as e:
            if e.response.status_code in (404, ):
                exists = False
                logging.debug(
                    f'Repository "{slug}" does not exist in Bitbucket Cloud workspace "{workspace}". Creating...'
                )
            elif e.response.status_code in (401, 500, 503):
                logging.error(
                    f'Failed to retrieve repository "{slug}" from Bitbucket Cloud! Service unavailable or user may not have permission.'
                )
                raise e
            elif e.response.status_code in (429, ):
                logging.info("Got Throttle checking:" + slug)
                time.sleep(random.randrange(5.0, 10.0))
                continue
        return exists
示例#2
0
def get_workspaces(token):
    oauth2 = {"client_id": client_id, "token": token}

    bitbucket = Cloud(url="https://api.bitbucket.org/",
                      oauth2=oauth2,
                      cloud=True)

    return [ws.name for ws in bitbucket.workspaces.each()]
from atlassian import Bitbucket
from atlassian.bitbucket import Cloud
from atlassian.bitbucket.cloud.common.users import User
from atlassian.bitbucket.cloud.repositories.pullRequests import Comment, Participant, PullRequest, Build, Task

BITBUCKET = None
try:
    from .mockup import mockup_server

    BITBUCKET = Bitbucket("{}/bitbucket/cloud".format(mockup_server()),
                          username="******",
                          password="******",
                          cloud=True)
    CLOUD = Cloud("{}/bitbucket/cloud".format(mockup_server()),
                  username="******",
                  password="******")
except ImportError:
    pass


def _datetimetostr(dtime):
    # convert datetime object to str because datetime.timezone is not available in py27
    # doesn't work on py27: datetime(2020, 12, 27, 14, 9, 14, 660262, tzinfo=timezone.utc)
    return dtime.strftime("%Y-%m-%d %H:%M:%S.%f")


@pytest.mark.skipif(sys.version_info < (3, 4), reason="requires python3.4")
class TestBasic:
    def test_exists_workspace(self):
        assert CLOUD.workspaces.exists("TestWorkspace1"), "Exists workspace"
示例#4
0
# coding=utf-8

from textwrap import indent

from atlassian.bitbucket import Cloud

cloud = Cloud(url="https://api.bitbucket.org/", username="******", password="******")

index = 0
for w in cloud.workspaces.each():
    print("Workspace name " + w.name)
    p = next(w.projects.each())
    print("   First project name " + p.name)
    index += 1
    if index == 5:
        print("   ...")
        break

print()
w = cloud.workspaces.get(w.slug)
p = w.projects.get(p.key)
print("Project key " + p.key)
for r in p.repositories.each():
    print("   Repository name " + r.name)
    for i in r.issues.each():
        print("   Issue uuid " + str(i.id))
        print("      Title: " + i.title)
    index = 0
    for pl in r.pipelines.each(sort="-created_on"):
        index += 1
        if index == 5: