diff --git a/CodecheckPlugin.php b/CodecheckPlugin.php index 2c462a72..557fc50d 100644 --- a/CodecheckPlugin.php +++ b/CodecheckPlugin.php @@ -115,15 +115,18 @@ public function validatePublicationHook(string $hookName, array $args): bool public function addCodecheckStatusLocalizations($hookName, $args) { $templateMgr = $args[0]; + + $localeKeys = array_combine( + Constants::CODECHECK_STATUSES, + array_map(fn($status) => __($status), Constants::CODECHECK_STATUSES) + ); + + $localeKeys[Constants::CODECHECK_STATUS_PENDING] = __(Constants::CODECHECK_STATUS_PENDING); + $templateMgr->addJavaScript( 'codecheck-locale-status', 'pkp.localeKeys = pkp.localeKeys || {};' . - 'Object.assign(pkp.localeKeys, ' . json_encode( - array_combine( - Constants::CODECHECK_STATUSES, - array_map(fn($status) => __($status), Constants::CODECHECK_STATUSES) - ) - ) . ');', + 'Object.assign(pkp.localeKeys, ' . json_encode($localeKeys) . ');', ['inline' => true, 'contexts' => ['backend']] ); return false; diff --git a/api/v1/CodecheckApiHandler.php b/api/v1/CodecheckApiHandler.php index 96292c0f..ccda7cd4 100644 --- a/api/v1/CodecheckApiHandler.php +++ b/api/v1/CodecheckApiHandler.php @@ -611,6 +611,7 @@ private function reserveIdentifierWithApi( array $repositories ): array { + $updateInformation = $this->plugin->getSetting($this->request->getContext()->getId(), Constants::CODECHECK_GITHUB_REGISTER_ISSUE_UPDATE_FIELDS); // Add the new issue to the CODECHECK GtiHub Register $issue = $codecheckGithubRegisterApiClient->addIssue( $identifier, @@ -618,7 +619,8 @@ private function reserveIdentifierWithApi( $articleTitle, $authorString, $codecheckers, - $repositories + $repositories, + $updateInformation ); return $issue; @@ -640,8 +642,9 @@ private function reserveIdentifierWithNewIssueUrl( array $repositories ): string { - $journalName = $this->request->getContext()?->getLocalizedName() ?? 'Unknwon Journal'; - + $context = $this->request->getContext(); + $journalName = $context?->getLocalizedName() ?? 'Unknwon Journal'; + $updateInformation = $this->plugin->getSetting($context->getId(), Constants::CODECHECK_GITHUB_REGISTER_ISSUE_UPDATE_FIELDS); $codecheckIssue = new CodecheckGithubRegisterIssue( $githubRegisterOrganization, $githubRegisterRepository, @@ -652,7 +655,8 @@ private function reserveIdentifierWithNewIssueUrl( $authorString, $this->codecheckMetadataHandler->getSubmissionId(), $codecheckers, - $repositories + $repositories, + $updateInformation ); return $codecheckIssue->getNewIssueUrl(); @@ -972,15 +976,6 @@ public function getCurrentStatus(): void $statusRecord = CodecheckStatusHandler::getCurrentStatusData($submissionId); - if($statusRecord == null) { - JsonResponse::staticResponse([ - 'success' => false, - 'error' => "There doesn't exist any Status in the OJS Databse for this submission Id yet.", - 'statusRecord' => null, - 'allStatuses' => Constants::CODECHECK_STATUSES, - ], 500); - } - JsonResponse::staticResponse([ 'success' => true, 'statusRecord' => $statusRecord, @@ -990,14 +985,18 @@ public function getCurrentStatus(): void public function getStatusHistory(): void { + CodecheckLogger::debug("Get Status History"); $submissionId = (int) $this->codecheckMetadataHandler->getSubmissionId(); $statusHistory = CodecheckStatusHandler::getStatusDataHistory($submissionId); - if($statusHistory == null) { + CodecheckLogger::debug(print_r($statusHistory, true)); + + if(empty($statusHistory)) { JsonResponse::staticResponse([ 'success' => false, - 'statusHistory' => $statusHistory, + 'error' => "Currently there is no recorded CODECHECK status history for this submission ID in the OJS database.", + 'statusHistory' => null, ], 400); } @@ -1038,13 +1037,13 @@ public function updateStatus(): void } $statusUpdate = CodecheckStatusHandler::automaticStatusUpdate($submissionMetadata); - if($statusUpdate == null) { + if(empty($statusUpdate)) { JsonResponse::staticResponse([ 'success' => false, 'statusRecord' => $statusUpdate, 'allStatuses' => Constants::CODECHECK_STATUSES, 'error' => "Status doesn't need to be automatically updated." - ], 200); + ], 400); } else { JsonResponse::staticResponse([ 'success' => true, diff --git a/classes/CodecheckRegister/CodecheckGithubRegisterApiClient.php b/classes/CodecheckRegister/CodecheckGithubRegisterApiClient.php index 7a2fef3e..c31ed342 100644 --- a/classes/CodecheckRegister/CodecheckGithubRegisterApiClient.php +++ b/classes/CodecheckRegister/CodecheckGithubRegisterApiClient.php @@ -204,7 +204,8 @@ public function addIssue( string $paperTitle, string $authorString, array $codecheckers, - array $repositories + array $repositories, + array $updateInformation ): array { $this->client->authenticate($this->githubPAT, null, Client::AUTH_ACCESS_TOKEN); @@ -218,7 +219,8 @@ public function addIssue( $authorString, $this->submissionID, $codecheckers, - $repositories + $repositories, + $updateInformation ); try { @@ -272,7 +274,8 @@ public function updateIssue( $authorString, $this->submissionID, $codecheckers, - $repositories + $repositories, + $updateInformation ); $issueContents = []; diff --git a/classes/CodecheckRegister/CodecheckGithubRegisterIssue.php b/classes/CodecheckRegister/CodecheckGithubRegisterIssue.php index 3e8578d9..5306c0bd 100644 --- a/classes/CodecheckRegister/CodecheckGithubRegisterIssue.php +++ b/classes/CodecheckRegister/CodecheckGithubRegisterIssue.php @@ -4,6 +4,11 @@ use APP\plugins\generic\codecheck\classes\CodecheckRegister\CertificateIdentifier; use APP\plugins\generic\codecheck\classes\CodecheckRegister\CodecheckIssueLabels; +use APP\plugins\generic\codecheck\classes\Workflow\CodecheckStatusHandler; +use APP\plugins\generic\codecheck\classes\Constants; +use PKP\plugins\PluginRegistry; +use APP\core\Application; +use APP\plugins\generic\codecheck\classes\Log\CodecheckLogger; class CodecheckGithubRegisterIssue { private string $repositoryOwner; @@ -13,6 +18,8 @@ class CodecheckGithubRegisterIssue { private string $submissionID; private array $labels; private string $jsonEncodedCodecheckMetadata; + private string $codecheckStatus; + private bool $updateStatus; public function __construct( string $repositoryOwner, @@ -24,11 +31,20 @@ public function __construct( string $authorString, string $submissionID, array $codecheckers, - array $repositories + array $repositories, + array $updateInformation ){ $this->repositoryOwner = $repositoryOwner; $this->repository = $repository; $this->submissionID = $submissionID; + $this->codecheckStatus = ''; + $this->updateStatus = false; + if(in_array(Constants::CODECHECK_GITHUB_REGISTER_ISSUE_UPDATE_STATUS, $updateInformation)) { + $this->updateStatus = true; + $this->codecheckStatus = CodecheckStatusHandler::getCurrentStatusData($this->submissionID)->status; + } + $updateCodecheckStatus = $this->updateStatus ? 'true' : 'false'; + CodecheckLogger::debug("Record / Update Status: " . $updateCodecheckStatus); $authorString = empty($authorString) ? 'New CODECHECK' : $authorString; $this->title = $this->createTitleMarkdown($authorString, $certificateIdentifier); $this->jsonEncodedCodecheckMetadata = $this->createJsonEncodedCodecheckMetadataMarkdown($authorString, $certificateIdentifier, $journalName, $submissionID, $codecheckers, $repositories); @@ -73,10 +89,12 @@ private function createJsonEncodedCodecheckMetadataMarkdown( array $repositories ): string { + $statusInformation = $this->updateStatus ? "\n\t\"status\": \"" . $this->codecheckStatus . "\"," : ""; return "
\n

JSON encoded CODECHECK metadata

\n\n" . "```json\n" . "{" . "\n\t\"identifier\": \"" . $certificateIdentifier->toStr() . "\"," + . $statusInformation . "\n\t\"repositories\": " . json_encode($repositories) . "," . "\n\t\"codecheckers\": " . json_encode($codecheckers) . "," . "\n\t\"links\": []," @@ -96,11 +114,13 @@ private function createBodyMarkdown( foreach ($repositories as $repo) { $repoStr .= "\t- " . $repo . "\n"; } + $statusInformation = $this->updateStatus ? "\n**CODECHECK Status:** " . __($this->codecheckStatus) . "\n\n" : ""; + return "\n## " . $paperTitle . "\n\n" . "\n**Article:**\n\n" . "\n**Journal:** " . $journalName . " *(Submission ID: " . $this->submissionID . ")*\n\n" - . "\n**Repositories:**\n" - . $repoStr; + . "\n**Repositories:**\n" . $repoStr . "\n\n" + . $statusInformation; } private function fillLabels( diff --git a/classes/Constants.php b/classes/Constants.php index aaf6fdbf..ee49748d 100644 --- a/classes/Constants.php +++ b/classes/Constants.php @@ -26,6 +26,7 @@ class Constants /** * The possible Codecheck Statuses */ + public const CODECHECK_STATUS_PENDING = 'plugins.generic.codecheck.status.pending'; public const CODECHECK_STATUS_NEEDS_CODECHECKER = 'plugins.generic.codecheck.status.needsCodechecker'; public const CODECHECK_STATUS_ASSIGNED_CODECHECKER = 'plugins.generic.codecheck.status.assignedCodechecker'; public const CODECHECK_STATUS_STALLED_AUTHOR = 'plugins.generic.codecheck.status.stalled.author'; @@ -65,6 +66,7 @@ class Constants public const CODECHECK_GITHUB_REGISTER_ISSUE_UPDATE_FIELDS = 'codecheckGithubUpdateFields'; public const CODECHECK_GITHUB_REGISTER_ISSUE_UPDATE_TITLE = 'updateTitle'; public const CODECHECK_GITHUB_REGISTER_ISSUE_UPDATE_BODY = 'updateBody'; + public const CODECHECK_GITHUB_REGISTER_ISSUE_UPDATE_STATUS = 'updateStatus'; # Codecheck Publication Validation # Codecheck Status public const CODECHECK_STATUS = 'codecheckStatus'; diff --git a/classes/Settings/SettingsForm.php b/classes/Settings/SettingsForm.php index 3ff1e7d9..5cf548ac 100644 --- a/classes/Settings/SettingsForm.php +++ b/classes/Settings/SettingsForm.php @@ -151,6 +151,7 @@ public function initData(): void // Unpack so each checkbox gets its own template variable $this->setData(Constants::CODECHECK_GITHUB_REGISTER_ISSUE_UPDATE_TITLE, in_array(Constants::CODECHECK_GITHUB_REGISTER_ISSUE_UPDATE_TITLE, $updateFields)); $this->setData(Constants::CODECHECK_GITHUB_REGISTER_ISSUE_UPDATE_BODY, in_array(Constants::CODECHECK_GITHUB_REGISTER_ISSUE_UPDATE_BODY, $updateFields)); + $this->setData(Constants::CODECHECK_GITHUB_REGISTER_ISSUE_UPDATE_STATUS, in_array(Constants::CODECHECK_GITHUB_REGISTER_ISSUE_UPDATE_STATUS, $updateFields)); $this->setData( Constants::CODECHECK_PUBLICATION_VALIDATION_EXTENDED, @@ -181,6 +182,7 @@ public function readInputData(): void Constants::CODECHECK_SHOW_DASHBOARD_COLUMN, Constants::CODECHECK_GITHUB_REGISTER_ISSUE_UPDATE_TITLE, Constants::CODECHECK_GITHUB_REGISTER_ISSUE_UPDATE_BODY, + Constants::CODECHECK_GITHUB_REGISTER_ISSUE_UPDATE_STATUS, Constants::CODECHECK_GITHUB_REGISTER_ISSUE_UPDATE_FIELDS, Constants::CODECHECK_STATUS, Constants::CODECHECK_STATUSES_SELECTED, @@ -308,6 +310,7 @@ public function execute(...$functionArgs): mixed $updateFields = array_values(array_filter([ $this->getData(Constants::CODECHECK_GITHUB_REGISTER_ISSUE_UPDATE_TITLE) ? Constants::CODECHECK_GITHUB_REGISTER_ISSUE_UPDATE_TITLE : null, $this->getData(Constants::CODECHECK_GITHUB_REGISTER_ISSUE_UPDATE_BODY) ? Constants::CODECHECK_GITHUB_REGISTER_ISSUE_UPDATE_BODY : null, + $this->getData(Constants::CODECHECK_GITHUB_REGISTER_ISSUE_UPDATE_STATUS) ? Constants::CODECHECK_GITHUB_REGISTER_ISSUE_UPDATE_STATUS : null, ])); $this->plugin->updateSetting( diff --git a/classes/Workflow/CodecheckStatusHandler.php b/classes/Workflow/CodecheckStatusHandler.php index 74d68bf2..c905c84c 100644 --- a/classes/Workflow/CodecheckStatusHandler.php +++ b/classes/Workflow/CodecheckStatusHandler.php @@ -4,22 +4,27 @@ use Illuminate\Support\Facades\DB; use APP\plugins\generic\codecheck\classes\Constants; +use APP\plugins\generic\codecheck\classes\Log\CodecheckLogger; class CodecheckStatusHandler { - public static function getCurrentStatusData(int $submissionId): object|null { - return DB::table('codecheck_status') + public static function getCurrentStatusData(int $submissionId): object { + $codecheckStatus = DB::table('codecheck_status') ->where('submission_id', $submissionId) ->orderBy('timestamp', 'desc') ->orderBy('status_id', 'desc') ->first(); + + return $codecheckStatus ?? (object) ['status' => 'plugins.generic.codecheck.status.pending']; } public static function getStatusDataHistory(int $submissionId): object|null { - return DB::table('codecheck_status') + $statusHistory = DB::table('codecheck_status') ->where('submission_id', $submissionId) ->orderBy('timestamp', 'desc') ->orderBy('status_id', 'desc') ->get(); + + return $statusHistory->isEmpty() ? null : $statusHistory; } public static function updateStatus(int $submissionId, string $status, int $userId): object|false { @@ -43,11 +48,9 @@ public static function automaticStatusUpdate(array $submissionMetadata): object| $submissionId = $submissionMetadata['submissionId']; $statusHistory = CodecheckStatusHandler::getStatusDataHistory($submissionId); - error_log("Status History: " . json_encode($statusHistory)); - error_log("Status History count: " . $statusHistory->count()); - error_log("Is null: " . ($statusHistory === null ? 'true' : 'false')); + CodecheckLogger::debug("Status History: " . json_encode($statusHistory)); - if($statusHistory == null || $statusHistory->count() < 2) { + if(empty($statusHistory) || $statusHistory->count() < 2) { $status = Constants::CODECHECK_STATUS_NEEDS_CODECHECKER; if(!empty($submissionMetadata['codecheck']['codecheckers'])) { $status = Constants::CODECHECK_STATUS_ASSIGNED_CODECHECKER; diff --git a/cypress/tests/component/CodecheckMetadataForm.cy.js b/cypress/tests/component/CodecheckMetadataForm.cy.js index 9f0095af..0229b67b 100644 --- a/cypress/tests/component/CodecheckMetadataForm.cy.js +++ b/cypress/tests/component/CodecheckMetadataForm.cy.js @@ -26,7 +26,7 @@ describe('CodecheckMetadataForm Component', () => { version: 'latest', publicationType: 'doi', manifest: [], - repository: '', + repository: JSON.stringify({ repositories: null, repoWithCodecheckYaml: null }), source: '', codecheckers: [], certificate: '', diff --git a/locale/en/locale.po b/locale/en/locale.po index e00a8c55..38d3c1b9 100644 --- a/locale/en/locale.po +++ b/locale/en/locale.po @@ -119,6 +119,9 @@ msgstr "Update the Issue Title (containing the article's authors)" msgid "plugins.generic.codecheck.settings.updateIssue.body" msgstr "Update the Issue Description (containing the article, codechecker and repository information)" +msgid "plugins.generic.codecheck.settings.updateIssue.status" +msgstr "Record & update the CODECHECK Status in the GitHub Register Issue" + msgid "plugins.generic.codecheck.settings.status" msgstr "What status must a check have for a submission to proceed with the publication?" diff --git a/resources/js/Components/CodecheckMetadataForm.vue b/resources/js/Components/CodecheckMetadataForm.vue index f9103e03..1fbea814 100644 --- a/resources/js/Components/CodecheckMetadataForm.vue +++ b/resources/js/Components/CodecheckMetadataForm.vue @@ -564,13 +564,13 @@ export default { manifestFiles: data.submission?.manifestFiles || '', dataAvailabilityStatement: data.submission?.dataAvailabilityStatement || '' }; - - let repositoryData = typeof data.codecheck.repository === 'string' ? JSON.parse(data.codecheck.repository) : { - repositories: null, - repoWithCodecheckYaml: null, - }; if (data.codecheck && typeof data.codecheck === 'object') { + let repositoryData = typeof data.codecheck.repository === 'string' ? JSON.parse(data.codecheck.repository) : { + repositories: null, + repoWithCodecheckYaml: null, + }; + this.metadata = { version: data.codecheck.version || data.codecheck.version || 'latest', publicationType: data.codecheck.publicationType || data.codecheck.publication_type || 'doi', diff --git a/resources/js/Components/CodecheckStatusForm.vue b/resources/js/Components/CodecheckStatusForm.vue index c1cb5940..7153c096 100644 --- a/resources/js/Components/CodecheckStatusForm.vue +++ b/resources/js/Components/CodecheckStatusForm.vue @@ -1,9 +1,10 @@