Skip to content

Commit 513ba5e

Browse files
authored
Merge pull request #47 from cffbots/validcff-filter
add filter to validate CITATION.cff using Docker image
2 parents 8423b2a + 5ea4c91 commit 513ba5e

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

query.mjs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Octokit } from "octokit";
22
import * as fs from 'fs';
3-
3+
import { exec } from "child_process";
44

55
const 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+
2963
const includeUsesPullRequests = async (url) => {
3064

3165
if (npull_requests_minimum > 30) {
@@ -131,6 +165,7 @@ urls = await filterAsync(urls, includeUsesPullRequests);
131165
urls = await filterAsync(urls, hasMultipleChangesToCitationcff);
132166
urls = await filterAsync(urls, includeUsesWorkflows);
133167
urls = await filterAsync(urls, hasRecentCommits);
168+
urls = await filterAsync(urls, includeHasValidcff);
134169
urls = await filterAsync(urls, hasSufficientContributors);
135170
urls.forEach(url => console.log(url))
136171

0 commit comments

Comments
 (0)