aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/cgitize/bitbucket.py
blob: 16f6d412573272a005f7734a82a245b5130dd4d1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Copyright (c) 2021 Egor Tensin <Egor.Tensin@gmail.com>
# This file is part of the "cgitize" project.
# For details, see https://github.com/egor-tensin/cgitize.
# Distributed under the MIT License.

import logging

from atlassian.bitbucket.cloud import Cloud
from requests.exceptions import HTTPError


class Bitbucket:
    def __init__(self, username=None, password=None):
        self._impl = Cloud(username=username, password=password, cloud=True)

    def get_repo(self, repo):
        if 'id' not in repo:
            raise ValueError('every Bitbucket repository must have an ID')
        repo_id = repo['id']
        try:
            return self._impl.repositories.get(repo_id)
        except HTTPError:
            logging.error("Couldn't fetch repository: %s", repo_id)
            raise