2727"""
2828
2929import argparse
30+ import json
3031import os
3132import re
3233import shutil
3334import subprocess
3435import sys
36+ from datetime import datetime , timezone
3537from pathlib import Path
3638
3739sys .path .insert (0 , os .getcwd ())
@@ -74,6 +76,24 @@ def get_project_info(path: str):
7476 return {"name" : name , "version" : version }
7577
7678
79+ def generate_metadata_json ():
80+ try :
81+ commit_hash = subprocess .check_output (["git" , "rev-parse" , "HEAD" ],
82+ text = True ).strip ()
83+ except subprocess .CalledProcessError as e :
84+ print (f"Error retrieving git commit hash: { e } " )
85+ raise
86+
87+ data = {
88+ "commit_hash" : commit_hash ,
89+ "timestamp" : datetime .now (timezone .utc ).strftime ("%Y-%m-%dT%H:%M:%SZ" )
90+ }
91+ with open (f"{ FOLDER_SECURITY_SCANNING } /metadata.json" ,
92+ "w" ,
93+ encoding = "utf-8" ) as f :
94+ json .dump (data , f , indent = 2 )
95+
96+
7797if __name__ == "__main__" :
7898 parser = argparse .ArgumentParser (
7999 description = "Lock files generator" ,
@@ -93,6 +113,7 @@ def get_project_info(path: str):
93113 if os .path .exists (FOLDER_SECURITY_SCANNING ):
94114 shutil .rmtree (FOLDER_SECURITY_SCANNING )
95115 os .mkdir (FOLDER_SECURITY_SCANNING )
116+ generate_metadata_json ()
96117
97118 # generate pyproject.toml and poetry.lock files in the same location
98119 for path in paths :
0 commit comments