22 lines
1.2 KiB
Python
22 lines
1.2 KiB
Python
"""Read-only inspection of source branch advancement after preflight refusal."""
|
|
from datetime import datetime, timezone
|
|
import json
|
|
from pathlib import Path
|
|
import urllib.parse
|
|
from publish import Client, API, BRANCH, TARGET
|
|
|
|
HERE = Path(__file__).resolve().parent
|
|
path = HERE / 'source-advance-inspection.json'
|
|
if path.exists():
|
|
raise RuntimeError('Preserve the previous inspection')
|
|
client = Client()
|
|
branch = client.request(API + '/branches/' + urllib.parse.quote(BRANCH, safe=''))
|
|
head = branch['commit']['id']
|
|
comparison = client.request(API + '/compare/' + TARGET + '...' + head)
|
|
target = client.request(API + '/git/commits/' + TARGET)
|
|
result = {'atUtc': datetime.now(timezone.utc).isoformat(), 'target': TARGET, 'branchHead': head, 'branch': branch, 'targetCommit': target, 'comparison': comparison}
|
|
with path.open('x', encoding='utf-8', newline='\n') as out:
|
|
json.dump(result, out, ensure_ascii=False, indent=2)
|
|
out.write('\n')
|
|
print(json.dumps({'branchHead': head, 'targetCommit': target.get('sha'), 'comparisonKeys': list(comparison), 'files': comparison.get('files'), 'commits': [{'sha': c.get('sha'), 'message': c.get('commit', {}).get('message')} for c in comparison.get('commits', [])]}, ensure_ascii=False))
|