88 lines
2.8 KiB
Bash
Executable File
88 lines
2.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Regression harness for Gitea PR metadata normalization.
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
WORK_DIR="${MOSAIC_TEST_WORK_DIR:-$PWD/.mosaic-test-work/pr-metadata-gitea}"
|
|
REPO_DIR="$WORK_DIR/repo"
|
|
FIXTURE_DIR="$WORK_DIR/fixtures"
|
|
|
|
rm -rf "$WORK_DIR"
|
|
mkdir -p "$REPO_DIR" "$FIXTURE_DIR"
|
|
|
|
git -C "$REPO_DIR" init -q
|
|
git -C "$REPO_DIR" remote add origin https://git.uscllc.com/USC/uconnect.git
|
|
|
|
cat > "$FIXTURE_DIR/gitea-standard.json" <<'JSON'
|
|
{
|
|
"number": 1905,
|
|
"title": "Smoke gate fix",
|
|
"state": "open",
|
|
"user": {"login": "edith"},
|
|
"head": {"ref": "edith/t_39ce717c-authentik-smoke-gate"},
|
|
"base": {"ref": "main"},
|
|
"labels": [{"name": "ci"}],
|
|
"assignees": [{"login": "edith"}],
|
|
"html_url": "https://git.uscllc.com/USC/uconnect/pulls/1905"
|
|
}
|
|
JSON
|
|
|
|
cat > "$FIXTURE_DIR/gitea-fallback.json" <<'JSON'
|
|
{
|
|
"number": 1908,
|
|
"title": "Fallback branch fields",
|
|
"state": "open",
|
|
"user": {"login": "edith"},
|
|
"head_branch": "fix/fallback-head",
|
|
"base_branch": "main",
|
|
"html_url": "https://git.uscllc.com/USC/uconnect/pulls/1908"
|
|
}
|
|
JSON
|
|
|
|
cat > "$FIXTURE_DIR/gitea-refs-pull-label.json" <<'JSON'
|
|
{
|
|
"number": 1908,
|
|
"title": "Closed merged PR with synthetic pull ref",
|
|
"state": "closed",
|
|
"user": {"login": "edith"},
|
|
"head": {"ref": "refs/pull/1908/head", "label": "fix/t_23fa9e1d-portal-health-backend"},
|
|
"base": {"ref": "main"},
|
|
"html_url": "https://git.uscllc.com/USC/uconnect/pulls/1908"
|
|
}
|
|
JSON
|
|
|
|
cat > "$FIXTURE_DIR/gitea-error.json" <<'JSON'
|
|
{"message": "user does not exist [uid: 0, name: ]", "url": "https://git.uscllc.com/api/swagger"}
|
|
JSON
|
|
|
|
run_case() {
|
|
local fixture="$1" expected_number="$2" expected_head="$3"
|
|
local output
|
|
output=$(cd "$REPO_DIR" && MOSAIC_GITEA_PR_METADATA_RAW_FILE="$fixture" "$SCRIPT_DIR/pr-metadata.sh" -n "$expected_number")
|
|
PR_METADATA_OUTPUT="$output" python3 - "$expected_number" "$expected_head" <<'PY'
|
|
import json
|
|
import os
|
|
import sys
|
|
|
|
data = json.loads(os.environ["PR_METADATA_OUTPUT"])
|
|
expected_number = int(sys.argv[1])
|
|
expected_head = sys.argv[2]
|
|
assert data["number"] == expected_number, data
|
|
assert data["baseRefName"] == "main", data
|
|
assert data["headRefName"] == expected_head, data
|
|
PY
|
|
}
|
|
|
|
run_case "$FIXTURE_DIR/gitea-standard.json" 1905 edith/t_39ce717c-authentik-smoke-gate
|
|
run_case "$FIXTURE_DIR/gitea-fallback.json" 1908 fix/fallback-head
|
|
run_case "$FIXTURE_DIR/gitea-refs-pull-label.json" 1908 fix/t_23fa9e1d-portal-health-backend
|
|
|
|
if cd "$REPO_DIR" && MOSAIC_GITEA_PR_METADATA_RAW_FILE="$FIXTURE_DIR/gitea-error.json" "$SCRIPT_DIR/pr-metadata.sh" -n 1909 >/dev/null 2>"$WORK_DIR/error.log"; then
|
|
echo "Expected API error fixture to fail" >&2
|
|
exit 1
|
|
fi
|
|
grep -q "Gitea API error" "$WORK_DIR/error.log"
|
|
|
|
echo "Gitea PR metadata regression harness passed"
|