From e5b1102abf286a062baaf4ff5fa4dce447e64f71 Mon Sep 17 00:00:00 2001 From: Evgeniy Alekseev Date: Mon, 22 Aug 2016 19:10:37 +0300 Subject: [PATCH] some changes inside bug reportin backend --- .../awesome-widget/plugin/awbugreporter.cpp | 56 ++++++++++++++++++- sources/awesome-widget/plugin/awbugreporter.h | 6 +- sources/test/testawbugreporter.cpp | 17 +++++- sources/test/testawbugreporter.h | 2 + 4 files changed, 74 insertions(+), 7 deletions(-) diff --git a/sources/awesome-widget/plugin/awbugreporter.cpp b/sources/awesome-widget/plugin/awbugreporter.cpp index c8e6c6b..5620e6a 100644 --- a/sources/awesome-widget/plugin/awbugreporter.cpp +++ b/sources/awesome-widget/plugin/awbugreporter.cpp @@ -17,8 +17,12 @@ #include "awbugreporter.h" +#include + +#include #include #include +#include #include #include #include @@ -30,6 +34,9 @@ AWBugReporter::AWBugReporter(QObject *parent) : QObject(parent) { qCDebug(LOG_AW) << __PRETTY_FUNCTION__; + + connect(this, SIGNAL(replyReceived(const int, const QString)), this, + SLOT(showInformation(const int, const QString))); } @@ -39,8 +46,30 @@ AWBugReporter::~AWBugReporter() } +QString AWBugReporter::generateText(const QString description, + const QString reproduce, + const QString expected) +{ + qCDebug(LOG_AW) << "Generate text with description" << description + << "steps" << reproduce << "and expected result" + << expected; + + QString output; + output += QString("**Description**\n\n%1\n").arg(description); + output += QString("**Step to reproduce**\n\n%1\n").arg(reproduce); + output += QString("**Expected result**\n\n%1\n").arg(expected); + output + += QString("**Version**\n\n%1").arg(getBuildData().join(QString("\n"))); + + return output; +} + + void AWBugReporter::sendBugReport(const QString title, const QString body) { + qCDebug(LOG_AW) << "Send bug report with title" << title << "and body" + << body; + QNetworkAccessManager *manager = new QNetworkAccessManager(nullptr); connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(issueReplyRecieved(QNetworkReply *))); @@ -68,20 +97,41 @@ void AWBugReporter::issueReplyRecieved(QNetworkReply *reply) if (reply->error() != QNetworkReply::NoError) { qCWarning(LOG_AW) << "An error occurs" << reply->error() << "with message" << reply->errorString(); - return emit(replyReceived(false, QString())); + return emit(replyReceived(0, QString())); } QJsonParseError error; QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error); if (error.error != QJsonParseError::NoError) { qCWarning(LOG_AW) << "Parse error" << error.errorString(); - return emit(replyReceived(false, QString())); + return emit(replyReceived(0, QString())); } reply->deleteLater(); // convert to map QVariantMap response = jsonDoc.toVariant().toMap(); QString url = response[QString("html_url")].toString(); + int number = response[QString("number")].toInt(); - return emit(replyReceived(true, url)); + return emit(replyReceived(number, url)); +} + + +void AWBugReporter::showInformation(const int number, const QString url) +{ + qCDebug(LOG_AW) << "Created issue with number" << number << "and url" + << url; + + QMessageBox *msgBox = new QMessageBox(nullptr); + msgBox->setAttribute(Qt::WA_DeleteOnClose); + msgBox->setModal(false); + msgBox->setWindowTitle(i18n("Issue created")); + msgBox->setText(i18n("Issue %1 has been created")); + msgBox->setStandardButtons(QMessageBox::Open | QMessageBox::Close); + msgBox->setIcon(QMessageBox::Information); + + connect(msgBox, &QMessageBox::accepted, + [this, url]() { return QDesktopServices::openUrl(url); }); + + return msgBox->open(); } diff --git a/sources/awesome-widget/plugin/awbugreporter.h b/sources/awesome-widget/plugin/awbugreporter.h index 4c460f2..6fb3e75 100644 --- a/sources/awesome-widget/plugin/awbugreporter.h +++ b/sources/awesome-widget/plugin/awbugreporter.h @@ -31,13 +31,17 @@ class AWBugReporter : public QObject public: explicit AWBugReporter(QObject *parent = nullptr); virtual ~AWBugReporter(); + Q_INVOKABLE QString generateText(const QString description, + const QString reproduce, + const QString expected); Q_INVOKABLE void sendBugReport(const QString title, const QString body); signals: - void replyReceived(bool status, QString url); + void replyReceived(const int number, const QString url); private slots: void issueReplyRecieved(QNetworkReply *reply); + void showInformation(const int number, const QString url); private: }; diff --git a/sources/test/testawbugreporter.cpp b/sources/test/testawbugreporter.cpp index e5c7455..a6258f6 100644 --- a/sources/test/testawbugreporter.cpp +++ b/sources/test/testawbugreporter.cpp @@ -36,16 +36,27 @@ void TestAWBugReporter::cleanupTestCase() } +void TestAWBugReporter::test_generateText() +{ + data = AWTestLibrary::randomStringList(3); + QString output = plugin->generateText(data.at(0), data.at(1), data.at(2)); + + for (auto string : data) + QVERIFY(output.contains(string)); +} + + void TestAWBugReporter::test_sendBugReport() { QSignalSpy spy(plugin, SIGNAL(replyReceived(bool, QString))); - plugin->sendBugReport(AWTestLibrary::randomString(), - AWTestLibrary::randomString()); + plugin->sendBugReport( + AWTestLibrary::randomString(), + plugin->generateText(data.at(0), data.at(1), data.at(2))); QVERIFY(spy.wait(5000)); QVariantList arguments = spy.takeFirst(); - QVERIFY(arguments.at(0).toBool()); + QVERIFY(arguments.at(0).toInt() > 0); QVERIFY(!arguments.at(1).toString().isEmpty()); } diff --git a/sources/test/testawbugreporter.h b/sources/test/testawbugreporter.h index 7b85254..4a02f98 100644 --- a/sources/test/testawbugreporter.h +++ b/sources/test/testawbugreporter.h @@ -33,10 +33,12 @@ private slots: void initTestCase(); void cleanupTestCase(); // test + void test_generateText(); void test_sendBugReport(); private: AWBugReporter *plugin = nullptr; + QStringList data; };