Skip to content

Commit

Permalink
CLI extended with the redmine issue update-related parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
zozlak committed Feb 15, 2023
1 parent 23cd8ca commit 2d33761
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
26 changes: 26 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand All @@ -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');
Expand All @@ -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);

0 comments on commit 2d33761

Please sign in to comment.