forked from bids-standard/legacy-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request bids-standard#2116 from rwblair/feat/citationcff
feat: Validate CITATION.cff
- Loading branch information
Showing
9 changed files
with
129 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { assert } from '@std/assert' | ||
import { pathsToTree } from '../files/filetree.ts' | ||
import { BIDSFileDeno } from '../files/deno.ts' | ||
import { citationValidate } from './citation.ts' | ||
import { BIDSContextDataset } from '../schema/context.ts' | ||
import { GenericSchema } from '../types/schema.ts' | ||
import { loadSchema } from '../setup/loadSchema.ts' | ||
|
||
Deno.test('citation validation', async (t) => { | ||
const schema = await loadSchema() | ||
await t.step('no errors on the good citation.cff', async () => { | ||
const tree = pathsToTree(['CITATION.cff']) | ||
const dsContext = new BIDSContextDataset({ tree }) | ||
const file = new BIDSFileDeno('tests/data/citation', 'good.cff') | ||
tree.files[0].text = () => file.text() | ||
await citationValidate({} as GenericSchema, dsContext) | ||
assert(dsContext.issues.size === 0) | ||
}) | ||
await t.step('An error on the bad citation.cff', async () => { | ||
const tree = pathsToTree(['CITATION.cff']) | ||
const dsContext = new BIDSContextDataset({ tree }) | ||
const file = new BIDSFileDeno('tests/data/citation', 'bad.cff') | ||
tree.files[0].text = () => file.text() | ||
await citationValidate({} as GenericSchema, dsContext) | ||
assert(dsContext.issues.get({ code: 'CITATION_CFF_VALIDATION_ERROR' }).length === 1) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import type { GenericSchema } from '../types/schema.ts' | ||
import type { BIDSFile, FileTree } from '../types/filetree.ts' | ||
import type { BIDSContextDataset } from '../schema/context.ts' | ||
import { schema as citationSchema } from '@bids/schema/citation' | ||
import { compile } from './json.ts' | ||
import type { DefinedError } from '@ajv' | ||
import { parse } from '@std/yaml' | ||
|
||
const citationFilename = 'CITATION.cff' | ||
|
||
export async function citationValidate( | ||
schema: GenericSchema, | ||
dsContext: BIDSContextDataset, | ||
) { | ||
const citationFile = dsContext.tree.get(citationFilename) | ||
if (!citationFile || 'directories' in citationFile) return | ||
let citation: unknown = {} | ||
try { | ||
citation = parse(await citationFile.text()) | ||
} catch (error) { | ||
dsContext.issues.add({ | ||
code: 'FILE_READ', | ||
issueMessage: `Error from attempted read of file:\n${error}`, | ||
location: citationFilename, | ||
}) | ||
return | ||
} | ||
const validate = compile(citationSchema) | ||
if (!validate(citation)) { | ||
for (const err of validate.errors as DefinedError[]) { | ||
dsContext.issues.add({ | ||
code: 'CITATION_CFF_VALIDATION_ERROR', | ||
subCode: err['instancePath'], | ||
issueMessage: err['message'], | ||
location: citationFilename, | ||
}) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
cff-version: 1.2.0 | ||
message: If you use this software, please cite it using these metadata. | ||
title: My Research Software | ||
abstract: This is my awesome research software. It does many things. | ||
version: 0.11.2 | ||
date-released: "2021-07-18" | ||
identifiers: | ||
- description: This is the collection of archived snapshots of all versions of My Research Software | ||
type: doi | ||
value: "10.5281/zenodo.123456" | ||
- description: This is the archived snapshot of version 0.11.2 of My Research Software | ||
type: doi | ||
value: "10.5281/zenodo.123457" | ||
license: Apache-2.0 | ||
repository-code: "https://github.com/citation-file-format/my-research-software" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
cff-version: 1.2.0 | ||
message: If you use this software, please cite it using these metadata. | ||
title: My Research Software | ||
abstract: This is my awesome research software. It does many things. | ||
authors: | ||
- family-names: Druskat | ||
given-names: Stephan | ||
orcid: "https://orcid.org/1234-5678-9101-1121" | ||
- name: "The Research Software project" | ||
version: 0.11.2 | ||
date-released: "2021-07-18" | ||
identifiers: | ||
- description: This is the collection of archived snapshots of all versions of My Research Software | ||
type: doi | ||
value: "10.5281/zenodo.123456" | ||
- description: This is the archived snapshot of version 0.11.2 of My Research Software | ||
type: doi | ||
value: "10.5281/zenodo.123457" | ||
license: Apache-2.0 | ||
repository-code: "https://github.com/citation-file-format/my-research-software" |