mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 23:47:20 +00:00
some changes inside bug reportin backend
This commit is contained in:
parent
f3f9239984
commit
e5b1102abf
@ -17,8 +17,12 @@
|
|||||||
|
|
||||||
#include "awbugreporter.h"
|
#include "awbugreporter.h"
|
||||||
|
|
||||||
|
#include <KI18n/KLocalizedString>
|
||||||
|
|
||||||
|
#include <QDesktopServices>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonParseError>
|
#include <QJsonParseError>
|
||||||
|
#include <QMessageBox>
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
@ -30,6 +34,9 @@ AWBugReporter::AWBugReporter(QObject *parent)
|
|||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
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)
|
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);
|
QNetworkAccessManager *manager = new QNetworkAccessManager(nullptr);
|
||||||
connect(manager, SIGNAL(finished(QNetworkReply *)), this,
|
connect(manager, SIGNAL(finished(QNetworkReply *)), this,
|
||||||
SLOT(issueReplyRecieved(QNetworkReply *)));
|
SLOT(issueReplyRecieved(QNetworkReply *)));
|
||||||
@ -68,20 +97,41 @@ void AWBugReporter::issueReplyRecieved(QNetworkReply *reply)
|
|||||||
if (reply->error() != QNetworkReply::NoError) {
|
if (reply->error() != QNetworkReply::NoError) {
|
||||||
qCWarning(LOG_AW) << "An error occurs" << reply->error()
|
qCWarning(LOG_AW) << "An error occurs" << reply->error()
|
||||||
<< "with message" << reply->errorString();
|
<< "with message" << reply->errorString();
|
||||||
return emit(replyReceived(false, QString()));
|
return emit(replyReceived(0, QString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error);
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error);
|
||||||
if (error.error != QJsonParseError::NoError) {
|
if (error.error != QJsonParseError::NoError) {
|
||||||
qCWarning(LOG_AW) << "Parse error" << error.errorString();
|
qCWarning(LOG_AW) << "Parse error" << error.errorString();
|
||||||
return emit(replyReceived(false, QString()));
|
return emit(replyReceived(0, QString()));
|
||||||
}
|
}
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
|
||||||
// convert to map
|
// convert to map
|
||||||
QVariantMap response = jsonDoc.toVariant().toMap();
|
QVariantMap response = jsonDoc.toVariant().toMap();
|
||||||
QString url = response[QString("html_url")].toString();
|
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();
|
||||||
}
|
}
|
||||||
|
@ -31,13 +31,17 @@ class AWBugReporter : public QObject
|
|||||||
public:
|
public:
|
||||||
explicit AWBugReporter(QObject *parent = nullptr);
|
explicit AWBugReporter(QObject *parent = nullptr);
|
||||||
virtual ~AWBugReporter();
|
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);
|
Q_INVOKABLE void sendBugReport(const QString title, const QString body);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void replyReceived(bool status, QString url);
|
void replyReceived(const int number, const QString url);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void issueReplyRecieved(QNetworkReply *reply);
|
void issueReplyRecieved(QNetworkReply *reply);
|
||||||
|
void showInformation(const int number, const QString url);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
@ -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()
|
void TestAWBugReporter::test_sendBugReport()
|
||||||
{
|
{
|
||||||
QSignalSpy spy(plugin, SIGNAL(replyReceived(bool, QString)));
|
QSignalSpy spy(plugin, SIGNAL(replyReceived(bool, QString)));
|
||||||
plugin->sendBugReport(AWTestLibrary::randomString(),
|
plugin->sendBugReport(
|
||||||
AWTestLibrary::randomString());
|
AWTestLibrary::randomString(),
|
||||||
|
plugin->generateText(data.at(0), data.at(1), data.at(2)));
|
||||||
|
|
||||||
QVERIFY(spy.wait(5000));
|
QVERIFY(spy.wait(5000));
|
||||||
QVariantList arguments = spy.takeFirst();
|
QVariantList arguments = spy.takeFirst();
|
||||||
|
|
||||||
QVERIFY(arguments.at(0).toBool());
|
QVERIFY(arguments.at(0).toInt() > 0);
|
||||||
QVERIFY(!arguments.at(1).toString().isEmpty());
|
QVERIFY(!arguments.at(1).toString().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,10 +33,12 @@ private slots:
|
|||||||
void initTestCase();
|
void initTestCase();
|
||||||
void cleanupTestCase();
|
void cleanupTestCase();
|
||||||
// test
|
// test
|
||||||
|
void test_generateText();
|
||||||
void test_sendBugReport();
|
void test_sendBugReport();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AWBugReporter *plugin = nullptr;
|
AWBugReporter *plugin = nullptr;
|
||||||
|
QStringList data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user