Coverage for src / eclipse / care / utils / eclipse.py: 70%
23 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-24 09:38 +0100
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-24 09:38 +0100
1# Copyright (c) 2025 The Eclipse Foundation
2#
3# This program and the accompanying materials are made available under the
4# terms of the Eclipse Public License 2.0 which is available at
5# http://www.eclipse.org/legal/epl-2.0.
6#
7# SPDX-License-Identifier: EPL-2.0
8#
9# Contributors:
10# Boris Baldassari - Initial implementation
12import sys
13import requests
16class Eclipse:
17 """A Class to retrieve all Eclipse-related information, in the context
18 of the EMO needs.
20 """
22 def __init__(self, verbose: bool = False):
23 """Initialises a class to interact with Eclipse-based data sources.
25 Parameters
26 ----------
27 verbose : bool
28 Boolean to display more information on stdout (optional).
29 """
31 if verbose:
32 print("Initialising Eclipse ")
36 def get_project_api(self, project_id: str, verbose: bool = False):
37 """
38 Retrieves project information from the Eclipse API.
40 Parameters
41 ----------
42 project_id : str
43 The project ID to look for, e.g. `technology.dash`.
44 verbose : bool
45 Boolean to display more information on stdout (optional).
46 """
48 # URL for the Eclipse API for projects.
49 url = "https://projects.eclipse.org/api/projects/" + project_id
51 if verbose:
52 print(f" Retrieving project API from {url}.")
53 try:
54 response = requests.get(url)
55 if response.status_code == 200:
56 data = response.json()
57 else:
58 print(f"Failed to get project from API: {response.status_code}.")
59 return None
60 except requests.exceptions.RequestException as e:
61 print(f"Error (RequestException) fetching API data: {e}.")
62 return None
64 if data[0]['project_id'] == project_id:
65 return data[0]
66 else:
67 print("Failed to get project from API.")
68 return None