add github issue reporing backend (#104)

This commit is contained in:
Evgenii Alekseev 2016-08-20 12:14:22 +03:00
parent a9e3e3f087
commit 18c993c0d5
8 changed files with 242 additions and 7 deletions

View File

@ -0,0 +1,87 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "awbugreporter.h"
#include <QJsonDocument>
#include <QJsonParseError>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include "awdebug.h"
AWBugReporter::AWBugReporter(QObject *parent)
: QObject(parent)
{
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
}
AWBugReporter::~AWBugReporter()
{
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
}
void AWBugReporter::sendBugReport(const QString title, const QString body)
{
QNetworkAccessManager *manager = new QNetworkAccessManager(nullptr);
connect(manager, SIGNAL(finished(QNetworkReply *)), this,
SLOT(issueReplyRecieved(QNetworkReply *)));
QNetworkRequest request(QUrl(BUGTRACKER_API));
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
// generate payload
QVariantMap payload;
payload[QString("title")] = title;
payload[QString("body")] = body;
payload[QString("labels")] = QStringList() << QString("from application");
// convert to QByteArray to send request
QByteArray data
= QJsonDocument::fromVariant(payload).toJson(QJsonDocument::Compact);
qCInfo(LOG_AW) << "Send request with body" << data.data() << "and size"
<< data.size();
manager->post(request, data);
}
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()));
}
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()));
}
reply->deleteLater();
// convert to map
QVariantMap response = jsonDoc.toVariant().toMap();
QString url = response[QString("html_url")].toString();
return emit(replyReceived(true, url));
}

View File

@ -0,0 +1,46 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#ifndef AWBUGREPORTER_H
#define AWBUGREPORTER_H
#include <QObject>
class QNetworkReply;
class AWBugReporter : public QObject
{
Q_OBJECT
public:
explicit AWBugReporter(QObject *parent = nullptr);
virtual ~AWBugReporter();
Q_INVOKABLE void sendBugReport(const QString title, const QString body);
signals:
void replyReceived(bool status, QString url);
private slots:
void issueReplyRecieved(QNetworkReply *reply);
private:
};
#endif /* AWBUGREPORTER_H */

View File

@ -23,7 +23,6 @@
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QPixmap>
#include <QtConcurrent/QtConcurrent>
#include <cmath>

View File

@ -20,6 +20,7 @@
#include <QtQml>
#include "awactions.h"
#include "awbugreporter.h"
#include "awconfighelper.h"
#include "awformatterconfigfactory.h"
#include "awkeys.h"
@ -30,6 +31,7 @@ void AWPlugin::registerTypes(const char *uri)
Q_ASSERT(uri == QLatin1String("org.kde.plasma.private.awesomewidget"));
qmlRegisterType<AWActions>(uri, 1, 0, "AWActions");
qmlRegisterType<AWBugReporter>(uri, 1, 0, "AWBugReporter");
qmlRegisterType<AWConfigHelper>(uri, 1, 0, "AWConfigHelper");
qmlRegisterType<AWFormatterConfigFactory>(uri, 1, 0,
"AWFormatterConfigFactory");

View File

