summaryrefslogtreecommitdiff
path: root/tools/libgithub/repository.py
blob: 0edc3d8a9262db47776d9caee58ff9736b7a92ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import sys

from .graphql import GraphQLClient
from typing import ClassVar
from logger import LOG

class OwnerInfo:
    id: ClassVar[str]
    name: ClassVar[str]

class RepoInfo:
    id: ClassVar[str]
    name: ClassVar[str]
    owner: ClassVar[OwnerInfo]

    @classmethod
    def set_ids(cls):
        LOG.debug(f'Fetching repo ID for {cls.name}')

        query = '''
        query ($owner: String!, $repo: String!) {
            repository(owner: $owner, name: $repo) {
                owner {
                    id
                }
                id
            }
        }
        '''
        variables = {
            "owner": cls.owner.name,
            "repo": cls.name
        }

        data = GraphQLClient.get_instance().make_request(query, variables)
        if data:
            cls.id = data['data']['repository']['id']
            cls.owner.id = data['data']['repository']['owner']['id']
        else:
            LOG.error(f"Failed to fetch repo ID! Make sure {cls.owner.name}/{cls.name} exists and isn't private.")
            sys.exit(1)