Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions CodecheckPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 16 additions & 17 deletions api/v1/CodecheckApiHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -611,14 +611,16 @@ 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,
$issueLabels,
$articleTitle,
$authorString,
$codecheckers,
$repositories
$repositories,
$updateInformation
);

return $issue;
Expand All @@ -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,
Expand All @@ -652,7 +655,8 @@ private function reserveIdentifierWithNewIssueUrl(
$authorString,
$this->codecheckMetadataHandler->getSubmissionId(),
$codecheckers,
$repositories
$repositories,
$updateInformation
);

return $codecheckIssue->getNewIssueUrl();
Expand Down Expand Up @@ -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,
Expand All @@ -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);
}

Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -218,7 +219,8 @@ public function addIssue(
$authorString,
$this->submissionID,
$codecheckers,
$repositories
$repositories,
$updateInformation
);

try {
Expand Down Expand Up @@ -272,7 +274,8 @@ public function updateIssue(
$authorString,
$this->submissionID,
$codecheckers,
$repositories
$repositories,
$updateInformation
);

$issueContents = [];
Expand Down
26 changes: 23 additions & 3 deletions classes/CodecheckRegister/CodecheckGithubRegisterIssue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -73,10 +89,12 @@ private function createJsonEncodedCodecheckMetadataMarkdown(
array $repositories
): string
{
$statusInformation = $this->updateStatus ? "\n\t\"status\": \"" . $this->codecheckStatus . "\"," : "";
return "<details>\n<summary><h3>JSON encoded CODECHECK metadata</h3></summary>\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\": [],"
Expand All @@ -96,11 +114,13 @@ private function createBodyMarkdown(
foreach ($repositories as $repo) {
$repoStr .= "\t- " . $repo . "\n";
}
$statusInformation = $this->updateStatus ? "<!-- The current status of the CODECHECK -->\n**CODECHECK Status:** " . __($this->codecheckStatus) . "\n\n" : "";

return "<!-- Provide the title of your published paper or preprint -->\n## " . $paperTitle . "\n\n"
. "<!-- Provide a link to your published paper or preprint, ideally with a DOI -->\n**Article:**\n\n"
. "<!-- Information about the Journal in which the paper/ preprint is published -->\n**Journal:** " . $journalName . " *(Submission ID: " . $this->submissionID . ")*\n\n"
. "<!-- Provide a link to your code (and data) repository(s) (GitHub, GitLab, etc.) -->\n**Repositories:**\n"
. $repoStr;
. "<!-- Provide a link to your code (and data) repository(s) (GitHub, GitLab, etc.) -->\n**Repositories:**\n" . $repoStr . "\n\n"
. $statusInformation;
}

private function fillLabels(
Expand Down
2 changes: 2 additions & 0 deletions classes/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down
3 changes: 3 additions & 0 deletions classes/Settings/SettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
17 changes: 10 additions & 7 deletions classes/Workflow/CodecheckStatusHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion cypress/tests/component/CodecheckMetadataForm.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('CodecheckMetadataForm Component', () => {
version: 'latest',
publicationType: 'doi',
manifest: [],
repository: '',
repository: JSON.stringify({ repositories: null, repoWithCodecheckYaml: null }),
source: '',
codecheckers: [],
certificate: '',
Expand Down
3 changes: 3 additions & 0 deletions locale/en/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -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?"

Expand Down
10 changes: 5 additions & 5 deletions resources/js/Components/CodecheckMetadataForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading
Loading