@ -16,7 +16,7 @@ include_directories(
${Kf5_INCLUDE}
)
## library
# library
set(AWTESTLIBRARY_HEADERS awtestlibrary.h)
set(AWTESTLIBRARY_SOURCES awtestlibrary.cpp)
add_library(${SUBPROJECT}-awtest STATIC ${AWTESTLIBRARY_SOURCES} ${AWTESTLIBRARY_HEADERS})
@ -24,18 +24,20 @@ target_link_libraries(${SUBPROJECT}-awtest ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES})
set(LIBRARY_TEST_SET ${SUBPROJECT}-awtest ${PROJECT_LIBRARY} ${PROJECT_MONITORSOURCES}
${Qt_LIBRARIES} ${Kf5_LIBRARIES} ${Qt5Test_LIBRARIES})
## modules
# modules
set(TEST_MODULES
abstractextitem extquotes extscript extupgrade extweather
abstractformatter datetimeformatter floatformatter listformatter noformatter scriptformatter stringformatter
extitemaggregator
batterysource desktopsource gpuloadsource gputempsource hddtempsource networksource playersource processessource
awconfighelper awkeycache awkeys awpatternfunctions awupdatehelper
awbugreporter awconfighelper awkeycache awkeys awpatternfunctions awupdatehelper
dpplugin)
foreach (TEST_MODULE ${TEST_MODULES})
set(${TEST_MODULE}_HEADERS test${TEST_MODULE}.h)
set(${TEST_MODULE}_SOURCES test${TEST_MODULE}.cpp)
if (TEST_MODULE MATCHES "awconfighelper")
if (TEST_MODULE MATCHES "awbugreporter")
set(${TEST_MODULE}_SOURCES ${${TEST_MODULE}_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/../awesome-widget/plugin/awbugreporter.cpp)
elseif (TEST_MODULE MATCHES "awconfighelper")
set(${TEST_MODULE}_SOURCES ${${TEST_MODULE}_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/../awesome-widget/plugin/awconfighelper.cpp)
elseif (TEST_MODULE MATCHES "awkeycache")
set(${TEST_MODULE}_SOURCES ${${TEST_MODULE}_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/../awesome-widget/plugin/awkeycache.cpp)
@ -60,8 +62,10 @@ foreach (TEST_MODULE ${TEST_MODULES})
elseif (TEST_MODULE MATCHES "dpplugin")
set(${TEST_MODULE}_SOURCES ${${TEST_MODULE}_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/../desktop-panel/plugin/dpadds.cpp
${PROJECT_TRDPARTY_DIR}/fontdialog/fontdialog.cpp)
endif (TEST_MODULE MATCHES "awconfighelper")
endif (TEST_MODULE MATCHES "awbugreporter")
add_executable(${SUBPROJECT}-${TEST_MODULE} ${${TEST_MODULE}_HEADERS} ${${TEST_MODULE}_SOURCES})
target_link_libraries(${SUBPROJECT}-${TEST_MODULE} ${LIBRARY_TEST_SET})
add_test(NAME ${TEST_MODULE} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-${TEST_MODULE})
if (NOT TEST_MODULE MATCHES "awbugreporter")
add_test(NAME ${TEST_MODULE} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-${TEST_MODULE})
endif (NOT TEST_MODULE MATCHES "awbugreporter")
endforeach (TEST_MODULE)

View File

@ -0,0 +1,53 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "testawbugreporter.h"
#include <QtTest>
#include "awbugreporter.h"
#include "awtestlibrary.h"
void TestAWBugReporter::initTestCase()
{
plugin = new AWBugReporter(this);
}
void TestAWBugReporter::cleanupTestCase()
{
delete plugin;
}
void TestAWBugReporter::test_sendBugReport()
{
QSignalSpy spy(plugin, SIGNAL(replyReceived(bool, QString)));
plugin->sendBugReport(AWTestLibrary::randomString(),
AWTestLibrary::randomString());
QVERIFY(spy.wait(5000));
QVariantList arguments = spy.takeFirst();
QVERIFY(arguments.at(0).toBool());
QVERIFY(!arguments.at(1).toString().isEmpty());
}
QTEST_MAIN(TestAWBugReporter);

View File

@ -0,0 +1,43 @@
/***************************************************************************
* This file is part of awesome-widgets *
* *
* awesome-widgets is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* awesome-widgets is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#ifndef TESTAWBUGREPORTER_H
#define TESTAWBUGREPORTER_H
#include <QObject>
class AWBugReporter;
class TestAWBugReporter : public QObject
{
Q_OBJECT
private slots:
// initialization
void initTestCase();
void cleanupTestCase();
// test
void test_sendBugReport();
private:
AWBugReporter *plugin = nullptr;
};
#endif /* TESTAWBUGREPORTER_H */

View File

@ -61,6 +61,7 @@
#define VERSION_API \
"https://api.github.com/repos/arcan1s/awesome-widgets/releases"
#define BUGTRACKER "https://github.com/arcan1s/awesome-widgets/issues"
#define BUGTRACKER_API "http://arcanis.me/repos/arcan1s/awesome-widgets/issues"
#define TRANSLATION "https://github.com/arcan1s/awesome-widgets/issues/14"
#define AUR_PACKAGES \
"https://aur.archlinux.org/packages/plasma5-applet-awesome-widgets/"