Files
Heimdall/scripts/ci/release-notes.py
T
arnaud.dartois d4b4ae8233
Heimdall Gitea / Detect CI scope (pull_request) Successful in 5s
Heimdall Gitea / Build and tests (pull_request) Successful in 21m57s
Heimdall Gitea / Build and scan agent image (pull_request) Skipped
Heimdall Gitea / Build and scan NVIDIA Agent image (pull_request) Skipped
Heimdall Gitea / Build and scan server image (pull_request) Successful in 4m41s
Heimdall Gitea / Publish versioned installer release (pull_request) Skipped
Heimdall Gitea / CI policy (pull_request) Successful in 2s
ci(release): publish versioned installer bundles
Refs #314
2026-11-09 15:38:50 +01:00

49 lines
1.8 KiB
Python

"""Generate release notes from pull requests merged since the previous version tag."""
import json
import os
from pathlib import Path
import urllib.error
import urllib.parse
import urllib.request
base = os.environ['BUILD_SERVER_URL'].rstrip('/') + '/api/v1/repos/' + os.environ['BUILD_REPOSITORY']
token = os.environ['GITEA_TOKEN']
before = os.environ['BEFORE_SHA']
current = os.environ['CURRENT_SHA']
def get(path):
request = urllib.request.Request(base + path, headers={
'Authorization': 'token ' + token,
'Accept': 'application/json',
})
try:
with urllib.request.urlopen(request, timeout=30) as response:
return json.load(response)
except urllib.error.HTTPError as error:
if error.code == 404:
return None
raise SystemExit(f'Gitea release notes API failed: HTTP {error.code}') from None
comparison = get('/compare/' + urllib.parse.quote(before, safe='') + '...' + urllib.parse.quote(current, safe=''))
if comparison is None:
raise SystemExit('Gitea could not compare the previous and current main commits')
pulls = {}
for commit in comparison.get('commits', []):
pull = get('/commits/' + urllib.parse.quote(commit['sha'], safe='') + '/pull')
if pull and pull.get('merged') and pull.get('number'):
pulls[pull['number']] = pull
lines = []
for number, pull in sorted(pulls.items()):
title = pull.get('title') or f'Pull request #{number}'
url = pull.get('html_url') or f"{base.removesuffix('/api/v1/repos/' + os.environ['BUILD_REPOSITORY'])}/pulls/{number}"
lines.append(f'- {title} ([#{number}]({url}))')
if not lines:
lines = [f'- Changes merged in commit `{current}`.']
Path('artifacts/release-notes.md').write_text('\n'.join(lines) + '\n')
print(f'Generated release notes for {len(pulls)} merged pull request(s).')