3
3
import argparse
4
4
import io
5
5
import os
6
+ import re
6
7
import sys
7
8
from datetime import datetime
8
9
from textwrap import dedent
9
10
11
+ import github
12
+ import github .PullRequest
10
13
import koji
11
14
import requests
12
15
@@ -66,6 +69,9 @@ def print_table_header(out, tag):
66
69
<th scope="col" class="px-6 py-3">
67
70
Cards
68
71
</th>
72
+ <th scope="col" class="px-6 py-3">
73
+ Pull Requests
74
+ </th>
69
75
<th scope="col" class="px-6 py-3">
70
76
By
71
77
</th>
@@ -82,7 +88,7 @@ def print_table_footer(out):
82
88
</div>
83
89
''' ), file = out )
84
90
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 ] ):
86
92
issues_content = '\n ' .join ([
87
93
f'''<li>
88
94
<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):
91
97
</li>'''
92
98
for i in issues
93
99
])
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
+ ])
94
108
print (f'''
95
109
<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">
96
110
<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):
101
115
{ issues_content }
102
116
</ul>
103
117
</td>
118
+ <td class="px-6 py-4">
119
+ <ul>
120
+ { prs_content }
121
+ </ul>
122
+ </td>
104
123
<td class="px-6 py-4">
105
124
{ by }
106
125
</td>
107
126
</tr>
108
127
''' , file = out ) # nopep8
109
128
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
+
110
134
parser = argparse .ArgumentParser (description = 'Generate a report of the packages in the pipe' )
111
135
parser .add_argument ('output' , nargs = '?' , help = 'Report output path' , default = 'report.html' )
112
136
parser .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):
120
144
)
121
145
issues = resp .json ().get ('results' , [])
122
146
147
+ # connect to github
148
+ gh = github .Github (auth = github .Auth .Token (os .environ ['GITHUB_TOKEN' ]))
149
+
123
150
ok = True
124
151
with open (args .output , 'w' ) as out :
125
152
print_header (out )
@@ -134,10 +161,15 @@ def print_table_line(out, build, link, issues, by):
134
161
session .ssl_login (config ['cert' ], None , config ['serverca' ])
135
162
for tag in tags :
136
163
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' ]} '
139
171
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 )
141
173
print_table_footer (temp_out )
142
174
out .write (temp_out .getvalue ())
143
175
except Exception as e :
0 commit comments