summaryrefslogtreecommitdiff
path: root/tools/libgithub/view.py
blob: f01abe8bdeb9c25aef0562a294de996c62a39498 (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
42
43
44
45
46
47
48
49
50
51
# This is mostly useless until Github extends their API to allow for view creation.

from .graphql import GraphQLClient
from dataclasses import dataclass
from logger import LOG

@dataclass
class View:
    def set_layoutout(self, layout: str):
        self.layout = layout

    # Doesn't actually work (yet)
    def check_and_create(self):
        LOG.debug(f'Checking if view {self.name} exists')
        query = '''
        query ($projectNumber: String!) {
            node(id: $projectNumber) {
                ... on ProjectV2 {
                    views {
                        nodes {
                            name
                            number
                        }
                    }
                }
            }
        }
        '''
        
        variables = {
            "projectNumber": self.number
        }

        data = GraphQLClient.get_instance().make_request(query, variables)
        if data:
            views = data['data']['node']['views']['nodes']
            LOG.info(f'Views: {views}')

            for view in views:
                if view['name'] == self.name:
                    LOG.info(f'View {self.name} exists')
                    return

            LOG.info(f'View {self.name} does not exist, creating')
            self.create()
        else:
            LOG.warning(f'No views found for project {self.number}')

    # Waiting on Github to update their API
    def create(self):
        pass