|
| 1 | +from enum import auto |
1 | 2 | from sqlalchemy import create_engine |
2 | | -from sqlalchemy import MetaData, Table, Column |
3 | | -from sqlalchemy import String, BigInteger, ForeignKey, Integer, DateTime, Boolean |
| 3 | +from sqlalchemy import MetaData, Table |
| 4 | +import requests |
| 5 | +import json |
4 | 6 |
|
5 | 7 |
|
6 | 8 | db_name = input('db_name: ') |
|
10 | 12 | db = create_engine(f'postgresql://{db_user}:{db_pass}@localhost/{db_name}') |
11 | 13 | meta = MetaData(db) |
12 | 14 |
|
13 | | -projects = Table('project', meta, |
14 | | - Column('id', BigInteger, primary_key=True, unique=True), |
15 | | - Column('description', String), |
16 | | - Column('fork_count', Integer), |
17 | | - Column('gitlab_project_id', Integer), |
18 | | - Column('last_commit', DateTime), |
19 | | - Column('name', String), |
20 | | - Column('name_space', String), |
21 | | - Column('url', String) |
22 | | - ) |
23 | | - |
24 | | -linting_results = Table('linting_result', meta, |
25 | | - Column('id', BigInteger, primary_key=True, unique=True), |
26 | | - Column('lint_time', DateTime), |
27 | | - Column('project_id', BigInteger, |
28 | | - ForeignKey('project.id')), |
29 | | - ) |
30 | | - |
31 | | -check_results = Table('check_result', meta, |
32 | | - Column('id', BigInteger, primary_key=True, unique=True), |
33 | | - Column('check_name', String), |
34 | | - Column('lint_id', BigInteger, |
35 | | - ForeignKey('linting_result.id')), |
36 | | - Column('result', Boolean) |
37 | | - ) |
38 | | - |
39 | | - |
40 | | -with db.connect() as conn: |
41 | | - pass |
| 15 | +projects = Table('project', meta, autoload=True) |
| 16 | +linting_results = Table('linting_result', meta, autoload=True) |
| 17 | +check_results = Table('check_result', meta, autoload=True) |
| 18 | + |
| 19 | + |
| 20 | +def get_projects(): |
| 21 | + with open('../config.json', 'r') as f: |
| 22 | + config = json.load(f) |
| 23 | + gitlab_host = config['settings']['gitLabHost'] |
| 24 | + |
| 25 | + res = requests.get(f'{gitlab_host}/api/v4/projects?per_page=100') |
| 26 | + if res.status_code == 200: |
| 27 | + return res.json() |
| 28 | + else: |
| 29 | + return [] |
| 30 | + |
| 31 | + |
0 commit comments