in infra-as-code/modules/ingest-pipeline/cf-feedback-generator/lib.py [0:0]
def get_latest_revision(self):
"""Gets the latests version of the scorecard for QAI
Returns:
str: version id
"""
try:
url = (
'https://{}/{}/projects/{}/locations/{}/qaScorecards/{}/revisions'
).format(self.insights_endpoint, self.insights_api_version, self.project_id, self.ccai_insights_location_id, self.scorecard_id)
headers = {
'charset': 'utf-8',
'Content-type': 'application/json',
'Authorization': 'Bearer {}'.format(self.oauth_token),
}
r = requests.get(url, headers=headers)
response_text = json.loads(r.text)
most_recent_revision = max(
response_text['qaScorecardRevisions'],
key=lambda x: datetime.fromisoformat(x['createTime'].replace('Z', '+00:00'))
)
return most_recent_revision['name'].split("/")[-1]
except Exception as e:
print("An error occurred while requesting the latest revision ID: {}".format(e))