11import { Octokit } from "octokit" ;
22import * as fs from 'fs' ;
3-
3+ import { exec } from "child_process" ;
44
55const loadFromJsonfile = ( filename ) => {
66 const data = fs . readFileSync ( filename , 'utf8' ) ;
@@ -26,6 +26,40 @@ const includeHasCitationcff = async (url) => {
2626}
2727
2828
29+ const includeHasValidcff = async ( url ) => {
30+
31+ const [ owner , repo , ...unuseds ] = url . slice ( "https://github.com/" . length ) . split ( '/' ) ;
32+
33+ const { data : { default_branch } } = await octokit . request ( 'GET /repos/{owner}/{repo}' , { owner, repo } ) ;
34+
35+ const dockerCommand = `docker run --rm -i citationcff/cffconvert:2.0.0 --validate --url ${ url } /tree/${ default_branch } `
36+
37+ const checkValidString = "Citation metadata are valid according to schema"
38+
39+ const execPromise = ( command ) => {
40+ return new Promise ( function ( resolve , reject ) {
41+ exec ( command , ( error , stdout , stderr ) => {
42+ if ( error ) {
43+ reject ( error ) ;
44+ return ;
45+ }
46+ resolve ( stdout . trim ( ) ) ;
47+ } ) ;
48+ } ) ;
49+ }
50+
51+ let result ;
52+ try {
53+ result = await execPromise ( dockerCommand ) ;
54+ if ( result . includes ( checkValidString ) ) {
55+ return true ;
56+ }
57+ } catch ( error ) {
58+ }
59+
60+ }
61+
62+
2963const includeUsesPullRequests = async ( url ) => {
3064
3165 if ( npull_requests_minimum > 30 ) {
@@ -131,6 +165,7 @@ urls = await filterAsync(urls, includeUsesPullRequests);
131165urls = await filterAsync ( urls , hasMultipleChangesToCitationcff ) ;
132166urls = await filterAsync ( urls , includeUsesWorkflows ) ;
133167urls = await filterAsync ( urls , hasRecentCommits ) ;
168+ urls = await filterAsync ( urls , includeHasValidcff ) ;
134169urls = await filterAsync ( urls , hasSufficientContributors ) ;
135170urls . forEach ( url => console . log ( url ) )
136171
0 commit comments