Return error status
This commit is contained in:
@@ -15,26 +15,16 @@
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import base64
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Dict, List
|
||||
|
||||
import requests
|
||||
|
||||
from app.settings import settings
|
||||
|
||||
DATA_DIR = Path(__file__).resolve().parent.parent / "data"
|
||||
|
||||
|
||||
def _load_json(filename: str) -> Dict:
|
||||
path = DATA_DIR / filename
|
||||
with open(path, encoding="utf-8") as file:
|
||||
return json.load(file)
|
||||
|
||||
|
||||
def _sort_builds(builds: List[Dict]) -> List[Dict]:
|
||||
return sorted(builds, key=lambda build: build.get("number", 0), reverse=True)
|
||||
|
||||
|
||||
def normalize_build(build: Dict) -> Dict:
|
||||
changes = build.get("changeSets", [])
|
||||
commits = []
|
||||
@@ -58,11 +48,16 @@ def normalize_build(build: Dict) -> Dict:
|
||||
|
||||
|
||||
def _auth_header() -> Dict[str, str]:
|
||||
if not settings.jenkins_user or not settings.jenkins_token:
|
||||
return {}
|
||||
token = f"{settings.jenkins_user}:{settings.jenkins_token}"
|
||||
encoded = base64.b64encode(token.encode()).decode()
|
||||
return {"Authorization": f"Basic {encoded}"}
|
||||
|
||||
|
||||
def fetch_builds(limit: int = 5) -> List[Dict]:
|
||||
if not settings.jenkins_job_name:
|
||||
raise ValueError("JENKINS_JOB_NAME not configured")
|
||||
url = (
|
||||
f"{settings.jenkins_base_url}/job/{settings.jenkins_job_name}/api/json"
|
||||
"?tree=builds[number,url,result,timestamp,duration,"
|
||||
@@ -78,6 +73,4 @@ def fetch_builds(limit: int = 5) -> List[Dict]:
|
||||
def build_history() -> Dict:
|
||||
"""Return Jenkins build history data."""
|
||||
builds = fetch_builds()
|
||||
return {
|
||||
"builds": [normalize_build(b) for b in builds]
|
||||
}
|
||||
return {"builds": [normalize_build(b) for b in builds]}
|
||||
|
||||
Reference in New Issue
Block a user