diff --git a/arXivSearches.json b/arXivSearches.json index ba12151..5eb6f94 100644 --- a/arXivSearches.json +++ b/arXivSearches.json @@ -1,458 +1,818 @@ [ { - "id": "http://arxiv.org/abs/1910.12614v1", + "id": { + "repository": "arXiv", + "article": "1910.12614", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1809.09841v1", + "id": { + "repository": "arXiv", + "article": "1809.09841", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1907.07769v1", + "id": { + "repository": "arXiv", + "article": "1907.07769", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1909.06805v3", + "id": { + "repository": "arXiv", + "article": "1909.07655", + "version": "2" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1909.07655v2", + "id": { + "repository": "arXiv", + "article": "1906.10508", + "version": "3" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1906.10508v3", + "id": { + "repository": "arXiv", + "article": "1903.04124", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1903.04124v1", + "id": { + "repository": "arXiv", + "article": "1905.05879", + "version": "2" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1905.05879v2", + "id": { + "repository": "arXiv", + "article": "1910.00067", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1910.00067v1", + "id": { + "repository": "arXiv", + "article": "1910.03713", + "version": "2" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1910.03713v2", + "id": { + "repository": "arXiv", + "article": "1907.08940", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1912.01852v1", + "id": { + "repository": "arXiv", + "article": "1804.02812", + "version": "2" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1907.08940v1", + "id": { + "repository": "arXiv", + "article": "1808.05294", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1804.02812v2", + "id": { + "repository": "arXiv", + "article": "1811.08111", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1808.05294v1", + "id": { + "repository": "arXiv", + "article": "1804.04262", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1811.08111v1", + "id": { + "repository": "arXiv", + "article": "1808.08311", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1804.04262v1", + "id": { + "repository": "arXiv", + "article": "1902.03705", + "version": "2" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1808.08311v1", + "id": { + "repository": "arXiv", + "article": "1903.12389", + "version": "2" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1902.03705v2", + "id": { + "repository": "arXiv", + "article": "1904.03522", + "version": "3" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1903.12389v2", + "id": { + "repository": "arXiv", + "article": "1906.00794", + "version": "2" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1904.03522v3", + "id": { + "repository": "arXiv", + "article": "1912.02461", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1906.00794v2", + "id": { + "repository": "arXiv", + "article": "1512.01809", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1911.03934v1", + "id": { + "repository": "arXiv", + "article": "1808.03113", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1912.02461v1", + "id": { + "repository": "arXiv", + "article": "1904.08352", + "version": "2" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1512.01809v1", - "status": "candidate" - }, - { - "id": "http://arxiv.org/abs/1808.03113v1", - "status": "candidate" - }, - { - "id": "http://arxiv.org/abs/1810.06865v4", - "status": "candidate" - }, - { - "id": "http://arxiv.org/abs/1904.08352v2", - "status": "candidate" - }, - { - "id": "http://arxiv.org/abs/1510.04205v1", + "id": { + "repository": "arXiv", + "article": "1510.04205", + "version": "1" + }, "status": "confirmed" }, { - "id": "http://arxiv.org/abs/1610.03988v1", + "id": { + "repository": "arXiv", + "article": "1610.03988", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1612.07523v1", + "id": { + "repository": "arXiv", + "article": "1612.07523", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1704.00849v3", + "id": { + "repository": "arXiv", + "article": "1704.00849", + "version": "3" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1712.08363v2", + "id": { + "repository": "arXiv", + "article": "1712.08363", + "version": "2" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1804.00425v1", + "id": { + "repository": "arXiv", + "article": "1804.00425", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1806.02169v2", + "id": { + "repository": "arXiv", + "article": "1806.02169", + "version": "2" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1811.01609v2", + "id": { + "repository": "arXiv", + "article": "1811.01609", + "version": "2" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1811.04076v1", + "id": { + "repository": "arXiv", + "article": "1811.04076", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1811.11078v2", + "id": { + "repository": "arXiv", + "article": "1811.11078", + "version": "2" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1904.05742v4", + "id": { + "repository": "arXiv", + "article": "1904.05742", + "version": "4" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1904.06590v3", + "id": { + "repository": "arXiv", + "article": "1904.06590", + "version": "3" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1905.02525v1", + "id": { + "repository": "arXiv", + "article": "1905.02525", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1909.03974v2", + "id": { + "repository": "arXiv", + "article": "1909.03974", + "version": "2" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1909.06532v1", + "id": { + "repository": "arXiv", + "article": "1909.06532", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1910.00496v1", + "id": { + "repository": "arXiv", + "article": "1910.00496", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1910.11269v1", + "id": { + "repository": "arXiv", + "article": "1910.11269", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1911.06149v2", + "id": { + "repository": "arXiv", + "article": "1911.06149", + "version": "2" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1912.05289v1", + "id": { + "repository": "arXiv", + "article": "1912.06813", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1912.06813v1", + "id": { + "repository": "arXiv", + "article": "1912.11984", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1912.11984v1", + "id": { + "repository": "arXiv", + "article": "1804.08438", + "version": "2" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1804.08438v2", + "id": { + "repository": "arXiv", + "article": "1907.11898", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1907.11898v1", + "id": { + "repository": "arXiv", + "article": "1704.02360", + "version": "4" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1704.02360v4", + "id": { + "repository": "arXiv", + "article": "1711.11293", + "version": "2" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1711.11293v2", + "id": { + "repository": "arXiv", + "article": "1803.00860", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1803.00860v1", + "id": { + "repository": "arXiv", + "article": "1804.11055", + "version": "2" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1804.11055v2", + "id": { + "repository": "arXiv", + "article": "1808.05092", + "version": "2" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1808.05092v2", + "id": { + "repository": "arXiv", + "article": "1808.09634", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1808.09634v1", + "id": { + "repository": "arXiv", + "article": "1904.04631", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1904.04631v1", + "id": { + "repository": "arXiv", + "article": "1905.00615", + "version": "2" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1905.00615v2", + "id": { + "repository": "arXiv", + "article": "1905.11563", + "version": "3" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1905.11563v3", + "id": { + "repository": "arXiv", + "article": "1907.10185", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1907.10185v1", + "id": { + "repository": "arXiv", + "article": "1907.12279", + "version": "2" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1907.12279v2", + "id": { + "repository": "arXiv", + "article": "1908.01454", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1908.01454v1", - "status": "candidate" - }, - { - "id": "http://arxiv.org/abs/1012.1416v1", + "id": { + "repository": "arXiv", + "article": "1012.1416", + "version": "1" + }, "status": "excluded" }, { - "id": "http://arxiv.org/abs/1502.03387v1", - "status": "candidate" - }, - { - "id": "http://arxiv.org/abs/1603.04264v1", + "id": { + "repository": "arXiv", + "article": "1502.03387", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1511.04867v2", + "id": { + "repository": "arXiv", + "article": "1603.04264", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1610.04019v1", + "id": { + "repository": "arXiv", + "article": "1511.04867", + "version": "2" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1610.08927v1", + "id": { + "repository": "arXiv", + "article": "1610.04019", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1804.09593v1", + "id": { + "repository": "arXiv", + "article": "1610.08927", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1810.11520v2", + "id": { + "repository": "arXiv", + "article": "1804.09593", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1810.12656v3", + "id": { + "repository": "arXiv", + "article": "1810.11520", + "version": "2" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1901.08025v1", + "id": { + "repository": "arXiv", + "article": "1810.12656", + "version": "3" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1904.01120v1", + "id": { + "repository": "arXiv", + "article": "1901.08025", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1904.05576v1", + "id": { + "repository": "arXiv", + "article": "1904.01120", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1905.03864v1", + "id": { + "repository": "arXiv", + "article": "1904.05576", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1905.12531v1", + "id": { + "repository": "arXiv", + "article": "1905.03864", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1908.03632v1", + "id": { + "repository": "arXiv", + "article": "1905.12531", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1908.06248v1", + "id": { + "repository": "arXiv", + "article": "1908.03632", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1910.13345v1", + "id": { + "repository": "arXiv", + "article": "1908.06248", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1912.02613v1", + "id": { + "repository": "arXiv", + "article": "1910.13345", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1912.10128v1", + "id": { + "repository": "arXiv", + "article": "1912.10128", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1911.01601v1", - "status": "candidate" - }, - { - "id": "http://arxiv.org/abs/1409.1415v1", + "id": { + "repository": "arXiv", + "article": "1409.1415", + "version": "1" + }, "status": "excluded" }, { - "id": "http://arxiv.org/abs/1507.06711v2", - "status": "candidate" - }, - { - "id": "http://arxiv.org/abs/1709.08041v1", - "status": "candidate" - }, - { - "id": "http://arxiv.org/abs/1711.11460v1", + "id": { + "repository": "arXiv", + "article": "1507.06711", + "version": "2" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1801.06492v1", + "id": { + "repository": "arXiv", + "article": "1709.08041", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1804.03201v2", + "id": { + "repository": "arXiv", + "article": "1711.11460", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1805.02958v1", + "id": { + "repository": "arXiv", + "article": "1801.06492", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1809.10288v2", + "id": { + "repository": "arXiv", + "article": "1804.03201", + "version": "2" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1904.04540v1", + "id": { + "repository": "arXiv", + "article": "1805.02958", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1904.07453v1", + "id": { + "repository": "arXiv", + "article": "1809.10288", + "version": "2" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1907.00501v1", + "id": { + "repository": "arXiv", + "article": "1904.04540", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1911.02933v1", + "id": { + "repository": "arXiv", + "article": "1907.00501", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1603.03947v3", + "id": { + "repository": "arXiv", + "article": "1603.03947", + "version": "3" + }, "status": "excluded" }, { - "id": "http://arxiv.org/abs/2001.01401v1", + "id": { + "repository": "arXiv", + "article": "2001.01401", + "version": "1" + }, "status": "confirmed" }, { - "id": "http://arxiv.org/abs/1810.06865v5", + "id": { + "repository": "arXiv", + "article": "1810.06865", + "version": "5" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1912.05289v2", + "id": { + "repository": "arXiv", + "article": "1912.05289", + "version": "2" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/2001.07849v1", - "status": "candidate" - }, - { - "id": "http://arxiv.org/abs/1904.07453v2", + "id": { + "repository": "arXiv", + "article": "1904.07453", + "version": "2" + }, "status": "excluded" }, { - "id": "http://arxiv.org/abs/2001.09723v1", + "id": { + "repository": "arXiv", + "article": "2001.09723", + "version": "1" + }, "status": "excluded" }, { - "id": "http://arxiv.org/abs/1912.02613v2", - "status": "candidate" - }, - { - "id": "http://arxiv.org/abs/1911.02933v2", + "id": { + "repository": "arXiv", + "article": "1911.02933", + "version": "2" + }, "status": "confirmed" }, { - "id": "http://arxiv.org/abs/1909.06805v4", - "status": "candidate" - }, - { - "id": "http://arxiv.org/abs/2002.00198v1", + "id": { + "repository": "arXiv", + "article": "1909.06805", + "version": "4" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/2001.07849v2", + "id": { + "repository": "arXiv", + "article": "2002.00198", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/2001.07849v3", + "id": { + "repository": "arXiv", + "article": "2001.07849", + "version": "3" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/2002.03808v1", + "id": { + "repository": "arXiv", + "article": "2002.03808", + "version": "1" + }, "status": "confirmed" }, { - "id": "http://arxiv.org/abs/1911.03934v2", + "id": { + "repository": "arXiv", + "article": "1911.03934", + "version": "2" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/2002.06328v1", + "id": { + "repository": "arXiv", + "article": "2002.06328", + "version": "1" + }, "status": "confirmed" }, { - "id": "http://arxiv.org/abs/2002.06778v1", + "id": { + "repository": "arXiv", + "article": "2002.06778", + "version": "1" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1912.01852v2", + "id": { + "repository": "arXiv", + "article": "1912.01852", + "version": "2" + }, "status": "candidate" }, { - "id": "http://arxiv.org/abs/1912.02613v3", + "id": { + "repository": "arXiv", + "article": "1912.02613", + "version": "3" + }, "status": "confirmed" }, { - "id": "http://arxiv.org/abs/1911.01601v2", + "id": { + "repository": "arXiv", + "article": "1911.01601", + "version": "2" + }, "status": "candidate" } ] diff --git a/jest.config.js b/jest.config.js index 5401636..ebf76fd 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,4 +1,5 @@ module.exports = { preset: "ts-jest/presets/js-with-ts", - testEnvironment: "node" + testEnvironment: "node", + testPathIgnorePatterns: ["/node_modules/", "/dist/"] }; diff --git a/package-lock.json b/package-lock.json index b38cf33..c0362ec 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5034,9 +5034,9 @@ } }, "immer": { - "version": "5.3.6", - "resolved": "https://registry.npmjs.org/immer/-/immer-5.3.6.tgz", - "integrity": "sha512-pqWQ6ozVfNOUDjrLfm4Pt7q4Q12cGw2HUZgry4Q5+Myxu9nmHRkWBpI0J4+MK0AxbdFtdMTwEGVl7Vd+vEiK+A==" + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/immer/-/immer-5.1.0.tgz", + "integrity": "sha512-t6gyFtTcokCuI0tX9KQZJQAkIjSqo/nTeJnwojfty69EzrorZbywwhZ8qNNlF+faajHeRnhOvM2F40KHLFCghQ==" }, "import-fresh": { "version": "3.2.1", diff --git a/package.json b/package.json index f681bd0..486beee 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "@actions/core": "^1.2.0", "@actions/github": "^2.0.0", "@octokit/webhooks": "^7.0.0", - "immer": "^5.3.6", + "immer": "^5.1.0", "node-fetch": "^2.6.0", "oauth-1.0a": "^2.2.6", "strict-uri-encode": "^2.0.0", diff --git a/src/ConfirmationAction.ts b/src/ConfirmationAction.ts index 05eec21..1cffcb3 100644 --- a/src/ConfirmationAction.ts +++ b/src/ConfirmationAction.ts @@ -4,7 +4,7 @@ import { searchArXivByID } from "./arXivSearch"; import { ArXivStorage } from "./domain"; import { tweet } from "./twitter"; import * as WebhooksApi from "@octokit/webhooks"; -import { updateArticleStatus } from "./updateArticles"; +import { updateArticleStatus, arXivID2identity } from "./updateArticles"; async function run(): Promise { //@ts-ignore @@ -16,7 +16,7 @@ async function run(): Promise { const regResult = idRegExp.exec(issueCommentPayload.issue.body); // regResult == null means the issue is not for article confirmation if (regResult != null) { - const id = regResult[1]; + const arXivID = regResult[1]; // extract judge const c = /\[vclab::confirmed\]|\[confirmed\]|vclab::confirmed/; @@ -25,7 +25,7 @@ async function run(): Promise { const isC = c.exec(issueCommentPayload.comment.body); const isE = e.exec(issueCommentPayload.comment.body); - // make thunks toward contribution + // make thanks toward contribution if (isC !== null || isE !== null) { const octokit = new github.GitHub(core.getInput("token")); // reply thunks in comment @@ -61,29 +61,35 @@ async function run(): Promise { ); //// update storage const judgeResult = isC !== null ? "confirmed" : "excluded"; - const newStorage = updateArticleStatus(storage, id, judgeResult); + const identity = arXivID2identity(arXivID); + const newStorage = updateArticleStatus( + storage, + identity.article, + judgeResult + ); //// commit storage update const blob = Buffer.from(JSON.stringify(newStorage, undefined, 2)); await octokit.repos .createOrUpdateFile({ ...github.context.repo, path: "arXivSearches.json", - message: `Add arXiv paper confirmation ${id}`, + message: `Add arXiv paper confirmation ${identity.repository}-${identity.article}`, content: blob.toString("base64"), // @ts-ignore sha: contents.data.sha }) .catch(err => core.setFailed(err)); + // Tweet if "confirmed" (== VC paper) if (isC !== null) { console.log("is [vclab::confirmed]"); const arXivIDRegResult = /http:\/\/arxiv.org\/abs\/([a-z.0-9]+)/.exec( - id + arXivID ); if (arXivIDRegResult !== null) { - const arXivID = arXivIDRegResult[1]; - const paper = await searchArXivByID(arXivID); - const content = `[[VC paper]]\n"${paper.title}"\narXiv: ${id}`; + const arXivSearchID = arXivIDRegResult[1]; + const paper = await searchArXivByID(arXivSearchID); + const content = `[[VC paper]]\n"${paper.title}"\narXiv: ${arXivSearchID}`; // tweet confirmed paper await tweet( content, @@ -101,7 +107,7 @@ async function run(): Promise { }); console.log("tweet created."); } else { - core.setFailed(`arXiv ID search failure for ${id}`); + core.setFailed(`arXiv ID search failure for ${arXivID}`); } } else if (isE !== null) { console.log("is [vclab::excluded]"); diff --git a/src/PullShareAction.ts b/src/PullShareAction.ts index c64ff52..c21c63b 100644 --- a/src/PullShareAction.ts +++ b/src/PullShareAction.ts @@ -1,8 +1,64 @@ import * as core from "@actions/core"; import * as github from "@actions/github"; import { searchArXiv } from "./arXivSearch"; -import { ArXivStorage } from "./domain"; +import { + ArXivStorage, + ArXivSearchResults, + ArXivRecord, + SearchedPaper, + Identity +} from "./domain"; import { tweet } from "./twitter"; +import { arXivID2identity } from "./updateArticles"; + +function findNewPaper( + searchResults: ArXivSearchResults, + storage: ArXivStorage +): [SearchedPaper, ArXivRecord] | undefined { + // find non-match (==new) arXivPaper (version update is excluded) + const newPapers = searchResults.filter(paper => { + const articleID = arXivID2identity(paper.id).article; + return storage.every(record => record.id.article !== articleID); + }); + if (newPapers.length === 0) { + return undefined; + } else { + const theNewPaper = newPapers[0]; + const identity = arXivID2identity(theNewPaper.id); + return [ + theNewPaper, + { + id: identity, + status: "candidate" + } + ]; + } +} + +/** + * Find versionUp-ed paper in arXiv + */ +function findUpdatedPaper( + searchResults: ArXivSearchResults, + storage: ArXivStorage +): [SearchedPaper, Identity] | undefined { + // + const updatedPaperCand = searchResults.find(paper => { + const paperID = arXivID2identity(paper.id); + // There is a record which match the articleID but not match version in storage + return storage.some( + record => + record.id.article === paperID.article && + record.id.version !== paperID.version + ); + }); + if (updatedPaperCand === undefined) { + return undefined; + } else { + const identity = arXivID2identity(updatedPaperCand.id); + return [updatedPaperCand, identity]; + } +} async function run(): Promise { // fetch search result @@ -23,26 +79,19 @@ async function run(): Promise { ).toString() ); - // find non-match (==new) arXivPaper - const newPapers = searchResults.filter(paper => - storage.every(record => record.id !== paper.id) - ); - - // add to storage with [candidate] status - if (newPapers.length > 0) { - const theNewPaper = newPapers[0]; - storage.push({ - id: theNewPaper.id, - status: "candidate" - }); - + const newPaperCand = findNewPaper(searchResults, storage); + if (newPaperCand !== undefined) { + const theNewPaper = newPaperCand[0]; + const newRecord = newPaperCand[1]; + // storage update + storage.push(newPaperCand[1]); // commit storage update const blob = Buffer.from(JSON.stringify(storage, undefined, 2)); await octokit.repos .createOrUpdateFile({ ...github.context.repo, path: "arXivSearches.json", - message: `Add new arXiv search result ${theNewPaper.id}`, + message: `Add new arXiv search result ${newRecord.id.article}`, content: blob.toString("base64"), // @ts-ignore sha: contents.data.sha @@ -54,7 +103,7 @@ async function run(): Promise { await octokit.issues .create({ ...github.context.repo, - title: `'Voice Conversion' paper candidate ${theNewPaper.id}`, + title: `'Voice Conversion' paper candidate ${newRecord.id.article}`, body: `Please check whether this paper is about 'Voice Conversion' or not.\n## article info.\n- title: **${theNewPaper.title}**\n- summary: ${theNewPaper.summary}\n- id: ${theNewPaper.id}\n## judge\nWrite [vclab::confirmed] or [vclab::excluded] in comment.` }) .catch(err => core.setFailed(err)); @@ -76,6 +125,57 @@ async function run(): Promise { core.setFailed(err); }); console.log("tweet created."); + return; + } + + // paper update (if newPaper, already returned after Tweet) + const updatedPaperCand = findUpdatedPaper(searchResults, storage); + if (updatedPaperCand !== undefined) { + const updatedPaper = updatedPaperCand[0]; + const paperID = updatedPaperCand[1]; + // storage update (version only update) + const indexInStorage = storage.findIndex( + record => record.id.article === paperID.article + ); + if (indexInStorage === -1) { + throw new Error("this should exist"); + } + const record = storage[indexInStorage]; + record.id.version = paperID.version; + + // commit storage update + const blob = Buffer.from(JSON.stringify(storage, undefined, 2)); + await octokit.repos + .createOrUpdateFile({ + ...github.context.repo, + path: "arXivSearches.json", + message: `Update arXiv search result ${paperID.article}@${paperID.version}`, + content: blob.toString("base64"), + // @ts-ignore + sha: contents.data.sha + }) + .catch(err => core.setFailed(err)); + console.log("storage updated (version update)"); + + // do NOT open issue because version up do not change "VC paper or not" + + // tweet candidate info + await tweet( + `[paper version up]\n"${updatedPaper.title}"\narXiv: ${updatedPaper.id}`, + core.getInput("twi-cons-key"), + core.getInput("twi-cons-secret"), + core.getInput("twi-token-key"), + core.getInput("twi-token-secret") + ) + .then(res => { + console.log(res.status); + return res.text(); + }) + .catch(err => { + core.setFailed(err); + }); + console.log("tweet created."); + return; } } diff --git a/src/domain.ts b/src/domain.ts index a2972db..d237d65 100644 --- a/src/domain.ts +++ b/src/domain.ts @@ -9,8 +9,13 @@ export type ArXivSearchResults = SearchedPaper[]; // points: this is merely arXiv search result storage (status is for refined search) export type candidate = "candidate"; export type resolved = "confirmed" | "excluded"; +export type Identity = { + repository: "arXiv"; + article: string; + version: string; +}; export type ArXivRecord = { - id: string; + id: Identity; status: candidate | resolved; }; export type ArXivStorage = ArXivRecord[]; diff --git a/src/updateArticles.test.ts b/src/updateArticles.test.ts index 93268d7..a69d71a 100644 --- a/src/updateArticles.test.ts +++ b/src/updateArticles.test.ts @@ -4,11 +4,11 @@ import { ArXivStorage } from "./domain"; test("updateArticles", () => { const input: ArXivStorage = [ { - id: "1", + id: { repository: "arXiv", article: "1", version: "1" }, status: "candidate" }, { - id: "2", + id: { repository: "arXiv", article: "2", version: "2" }, status: "candidate" } ]; @@ -16,11 +16,11 @@ test("updateArticles", () => { const expected: ArXivStorage = [ { - id: "1", + id: { repository: "arXiv", article: "1", version: "1" }, status: "candidate" }, { - id: "2", + id: { repository: "arXiv", article: "2", version: "2" }, status: "confirmed" } ]; diff --git a/src/updateArticles.ts b/src/updateArticles.ts index cc9d9f8..358a30d 100644 --- a/src/updateArticles.ts +++ b/src/updateArticles.ts @@ -1,14 +1,27 @@ -import { ArXivStorage, resolved } from "./domain"; +import { ArXivStorage, resolved, Identity } from "./domain"; import { produce } from "immer"; +export function arXivID2identity(arXivID: string): Identity { + const result = /http:\/\/arxiv.org\/abs\/(\d+\.\d+)v(\d+)/.exec(arXivID); + if (result && result.length >= 3) { + return { + repository: "arXiv", + article: result[1], + version: result[2] + }; + } else { + throw new Error("arXivID parse error"); + } +} + export function updateArticleStatus( storage: ArXivStorage, - id: string, + articleID: string, status: resolved ): ArXivStorage { return produce(storage, draft => { // find index - const index = draft.findIndex(paper => paper.id === id); + const index = draft.findIndex(paper => paper.id.article === articleID); draft[index].status = status; }); }