Skip to content

Commit ec0ba72

Browse files
committed
package in pipe html report generator
Signed-off-by: Gaëtan Lehmann <[email protected]>
1 parent c8a6eb8 commit ec0ba72

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

scripts/pkg_in_pipe/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
report.html

scripts/pkg_in_pipe/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Packages in pipe report generator
2+
3+
Generates an html report with the packages in the current tags.
4+
5+
# Requirements
6+
7+
An environmnt variable `PLANE_TOKEN` must be defined when running the generator.

scripts/pkg_in_pipe/pkg_in_pipe.py

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/usr/bin/env python
2+
3+
import os
4+
import sys
5+
from datetime import datetime
6+
7+
import koji
8+
import requests
9+
10+
def print_header(out):
11+
print('''
12+
<!DOCTYPE html>
13+
<html lang="en">
14+
<head>
15+
<meta charset="UTF-8">
16+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
17+
<title>XCP-ng Package Update</title>
18+
<script src="https://cdn.tailwindcss.com"></script>
19+
</head>
20+
<body class="bg-gray-400 text-center">
21+
''', file=out)
22+
23+
def print_footer(out):
24+
now = datetime.now()
25+
print(f'''
26+
Last generated at {now}. Generated every 5 minutes.
27+
</body>
28+
</html>
29+
''', file=out)
30+
31+
def print_table_header(out, tag):
32+
print(f'''
33+
<div class="px-3 py-3">
34+
<div class="relative overflow-x-auto shadow-md sm:rounded-lg">
35+
<table class="table-fixed w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400">
36+
<caption class="p-5 text-lg font-semibold text-left rtl:text-right text-gray-900 bg-white dark:text-white dark:bg-gray-800">
37+
{tag}
38+
</caption>
39+
<thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
40+
<tr>
41+
<th scope="col" class="px-6 py-3">
42+
Build
43+
</th>
44+
<th scope="col" class="px-6 py-3">
45+
Cards
46+
</th>
47+
<th scope="col" class="px-6 py-3">
48+
By
49+
</th>
50+
</tr>
51+
</thead>
52+
<tbody>
53+
''', file=out)
54+
55+
def print_table_footer(out):
56+
print('''
57+
</tbody>
58+
</table>
59+
</div>
60+
</div>
61+
''', file=out)
62+
63+
def print_table_line(out, build, link, issues, by):
64+
issues_content = '\n'.join([f'<li><a class="font-medium text-blue-600 dark:text-blue-500 hover:underline" href="https://project.vates.tech/vates-global/browse/XCPNG-{i['sequence_id']}/">XCPNG-{i['sequence_id']}</a></li>' for i in issues])
65+
print(f'''
66+
<tr class="odd:bg-white odd:dark:bg-gray-900 even:bg-gray-50 even:dark:bg-gray-800 border-b dark:border-gray-700 border-gray-200">
67+
<th scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">
68+
<a class="font-medium text-blue-600 dark:text-blue-500 hover:underline" href="{link}">{build}</a>
69+
</th>
70+
<td class="px-6 py-4">
71+
<ul>
72+
{issues_content}
73+
</ul>
74+
</td>
75+
<td class="px-6 py-4">
76+
{by}
77+
</td>
78+
</tr>
79+
''', file=out)
80+
81+
# open koji session
82+
config = koji.read_config("koji")
83+
session = koji.ClientSession('https://kojihub.xcp-ng.org', config)
84+
session.ssl_login(config['cert'], None, config['serverca'])
85+
86+
# load the issues from plane, so we can search for the plane card related to a build
87+
resp = requests.get('https://project.vates.tech/api/v1/workspaces/vates-global/projects/43438eec-1335-4fc2-8804-5a4c32f4932d/issues/',
88+
headers={'x-api-key': os.environ['PLANE_TOKEN']})
89+
project_issues = resp.json()
90+
91+
output_path = sys.argv[1] if len(sys.argv) >=2 else 'report.html'
92+
with open(output_path, 'w') as out:
93+
print_header(out)
94+
tags = [f'v{v}-{p}' for v in ['8.2', '8.3'] for p in ['incoming', 'ci', 'testing', 'candidates', 'lab']]
95+
for tag in tags:
96+
print_table_header(out, tag)
97+
for build in session.listTagged(tag):
98+
build_url = f'https://koji.xcp-ng.org/buildinfo?buildID={build['build_id']}'
99+
build_issues = [i for i in project_issues['results'] if f'href="{build_url}"' in i['description_html']]
100+
print_table_line(out, build['nvr'], build_url, build_issues, build['owner_name'])
101+
print_table_footer(out)
102+
print_footer(out)

0 commit comments

Comments
 (0)