qa_dashboard.py 10.4 KB
Newer Older
Laurent Peuch's avatar
Laurent Peuch committed
1
2
3
4
5
#!/usr/bin/env python3

import os
import gitlab
import jinja2
6
7
8
import tempfile

from tox.config import parseconfig
Laurent Peuch's avatar
Laurent Peuch committed
9
10
11

gl = gitlab.Gitlab("https://forge.extranet.logilab.fr", oauth_token=os.environ.get("TOKEN"))

Laurent Peuch's avatar
Laurent Peuch committed
12
context = {"cubes": []}
Laurent Peuch's avatar
Laurent Peuch committed
13
14
15

all_cubes = [x for x in gl.projects.list(all=True) if x.namespace["name"] == "cubes"]

16
for number, cube in enumerate(all_cubes):
Laurent Peuch's avatar
Laurent Peuch committed
17
18
19
20
21
22
23
    # python3
    # doc8
    # a de la doc
    # safety
    # deprecation warnings ?

    try:
24
        tox_content = cube.files.get("tox.ini", ref="branch/default").decode().decode("Utf-8")
Laurent Peuch's avatar
Laurent Peuch committed
25
26
27
        has_tox = True
    except (gitlab.GitlabHttpError, gitlab.GitlabGetError):
        has_tox = False
28
        tox_content = None
Laurent Peuch's avatar
Laurent Peuch committed
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

    try:
        cube.files.get(".gitlab-ci.yml", ref="branch/default")
        has_gitlab_ci = True
    except (gitlab.GitlabHttpError, gitlab.GitlabGetError):
        has_gitlab_ci = False

    try:
        cube.files.get("README.rst", ref="branch/default")
        has_readme_rst = True
    except (gitlab.GitlabHttpError, gitlab.GitlabGetError):
        try:
            cube.files.get("README.md", ref="branch/default")
            has_readme_rst = True
        except (gitlab.GitlabHttpError, gitlab.GitlabGetError):
            has_readme_rst = False

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
    if tox_content is not None:
        with tempfile.TemporaryDirectory() as temporary_directory_path:
            # TODO pyproject.toml
            tox_path = os.path.join(temporary_directory_path, "tox.ini")
            open(tox_path, "w").write(tox_content)
            tox_config = parseconfig(["-c", tox_path])

            has_py2_tests = any([x.startswith("py2") for x in tox_config.envlist])
            has_py3_tests = any([x.startswith("py3") for x in tox_config.envlist])
            has_check_manifest = "check-manifest" in tox_config.envlist
            has_black = "black" in tox_config.envlist
            has_mypy = "mypy" in tox_config.envlist
            has_flake8 = "flake8" in tox_config.envlist
            has_from_forge = any(["from-forge" in x for x in tox_config.envlist])
            # has_doc8, check if has doc first
            # has_pytest_html
            # has_pytest_capture_deprecationwarnings
    else:
        has_py2_tests = False
        has_py3_tests = False
        has_check_manifest = False
        has_black = False
        has_mypy = False
        has_flake8 = False
        has_from_forge = False

Laurent Peuch's avatar
Laurent Peuch committed
72
    context["cubes"].append({
Laurent Peuch's avatar
Laurent Peuch committed
73
74
75
76
        "cube": cube.attributes,
        "has_tox": has_tox,
        "has_gitlab_ci": has_gitlab_ci,
        "has_readme_rst": has_readme_rst,
77
78
79
80
81
82
83
        "has_py2_tests": has_py2_tests,
        "has_py3_tests": has_py3_tests,
        "has_check_manifest": has_check_manifest,
        "has_black": has_black,
        "has_mypy": has_mypy,
        "has_flake8": has_flake8,
        "has_from_forge": has_from_forge,
Laurent Peuch's avatar
Laurent Peuch committed
84
85
86
    })

context["cubes"] = sorted(context["cubes"], key=lambda x: x["cube"]["name"].lower())
Laurent Peuch's avatar
Laurent Peuch committed
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281

os.system("mkdir -p public")  # XXX lazy
result = jinja2.Template(open("template/qa.html", "r").read()).render(**context)
open("public/qa.html", "w").write(result)

