6363@click .option ('--export' , '-e' ,
6464 type = click .Path (),
6565 help = 'A file where, the validation errors can be saved.' )
66+ @click .option ('--export-type' , '-et' ,
67+ default = None ,
68+ type = click .Choice (['md' ], case_sensitive = False ),
69+ help = 'The export type that will be used for output.' )
6670@with_appcontext
67- def validate (schema_url , ana_type , ana_version , compare_with , status , export ):
71+ def validate (schema_url , ana_type , ana_version , compare_with ,
72+ status , export , export_type ):
6873 """
6974 Validate deposit or record metadata based on their schema. Provide the
7075 schema url OR ana-type and version, as well as the schema version that you
@@ -116,7 +121,9 @@ def validate(schema_url, ana_type, ana_version, compare_with, status, export):
116121 total_errors = []
117122 for pid in pids :
118123 cap_record = cap_record_class .get_record (pid )
119-
124+ cap_record_pid = cap_record .get ('_deposit' , {}).get ('id' )
125+ cap_record_cadi_id = cap_record .get ('basic_info' , {}).get ('cadi_id' )
126+ cap_host = 'https://analysispreservation.cern.ch/drafts'
120127 # get the url of the schema version, used for validation
121128 if compare_with :
122129 cap_record ['$schema' ] = schema_name_to_url (
@@ -125,8 +132,22 @@ def validate(schema_url, ana_type, ana_version, compare_with, status, export):
125132 cap_record .validate ()
126133 click .secho (f'No errors found in record { pid } ' , fg = 'green' )
127134 except DepositValidationError as exc :
128- error_list = '\n ' .join (str (err .res ) for err in exc .errors )
129- msg = f'Errors in { pid } :\n { error_list } '
135+ if export_type == 'md' :
136+ msg = '- [ ] Errors in **CADI ID:** ' + \
137+ f'{ cap_record_cadi_id or "?" } ' + \
138+ f' - **[link]({ cap_host } /{ cap_record_pid } )** :\n '
139+ msg += "\n | Field Path | Error | \n | ---------- | ----- | \n "
140+ for err in exc .errors :
141+ _err = err .res
142+ msg += f"| ```{ _err .get ('field' )} ``` |"
143+ msg += f" { _err .get ('message' )} | \n "
144+ msg += "----\n "
145+ else :
146+ error_list = '\n ' .join (str (err .res ) for err in exc .errors )
147+ msg = f'Errors in { pid } - CADI ' + \
148+ f'id: { cap_record_cadi_id or "?" } ' + \
149+ f' - { cap_host } /{ cap_record_pid } :\n { error_list } '
150+
130151 click .secho (msg , fg = 'red' )
131152
132153 if export :
0 commit comments