Im currently working on a project where i should be able to commit Python Code via GitLab and then it will automatically run some test cases for that code and will display a result. Im facing the problem that no matter what i try, i cant get any Data of these test results to with my Code (didnt include URL and Token) `def get_test_report(pipeline_id, job_name): """ Fetches the test report for a specific job in a given pipeline from GitLab. """ url = f"{GITLAB_API_URL}/projects/{PROJECT_ID}/pipelines/{pipeline_id}/builds" headers = { "Authorization": f"Bearer {ACCESS_TOKEN}" }
response = requests.get(url, headers=headers)
if response.status_code != 200:
print(f"Error: Unable to fetch jobs for pipeline {pipeline_id}. Status code: {response.status_code}")
return None
jobs = response.json()
for job in jobs:
if job["name"] == job_name:
job_id = job["id"]
# Once the job is found, fetch the test report (if available) for the job
test_report_url = f"{GITLAB_API_URL}/projects/{PROJECT_ID}/pipelines/{pipeline_id}/test-report?job_name=python_test"
test_report_response = requests.get(test_report_url, headers=headers)
if test_report_response.status_code == 200:
return test_report_response.json()
else:
print(f"Error: Unable to fetch test report for job {job_name} in pipeline {pipeline_id}.")
return None
print(f"Error: Job {job_name} not found in pipeline {pipeline_id}.")
return None
@app.route('/pipeline/<pipeline_id>/test-results', methods=['GET']) def get_test_results(pipeline_id): """ Fetches the test results for a pipeline by retrieving the test report for specific jobs in that pipeline. """ job_name = "python_test"
test_report = get_test_report(pipeline_id, job_name)
if not test_report:
return jsonify({"message": "No test report found for this job."}), 404
return jsonify(test_report)
if name == 'main': app.run(debug=True)`
After trying to run this, there will be an error message for the .json() because im getting no data, after print debugging a bit i think it is because the authorization for gitlab is not working correctly and the code will be stuck on a login page. Does Anyone know what could help me here?