33import argparse
44import io
55import os
6+ import re
67import sys
78from datetime import datetime
89from textwrap import dedent
910
11+ import github
12+ import github .PullRequest
1013import koji
1114import requests
1215
@@ -66,6 +69,9 @@ def print_table_header(out, tag):
6669 <th scope="col" class="px-6 py-3">
6770 Cards
6871 </th>
72+ <th scope="col" class="px-6 py-3">
73+ Pull Requests
74+ </th>
6975 <th scope="col" class="px-6 py-3">
7076 By
7177 </th>
@@ -82,7 +88,7 @@ def print_table_footer(out):
8288 </div>
8389 ''' ), file = out )
8490
85- def print_table_line (out , build , link , issues , by ):
91+ def print_table_line (out , build , link , issues , by , prs : list [ github . PullRequest . PullRequest ] ):
8692 issues_content = '\n ' .join ([
8793 f'''<li>
8894 <a class="font-medium text-blue-600 dark:text-blue-500 hover:underline"
@@ -91,6 +97,14 @@ def print_table_line(out, build, link, issues, by):
9197 </li>'''
9298 for i in issues
9399 ])
100+ prs_content = '\n ' .join ([
101+ f'''<li>
102+ <a class="font-medium text-blue-600 dark:text-blue-500 hover:underline"
103+ href="{ pr .html_url } ">{ pr .title }
104+ </a>
105+ </li>'''
106+ for pr in prs
107+ ])
94108 print (f'''
95109 <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">
96110 <th scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">
@@ -101,12 +115,22 @@ def print_table_line(out, build, link, issues, by):
101115 { issues_content }
102116 </ul>
103117 </td>
118+ <td class="px-6 py-4">
119+ <ul>
120+ { prs_content }
121+ </ul>
122+ </td>
104123 <td class="px-6 py-4">
105124 { by }
106125 </td>
107126 </tr>
108127 ''' , file = out ) # nopep8
109128
129+ def parse_source (source ):
130+ groups = re .match (r'git\+https://github\.com/([\w-]+/[\w-]+)(|\.git)#([0-9a-f]{40})' , source )
131+ assert groups is not None , "can't match the source to the expected github url"
132+ return (groups [1 ], groups [3 ])
133+
110134parser = argparse .ArgumentParser (description = 'Generate a report of the packages in the pipe' )
111135parser .add_argument ('output' , nargs = '?' , help = 'Report output path' , default = 'report.html' )
112136parser .add_argument ('--generated-info' , help = "Add this message about the generation in the report" )
@@ -120,6 +144,9 @@ def print_table_line(out, build, link, issues, by):
120144)
121145issues = resp .json ().get ('results' , [])
122146
147+ # connect to github
148+ gh = github .Github (auth = github .Auth .Token (os .environ ['GITHUB_TOKEN' ]))
149+
123150ok = True
124151with open (args .output , 'w' ) as out :
125152 print_header (out )
@@ -134,10 +161,15 @@ def print_table_line(out, build, link, issues, by):
134161 session .ssl_login (config ['cert' ], None , config ['serverca' ])
135162 for tag in tags :
136163 print_table_header (temp_out , tag )
137- for build in sorted (session .listTagged (tag ), key = lambda build : int (build ['build_id' ]), reverse = True ):
138- build_url = f'https://koji.xcp-ng.org/buildinfo?buildID={ build ['build_id' ]} '
164+ for tagged in sorted (session .listTagged (tag ), key = lambda build : int (build ['build_id' ]), reverse = True ):
165+ build = session .getBuild (tagged ['build_id' ])
166+ prs : list [github .PullRequest .PullRequest ] = []
167+ if build ['source' ] is not None :
168+ (repo , sha ) = parse_source (build ['source' ])
169+ prs = list (gh .get_repo (repo ).get_commit (sha ).get_pulls ())
170+ build_url = f'https://koji.xcp-ng.org/buildinfo?buildID={ tagged ['build_id' ]} '
139171 build_issues = [i for i in issues if f'href="{ build_url } "' in i ['description_html' ]]
140- print_table_line (temp_out , build ['nvr' ], build_url , build_issues , build ['owner_name' ])
172+ print_table_line (temp_out , tagged ['nvr' ], build_url , build_issues , tagged ['owner_name' ], prs )
141173 print_table_footer (temp_out )
142174 out .write (temp_out .getvalue ())
143175 except Exception as e :
0 commit comments