Skip to content

Commit c258a97

Browse files
committed
generate the report even without github
Signed-off-by: Gaëtan Lehmann <gaetan.lehmann@vates.tech>
1 parent acf75eb commit c258a97

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

scripts/pkg_in_pipe/pkg_in_pipe.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import koji
1515
import requests
1616
from github.Commit import Commit
17+
from github.GithubException import BadCredentialsException
1718
from github.PullRequest import PullRequest
1819

1920
# from icecream import ic
@@ -41,6 +42,15 @@ def print_plane_warning(out):
4142
</div>
4243
</div>'''), file=out)
4344

45+
def print_github_warning(out):
46+
print(dedent('''
47+
<div class="px-3 py-3">
48+
<div class="bg-orange-100 border-l-4 border-orange-500 text-orange-700 p-4" role="alert">
49+
<p class="font-bold">Github malfunction</p>
50+
<p>The pull requests could not be retrieved from Github.</p>
51+
</div>
52+
</div>'''), file=out)
53+
4454
def print_koji_error(out):
4555
print(dedent('''
4656
<div class="px-3 py-3">
@@ -193,6 +203,12 @@ def find_pull_requests(gh, repo, start_sha, end_sha):
193203
parser = argparse.ArgumentParser(description='Generate a report of the packages in the pipe')
194204
parser.add_argument('output', nargs='?', help='Report output path', default='report.html')
195205
parser.add_argument('--generated-info', help="Add this message about the generation in the report")
206+
parser.add_argument(
207+
'--plane-token', help="The token used to access the plane api", default=os.environ.get('PLANE_TOKEN')
208+
)
209+
parser.add_argument(
210+
'--github-token', help="The token used to access the Github api", default=os.environ.get('GITHUB_TOKEN')
211+
)
196212
parser.add_argument('--cache', help="The cache path", default="/tmp/pkg_in_pipe.cache")
197213
args = parser.parse_args()
198214

@@ -206,13 +222,22 @@ def find_pull_requests(gh, repo, start_sha, end_sha):
206222
issues = resp.json().get('results', [])
207223

208224
# connect to github
209-
gh = github.Github(auth=github.Auth.Token(os.environ['GITHUB_TOKEN']))
225+
if args.github_token:
226+
gh = github.Github(auth=github.Auth.Token(args.github_token))
227+
try:
228+
gh.get_repo('xcp-ng/xcp') # check that the token is valid
229+
except BadCredentialsException:
230+
gh = None
231+
else:
232+
gh = None
210233

211234
ok = True
212235
with open(args.output, 'w') as out:
213236
print_header(out)
214237
if not issues:
215238
print_plane_warning(out)
239+
if not gh:
240+
print_github_warning(out)
216241
tags = [f'v{v}-{p}' for v in ['8.2', '8.3'] for p in ['incoming', 'ci', 'testing', 'candidates', 'lab']]
217242
temp_out = io.StringIO()
218243
try:
@@ -226,7 +251,7 @@ def find_pull_requests(gh, repo, start_sha, end_sha):
226251
build = session.getBuild(tagged['build_id'])
227252
prs: list[PullRequest] = []
228253
previous_build_sha = find_previous_build_commit(session, tag, build)
229-
if build['source'] is not None:
254+
if gh and build['source'] is not None:
230255
(repo, sha) = parse_source(build['source'])
231256
prs = find_pull_requests(gh, repo, sha, previous_build_sha)
232257
build_url = f'https://koji.xcp-ng.org/buildinfo?buildID={tagged['build_id']}'

0 commit comments

Comments
 (0)