Skip to content

Commit

Permalink
Merge pull request #10 from zenodraft/9-upserting-date-precision
Browse files Browse the repository at this point in the history
upserting date precision
  • Loading branch information
jspaaks authored Jun 30, 2021
2 parents 9cbadf8 + 5dba83c commit 5644867
Show file tree
Hide file tree
Showing 39 changed files with 146 additions and 1,371 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `zenodraft/action@0.9.0` PRERELEASE
# `zenodraft/action@0.9.1` PRERELEASE

Automates drafting depositions on Zenodo or Zenodo Sandbox.

Expand Down Expand Up @@ -34,7 +34,7 @@ jobs:
from repository file .zenodo.json
env:
ZENODO_SANDBOX_ACCESS_TOKEN: ${{ secrets.ZENODO_SANDBOX_ACCESS_TOKEN }}
uses: zenodraft/action@0.9.0
uses: zenodraft/action@0.9.1
with:
collection: 1234567
metadata: .zenodo.json
Expand Down
14 changes: 13 additions & 1 deletion lib/upserting.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,19 @@ const upsert_prereserved_doi = (upsert_location, prereserved_doi) => {
};
exports.upsert_prereserved_doi = upsert_prereserved_doi;
const write_cff_file = (cff) => {
const cffstr = yaml.dump(cff, { sortKeys: false });
let cffstr = yaml.dump(cff, { sortKeys: false });
// replace full precision dates with just YYYY-MM-DD before writing to file
const regexes = [
new RegExp('(?<k>date-accessed): (?<v>[0-9]{4}-[0-9]{2}-[0-9]{2})T00:00:00.000Z', 'g'),
new RegExp('(?<k>date-downloaded): (?<v>[0-9]{4}-[0-9]{2}-[0-9]{2})T00:00:00.000Z', 'g'),
new RegExp('(?<k>date-published): (?<v>[0-9]{4}-[0-9]{2}-[0-9]{2})T00:00:00.000Z', 'g'),
new RegExp('(?<k>date-released): (?<v>[0-9]{4}-[0-9]{2}-[0-9]{2})T00:00:00.000Z', 'g'),
new RegExp('(?<k>date-end): (?<v>[0-9]{4}-[0-9]{2}-[0-9]{2})T00:00:00.000Z', 'g'),
new RegExp('(?<k>date-start): (?<v>[0-9]{4}-[0-9]{2}-[0-9]{2})T00:00:00.000Z', 'g')
];
for (const regex of regexes) {
cffstr = cffstr.replace(regex, '$<k>: $<v>');
}
fs.writeFileSync('CITATION.cff', cffstr, 'utf8');
return;
};
11 changes: 9 additions & 2 deletions node_modules/zenodraft/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node_modules/zenodraft/assets/autocomplete.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node_modules/zenodraft/dist/cli.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node_modules/zenodraft/dist/cli.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 17 additions & 18 deletions node_modules/zenodraft/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@actions/github": "^5.0.0",
"js-yaml": "^4.1.0",
"typescript": "^4.3.2",
"zenodraft": "git+https://github.com/zenodraft/zenodraft.git#0.9.0"
"zenodraft": "0.9.1"
},
"description": "GitHub action to automate making draft depositions on Zenodo or Zenodo Sandbox",
"homepage": "https://github.com/zenodraft/action#readme",
Expand All @@ -33,7 +33,7 @@
"test": "jest --config jest.config.js",
"transpile": "tsc -p tsconfig.json"
},
"version": "0.9.0",
"version": "0.9.1",
"devDependencies": {
"@types/jest": "^26.0.23",
"@types/js-yaml": "^4.0.1",
Expand Down
14 changes: 13 additions & 1 deletion src/upserting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,19 @@ export const upsert_prereserved_doi = (upsert_location: string, prereserved_doi:


const write_cff_file = (cff: CffObject): void => {
const cffstr = yaml.dump(cff, { sortKeys: false })
let cffstr = yaml.dump(cff, { sortKeys: false })
// replace full precision dates with just YYYY-MM-DD before writing to file
const regexes = [
new RegExp('(?<k>date-accessed): (?<v>[0-9]{4}-[0-9]{2}-[0-9]{2})T00:00:00.000Z', 'g'),
new RegExp('(?<k>date-downloaded): (?<v>[0-9]{4}-[0-9]{2}-[0-9]{2})T00:00:00.000Z', 'g'),
new RegExp('(?<k>date-published): (?<v>[0-9]{4}-[0-9]{2}-[0-9]{2})T00:00:00.000Z', 'g'),
new RegExp('(?<k>date-released): (?<v>[0-9]{4}-[0-9]{2}-[0-9]{2})T00:00:00.000Z', 'g'),
new RegExp('(?<k>date-end): (?<v>[0-9]{4}-[0-9]{2}-[0-9]{2})T00:00:00.000Z', 'g'),
new RegExp('(?<k>date-start): (?<v>[0-9]{4}-[0-9]{2}-[0-9]{2})T00:00:00.000Z', 'g')
]
for (const regex of regexes) {
cffstr = cffstr.replace(regex, '$<k>: $<v>')
}
fs.writeFileSync('CITATION.cff', cffstr, 'utf8')
return
}
49 changes: 0 additions & 49 deletions tests/upserting/1.0.3/doi/append/upserting.test.js

This file was deleted.

49 changes: 0 additions & 49 deletions tests/upserting/1.0.3/doi/overwrite/upserting.test.js

This file was deleted.

55 changes: 0 additions & 55 deletions tests/upserting/1.0.3/errors/upserting.test.js

This file was deleted.

21 changes: 21 additions & 0 deletions tests/upserting/1.1.0/dates/CITATION.cff
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
authors:
- name: anonymous
cff-version: 1.1.0
date-released: 2020-12-31
doi: 10.0000/FIXME
message: testing dates
references:
- authors:
- name: anonymous
date-accessed: 2020-11-30
date-downloaded: 2020-10-30
date-published: 2020-09-30
date-released: 2020-08-30
type: conference
title: reference title
conference:
name: some conference
date-end: 2020-02-02
date-start: 2020-01-30
title: testing dates
version: 0.0.0
Loading

0 comments on commit 5644867

Please sign in to comment.