diff --git a/composer.json b/composer.json index 924d41c..ff3480e 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,8 @@ "smalot/pdfparser": "*", "zozlak/argparse": "^1", "whikloj/bagittools": "^4.2.3", - "acdh-oeaw/arche-assets": "^3.9.4" + "acdh-oeaw/arche-assets": "^3.9.4", + "acdh-oeaw/arche-lib-ingest": "^3.5" }, "autoload": { "psr-4": { diff --git a/index.php b/index.php index c5817aa..88b152f 100755 --- a/index.php +++ b/index.php @@ -27,6 +27,7 @@ use acdhOeaw\arche\fileChecker\FileChecker; use zozlak\argparse\ArgumentParser; +use acdhOeaw\arche\lib\ingest\Redmine; $composerDir = realpath(__DIR__); while ($composerDir !== false && !file_exists("$composerDir/vendor")) { @@ -42,6 +43,14 @@ $parser->addArgument('--html', action: ArgumentParser::ACTION_STORE_TRUE, help: "If present, HTML reports are generated on top of the standard JSON lines output."); $parser->addArgument('--overwrite', action: ArgumentParser::ACTION_STORE_TRUE, help: "If present, the report is generated directly in the reportDir without creation of a timestamp-based directory."); $parser->addArgument('--match', help: "If provided, only files and directories matching a given regular expression are being checked. If the directory check is skipped, the directory content is still being checked."); +$parser->addArgument('--redmineIssueId', help: "If provided (along with --redmineUser and --redminePswd), the corresponding redmine id will be updated with the check results. Both repo-filechecker issue id or its parent issue id can be provided."); +$parser->addArgument('--redmineUser'); +$parser->addArgument('--redminePswd'); +$parser->addArgument('--redmineToken'); +$parser->addArgument('--redmineApiUrl', default: "https://redmine.acdh.oeaw.ac.at"); +$parser->addArgument('--redmineDone', type: ArgumentParser::TYPE_INT, default: 10, help: "Percent done value set on the redmine issue in case of unsuccessful check."); +$parser->addArgument('--redmineMessage', default: '', help: "Message posted as a note in the redmine issue. If not provided, a default value is used."); +$parser->addArgument('--redmineAppend', type: ArgumentParser::ACTION_STORE_TRUE, help: "Should --redmineMessage be appended to the default message?"); $parser->addArgument('--skipWarnings', action: ArgumentParser::ACTION_STORE_TRUE, help: "If present, only errors cause a non-zero script return value."); $parser->addArgument('directoryToCheck'); $parser->addArgument('reportDir'); @@ -50,4 +59,21 @@ $ch = new FileChecker((array) $args); $ret = $ch->check($args->directoryToCheck); $ch->generateReports($args->csv, $args->html); + +if (!empty($args->redmineId)) { + try { + $redmine = new Redmine($args->redmineApiUrl, (string) ($args->redmineToken ?? $args->redmineUser), (string) $args->redminePswd); + $redmineId = $redmine->updateIssue( + $args->mainIssueId, 'Run repo-file-checker', $ret, + issueStatus: $ret ? 'Resolved' : 'In Progress', + done: $ret ? $args->redmineDone : 100, + message: $args->redmineMessage, + append: $args->redmineAppend + ); + echo "Redmine issue $redmineId updated successfully\n"; + } catch (Throwable $e) { + echo $e->getMessage() . "\n"; + } +} + exit($ret ? 0 : 2);