| 1 | /* |
| 2 | This file is part of the Purpose library. |
| 3 | SPDX-FileCopyrightText: 2017 René J.V. Bertin <rjvbertin@gmail.com> |
| 4 | |
| 5 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 6 | */ |
| 7 | |
| 8 | #include <QCommandLineParser> |
| 9 | #include <QCoreApplication> |
| 10 | #include <QDebug> |
| 11 | #include <QString> |
| 12 | |
| 13 | #include "../phabricatorjobs.h" |
| 14 | |
| 15 | int main(int argc, char *argv[]) |
| 16 | { |
| 17 | QCoreApplication app(argc, argv); |
| 18 | |
| 19 | QString projectName; |
| 20 | QString diffID; |
| 21 | QString patchFile; |
| 22 | QString ; |
| 23 | |
| 24 | app.setApplicationName(QStringLiteral("testphabricator" )); |
| 25 | QCommandLineParser parser; |
| 26 | const QCommandLineOption projectNameOption(QStringLiteral("project" ), |
| 27 | QStringLiteral("a directory holding the project" ), |
| 28 | QStringLiteral("project" ), |
| 29 | projectName); |
| 30 | const QCommandLineOption diffIDOption(QStringLiteral("ID" ), |
| 31 | QStringLiteral("set the revision ID to update (when missing, create a new diff)" ), |
| 32 | QStringLiteral("ID" ), |
| 33 | diffID); |
| 34 | const QCommandLineOption patchFileOption(QStringLiteral("patch" ), QStringLiteral("the patch to upload" ), QStringLiteral("patch" ), patchFile); |
| 35 | const QCommandLineOption (QStringLiteral("message" ), |
| 36 | QStringLiteral("comment describing the patch update" ), |
| 37 | QStringLiteral("message" ), |
| 38 | updateComment); |
| 39 | const QCommandLineOption listOption(QStringLiteral("list" ), QStringLiteral("list your open differential revisions" )); |
| 40 | parser.addOption(commandLineOption: projectNameOption); |
| 41 | parser.addOption(commandLineOption: diffIDOption); |
| 42 | parser.addOption(commandLineOption: patchFileOption); |
| 43 | parser.addOption(commandLineOption: updateCommentOption); |
| 44 | parser.addOption(commandLineOption: listOption); |
| 45 | parser.addHelpOption(); |
| 46 | parser.addVersionOption(); |
| 47 | |
| 48 | parser.process(app); |
| 49 | if (parser.isSet(option: projectNameOption)) { |
| 50 | projectName = parser.value(option: projectNameOption); |
| 51 | } |
| 52 | if (parser.isSet(option: listOption)) { |
| 53 | Phabricator::DiffRevList diffList(projectName); |
| 54 | if (diffList.error()) { |
| 55 | qCritical() << "Error creating diffList:" << diffList.errorString() << ";" << diffList.error(); |
| 56 | } else { |
| 57 | diffList.exec(); |
| 58 | if (diffList.error()) { |
| 59 | qCritical() << "Error getting diffList:" << diffList.errorString() << ";" << diffList.error(); |
| 60 | } else { |
| 61 | qWarning() << "Open differential revisions:" << diffList.reviewMap(); |
| 62 | const auto reviews = diffList.reviews(); |
| 63 | for (const auto &rev : reviews) { |
| 64 | qWarning() << rev; |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | } else { |
| 69 | if (parser.isSet(option: diffIDOption)) { |
| 70 | diffID = parser.value(option: diffIDOption); |
| 71 | } |
| 72 | if (parser.isSet(option: patchFileOption)) { |
| 73 | patchFile = parser.value(option: patchFileOption); |
| 74 | if (diffID.isEmpty()) { |
| 75 | Phabricator::NewDiffRev newDiffRev(QUrl::fromLocalFile(localfile: patchFile), projectName); |
| 76 | newDiffRev.exec(); |
| 77 | if (newDiffRev.error()) { |
| 78 | qCritical() << "Error creating new diff diff:" << newDiffRev.errorString() << ";" << newDiffRev.error(); |
| 79 | } else { |
| 80 | qWarning() << "New differential diff to be completed online:" << newDiffRev.diffURI(); |
| 81 | } |
| 82 | } else { |
| 83 | if (parser.isSet(option: updateCommentOption)) { |
| 84 | updateComment = parser.value(option: updateCommentOption); |
| 85 | } |
| 86 | Phabricator::UpdateDiffRev submitDiffRev(QUrl::fromLocalFile(localfile: patchFile), projectName, diffID, updateComment); |
| 87 | submitDiffRev.exec(); |
| 88 | if (submitDiffRev.error()) { |
| 89 | qCritical() << "Error creating new diff diff:" << submitDiffRev.errorString() << ";" << submitDiffRev.error(); |
| 90 | } else { |
| 91 | qWarning() << "Updated differential revision; please edit comment online:" << submitDiffRev.diffURI(); |
| 92 | } |
| 93 | } |
| 94 | } else { |
| 95 | qCritical() << "need a patchfile" ; |
| 96 | } |
| 97 | } |
| 98 | exit(status: 0); |
| 99 | } |
| 100 | |