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

import os
4
import requests
Laurent Peuch's avatar
Laurent Peuch committed
5
6
import gitlab
import jinja2
7
8
9
import tempfile

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

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

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

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

17
18
PYTEST_CAPTURE_DEPRECATIONWARNINGS_PACKAGE_URI = "git+https://github.com/psycojoker/pytest-capture-deprecationwarnings"

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

26
27
28
29
30
    if cube.name.startswith("cubicweb-"):
        cube_normalized_name = cube.name.split("-", 1)[1].replace("-", "_")
    else:
        cube_normalized_name = cube.name.replace("-", "_")

Laurent Peuch's avatar
Laurent Peuch committed
31
    try:
32
        cube_files = {x["name"] for x in cube.repository_tree()}
Laurent Peuch's avatar
Laurent Peuch committed
33
    except (gitlab.GitlabHttpError, gitlab.GitlabGetError):
34
35
        # we don't care about empty repositories
        continue
Laurent Peuch's avatar
Laurent Peuch committed
36

37
38
39
    has_tox = "tox.ini" in cube_files
    has_gitlab_ci = ".gitlab-ci.yml" in cube_files
    has_readme_rst = bool({"README.rst", "README.md"} & cube_files)  # set intersection
40
    is_new_format = f"cubicweb_{cube_normalized_name}" in cube_files
Laurent Peuch's avatar
Laurent Peuch committed
41

42
    has_doc = bool({"doc", "docs"} & cube_files)  # set intersection
43
    has_readthedocs = requests.get(f"https://cubicweb-{cube_normalized_name}.readthedocs.io").status_code == 200
44

45
46
47
    # will be set after
    has_capture_deprecation_warnings = None

48
49
    if has_tox:
        tox_content = cube.files.get("tox.ini", ref="branch/default").decode().decode("Utf-8")
Laurent Peuch's avatar
Laurent Peuch committed
50

51
52
53
54
55
56
57
58
59
60
61
62
63
        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])
64
65
66
67

            if has_py3_tests:
                env_name = [x for x in tox_config.envconfigs if x.startswith("py3")]
                py3 = tox_config.envconfigs[env_name[0]]
68
69
70

                has_pytest = any(("pytest" in x for x in py3.commands))

71
72
73
74
75
76
77
78
79
80
81
82
83
                deps = [str(x) for x in py3.deps]
                uses_dev_requirements = bool([x for x in deps if x.startswith("-r") and x.endswith("dev-requirements.txt")])

                if PYTEST_CAPTURE_DEPRECATIONWARNINGS_PACKAGE_URI in deps:
                    has_capture_deprecation_warnings = True
                elif uses_dev_requirements and "dev-requirements.txt" in cube_files:
                    requirements = [x.strip() for x in cube.files.get("dev-requirements.txt", ref="branch/default").decode().decode("Utf-8") if not x.strip().startswith("#")]
                    if PYTEST_CAPTURE_DEPRECATIONWARNINGS_PACKAGE_URI in requirements:
                        has_capture_deprecation_warnings = True

            else:
                has_capture_deprecation_warnings = False

84
85
86
87
88
                if has_py2_tests:
                    env_name = [x for x in tox_config.envconfigs if x.startswith("py2")]
                    py2 = tox_config.envconfigs[env_name[0]]
                    has_pytest = any(("pytest" in x for x in py2.commands))

89
90
91
92
93
94
95
96
97
98
99
100
            # 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
101
    context["cubes"].append({
Laurent Peuch's avatar
Laurent Peuch committed
102
        "cube": cube.attributes,
103
        "has_doc": has_doc,
104
        "has_readthedocs": has_readthedocs,
105
        "is_new_format": is_new_format,
Laurent Peuch's avatar
Laurent Peuch committed
106
107
108
        "has_tox": has_tox,
        "has_gitlab_ci": has_gitlab_ci,
        "has_readme_rst": has_readme_rst,
109
110
        "has_py2_tests": has_py2_tests,
        "has_py3_tests": has_py3_tests,
111
        "has_pytest": has_pytest,
112
113
114
115
116
        "has_check_manifest": has_check_manifest,
        "has_black": has_black,
        "has_mypy": has_mypy,
        "has_flake8": has_flake8,
        "has_from_forge": has_from_forge,
117
        "has_capture_deprecation_warnings": has_capture_deprecation_warnings,
Laurent Peuch's avatar
Laurent Peuch committed
118
119
120
    })

context["cubes"] = sorted(context["cubes"], key=lambda x: x["cube"]["name"].lower())
Laurent Peuch's avatar
Laurent Peuch committed
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315

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}