# reference:
# In [71]: project.attributes
# Out[71]:
# {'id': 385,
#  'description': 'https://cubicweb.readthedocs.io/',
#  'vcs_type': 'hg_git',
#  'name': 'cubicweb',
#  'name_with_namespace': 'cubicweb / cubicweb',
#  'path': 'cubicweb',
#  'path_with_namespace': 'cubicweb/cubicweb',
#  'created_at': '2020-04-10T13:39:55.623Z',
#  'default_branch': 'branch/default',
#  'tag_list': ['cw-core'],
#  'ssh_url_to_repo': 'ssh://git@forge.extranet.logilab.fr/cubicweb/cubicweb',
#  'http_url_to_repo': 'https://forge.extranet.logilab.fr/cubicweb/cubicweb',
#  'web_url': 'https://forge.extranet.logilab.fr/cubicweb/cubicweb',
#  'readme_url': 'https://forge.extranet.logilab.fr/cubicweb/cubicweb/-/blob/branch/default/README',
#  'avatar_url': 'https://forge.extranet.logilab.fr/uploads/-/system/project/avatar/385/cubicweb_logo.png',
#  'star_count': 2,
#  'forks_count': 0,
#  'last_activity_at': '2020-07-22T02:01:43.427Z',
#  'namespace': {'id': 23,
#   'name': 'cubicweb',
#   'path': 'cubicweb',
#   'kind': 'group',
#   'full_path': 'cubicweb',
#   'parent_id': None,
#   'avatar_url': '/uploads/-/system/group/avatar/23/cubicweb.png',
#   'web_url': 'https://forge.extranet.logilab.fr/groups/cubicweb'},
#  '_links': {'self': 'https://forge.extranet.logilab.fr/api/v4/projects/385',
#   'issues': 'https://forge.extranet.logilab.fr/api/v4/projects/385/issues',
#   'merge_requests': 'https://forge.extranet.logilab.fr/api/v4/projects/385/merge_requests',
#   'repo_branches': 'https://forge.extranet.logilab.fr/api/v4/projects/385/repository/branches',
#   'labels': 'https://forge.extranet.logilab.fr/api/v4/projects/385/labels',
#   'events': 'https://forge.extranet.logilab.fr/api/v4/projects/385/events',
#   'members': 'https://forge.extranet.logilab.fr/api/v4/projects/385/members'},
#  'empty_repo': False,
#  'archived': False,
#  'visibility': 'public',
#  'resolve_outdated_diff_discussions': False,
#  'container_registry_enabled': True,
#  'issues_enabled': True,
#  'merge_requests_enabled': True,
#  'wiki_enabled': True,
#  'jobs_enabled': True,
#  'snippets_enabled': True,
#  'can_create_merge_request_in': True,
#  'issues_access_level': 'enabled',
#  'repository_access_level': 'enabled',
#  'merge_requests_access_level': 'enabled',
#  'forking_access_level': 'enabled',
#  'wiki_access_level': 'enabled',
#  'builds_access_level': 'enabled',
#  'snippets_access_level': 'enabled',
#  'pages_access_level': 'enabled',
#  'emails_disabled': False,
#  'shared_runners_enabled': True,
#  'lfs_enabled': True,
#  'creator_id': 19,
#  'import_status': 'none',
#  'open_issues_count': 38,
#  'ci_default_git_depth': 50,
#  'public_jobs': True,
#  'build_timeout': 14400,
#  'auto_cancel_pending_pipelines': 'enabled',
#  'build_coverage_regex': '',
#  'ci_config_path': '',
#  'shared_with_groups': [{'group_id': 21,
#    'group_name': 'logilab',
#    'group_full_path': 'logilab',
#    'group_access_level': 40,
#    'expires_at': None}],
#  'only_allow_merge_if_pipeline_succeeds': False,
#  'request_access_enabled': True,
#  'only_allow_merge_if_all_discussions_are_resolved': False,
#  'remove_source_branch_after_merge': None,
#  'printing_merge_request_link_enabled': True,
#  'merge_method': 'ff',
#  'suggestion_commit_message': None,
#  'auto_devops_enabled': False,
#  'auto_devops_deploy_strategy': 'continuous',
#  'autoclose_referenced_issues': True,
#  'permissions': {'project_access': {'access_level': 30,
#    'notification_level': 3},
#   'group_access': {'access_level': 40, 'notification_level': 2}}}
#
# In [171]: mr.attributes
# Out[171]:
# {'assignees': [],
#  'labels': ['Need Revision'],
#  'id': 2098,
#  'iid': 40,
#  'project_id': 385,
#  'title': 'fix: UX when migractions failed to get its connection',
#  'description': "It was a mess to debug because from the exception we couldn't get the right information to understand what was happening.",
#  'state': 'opened',
#  'created_at': '2020-07-08T13:43:26.081Z',
#  'updated_at': '2020-07-22T02:01:50.582Z',
#  'merged_by': None,
#  'merged_at': None,
#  'closed_by': None,
#  'closed_at': None,
#  'target_branch': 'topic/default/fix-yams-str-only-api',
#  'source_branch': 'topic/default/ux-migractions-get-connections',
#  'user_notes_count': 4,
#  'upvotes': 0,
#  'downvotes': 0,
#  'assignee': None,
#  'author': {'id': 52,
#   'name': 'Laurent Peuch',
#   'username': 'bram',
#   'state': 'active',
#   'avatar_url': 'https://forge.extranet.logilab.fr/uploads/-/system/user/avatar/52/avatar.png',
#   'web_url': 'https://forge.extranet.logilab.fr/bram'},
#  'source_project_id': 385,
#  'target_project_id': 385,
#  'work_in_progress': False,
#  'milestone': None,
#  'merge_when_pipeline_succeeds': False,
#  'merge_status': 'cannot_be_merged',
#  'sha': 'b082d6abc2dd0eff89c5b2d5a200afed87f871bd',
#  'merge_commit_sha': None,
#  'squash_commit_sha': None,
#  'discussion_locked': None,
#  'should_remove_source_branch': True,
#  'force_remove_source_branch': True,
#  'reference': '!40',
#  'references': {'short': '!40',
#   'relative': '!40',
#   'full': 'cubicweb/cubicweb!40'},
#  'web_url': 'https://forge.extranet.logilab.fr/cubicweb/cubicweb/-/merge_requests/40',
#  'time_stats': {'time_estimate': 0,
#   'total_time_spent': 0,
#   'human_time_estimate': None,
#   'human_total_time_spent': None},
#  'squash': False,
#  'task_completion_status': {'count': 0, 'completed_count': 0},
#  'has_conflicts': True,
#  'blocking_discussions_resolved': True}
#
# In [173]: mr.pipelines()
# Out[173]:
# [{'id': 10456,
#   'sha': 'b082d6abc2dd0eff89c5b2d5a200afed87f871bd',
#   'ref': 'topic/default/ux-migractions-get-connections',
#   'status': 'failed',
#   'created_at': '2020-07-22T02:01:45.244Z',
#   'updated_at': '2020-07-22T02:49:01.167Z',
#   'web_url': 'https://forge.extranet.logilab.fr/cubicweb/cubicweb/pipelines/10456'},
#  {'id': 10172,
#   'sha': 'ecd6627517e6d933fed6142251ac33e01feadb7d',
#   'ref': 'topic/default/ux-migractions-get-connections',
#   'status': 'success',
#   'created_at': '2020-07-15T19:14:46.111Z',
#   'updated_at': '2020-07-15T19:49:18.689Z',
#   'web_url': 'https://forge.extranet.logilab.fr/cubicweb/cubicweb/pipelines/10172'},
#  {'id': 10139,
#   'sha': '80da4968dbd33dc3c595f34ed42f363c09afe93b',
#   'ref': 'topic/default/ux-migractions-get-connections',
#   'status': 'success',
#   'created_at': '2020-07-15T13:48:35.325Z',
#   'updated_at': '2020-07-15T14:23:44.391Z',
#   'web_url': 'https://forge.extranet.logilab.fr/cubicweb/cubicweb/pipelines/10139'},
#  {'id': 9981,
#   'sha': '43ba55bcb3b09008ea180f9fb13e38871c61d72a',
#   'ref': 'topic/default/ux-migractions-get-connections',
#   'status': 'failed',
#   'created_at': '2020-07-08T21:26:50.427Z',
#   'updated_at': '2020-07-08T22:05:34.317Z',
#   'web_url': 'https://forge.extranet.logilab.fr/cubicweb/cubicweb/pipelines/9981'},
#  {'id': 9963,
#   'sha': '927761a999636ce7a8707ce5e320d0aa1f840c77',
#   'ref': 'topic/default/ux-migractions-get-connections',
#   'status': 'failed',
#   'created_at': '2020-07-08T13:40:32.447Z',
#   'updated_at': '2020-07-08T14:16:23.240Z',
#   'web_url': 'https://forge.extranet.logilab.fr/cubicweb/cubicweb/pipelines/9963'}]
#
# In [174]: project.labels.list(all=True)[0].attributes
# Out[174]:
# {'id': 945,
#  'name': 'Doing',
#  'color': '#5CB85C',
#  'description': 'Issue in progress',
#  'description_html': 'Issue in progress',
#  'text_color': '#FFFFFF',
#  'subscribed': True,
#  'priority': None,
#  'is_project_label': True,
#  'project_id': 385}