add test support of gitreport

This commit is contained in:
arcan1s 2014-07-28 11:21:25 +04:00
parent 7bdf7c6584
commit 99d3ecdedb
4 changed files with 275 additions and 153 deletions

View File

@ -20,19 +20,12 @@
/* /*
* configuration of creating an issue using GitHub API * main configuration
*/ */
// enable this function
#define ENABLE_GITHUB true
// combobox text
#define GITHUB_COMBOBOX "I want to report a bug using my GitHub account"
// the owner of the source repository // the owner of the source repository
#define OWNER "arcan1s" #define OWNER "arcan1s"
// project name // project name
#define PROJECT "reportabug" #define PROJECT "reportabug"
// issues url; in the most cases do not touch it
// available tags are $PROJECT, $OWNER
#define ISSUES_URL "https://api.github.com/repos/$OWNER/$PROJECT/issues"
// tags defaults // tags defaults
#define TAG_TITLE "A new bug" #define TAG_TITLE "A new bug"
#define TAG_BODY "Some error occurs" #define TAG_BODY "Some error occurs"
@ -43,6 +36,17 @@
// comma separated // comma separated
#define TAG_LABELS "auto,bug" #define TAG_LABELS "auto,bug"
/*
* configuration of creating an issue using GitHub API
*/
// enable this function
#define ENABLE_GITHUB true
// combobox text
#define GITHUB_COMBOBOX "I want to report a bug using my GitHub account"
// issues url; in the most cases do not touch it
// available tags are $PROJECT, $OWNER
#define ISSUES_URL "https://api.github.com/repos/$OWNER/$PROJECT/issues"
/* /*
* configuration of creating an issue using GitReports * configuration of creating an issue using GitReports
* *
@ -56,6 +60,10 @@
// public link; in the most cases do not touch it // public link; in the most cases do not touch it
// available tags are $PROJECT, $OWNER // available tags are $PROJECT, $OWNER
#define PUBLIC_URL "https://gitreports.com/issue/$OWNER/$PROJECT" #define PUBLIC_URL "https://gitreports.com/issue/$OWNER/$PROJECT"
// captcha
#define CAPTCHA_KEY "7f6ef90bce7389088a52c5c9101aad206b21b56d"
#define CAPTCHA_TEXT "QJNZXY"
#define CAPTCHA_TIME "1406531273"
#endif /* CONFIG_H */ #endif /* CONFIG_H */

View File

@ -25,6 +25,8 @@
#include <QNetworkRequest> #include <QNetworkRequest>
#include <QPushButton> #include <QPushButton>
#include <QUrl> #include <QUrl>
#include <QWebElement>
#include <QWebFrame>
#include "config.h" #include "config.h"
@ -174,39 +176,50 @@ void Reportabug::updateTabs(const int index)
if (debug) qDebug() << "[Reportabug]" << "[updateTabs]" << ":" << "Index" << index; if (debug) qDebug() << "[Reportabug]" << "[updateTabs]" << ":" << "Index" << index;
int number = getNumberByIndex(index); int number = getNumberByIndex(index);
ui->stackedWidget->setCurrentIndex(number + 1);
if (number == -1) if (number == -1) {
return; ui->widget_auth->setHidden(true);
else if (number == 0) ui->widget_title->setHidden(true);
updateGithubTab(); ui->textEdit->setHidden(true);
else if (number == 1) ui->webView->setHidden(true);
updateGitreportTab(); }
else if (number == 0) {
ui->widget_auth->setHidden(false);
ui->widget_title->setHidden(false);
ui->textEdit->setHidden(false);
ui->webView->setHidden(true);
ui->label_password->setText(QApplication::translate("Reportabug", "Password"));
ui->label_password->setToolTip(QApplication::translate("Reportabug", "GitHub account password"));
ui->lineEdit_password->setPlaceholderText(QApplication::translate("Reportabug", "password"));
ui->lineEdit_password->setEchoMode(QLineEdit::Password);
ui->lineEdit_username->clear();
ui->lineEdit_password->clear();
ui->lineEdit_title->setText(QString(TAG_TITLE));
ui->textEdit->setPlainText(QString(TAG_BODY));
}
else if (number == 1) {
ui->widget_auth->setHidden(true);
ui->widget_title->setHidden(true);
ui->textEdit->setHidden(true);
ui->webView->setHidden(true);
ui->lineEdit_username->clear();
ui->lineEdit_password->clear();
ui->textEdit->setPlainText(QString(TAG_BODY));
ui->webView->load(QUrl(parseString(QString(PUBLIC_URL))));
disconnect(ui->webView, SIGNAL(loadFinished(bool)), this, SLOT(gitreportLoaded(bool)));
disconnect(ui->webView, SIGNAL(loadFinished(bool)), this, SLOT(gitreportFinished(bool)));
connect(ui->webView, SIGNAL(loadFinished(bool)), this, SLOT(gitreportLoaded(bool)));
}
} }
void Reportabug::updateGithubTab() void Reportabug::githubFinished(QNetworkReply *reply)
{ {
if (debug) qDebug() << "[Reportabug]" << "[updateGithubTab]"; if (debug) qDebug() << "[Reportabug]" << "[githubFinished]";
if (debug) qDebug() << "[Reportabug]" << "[githubFinished]" << ":" << "Error state" << reply->error();
ui->lineEdit_username->clear(); if (debug) qDebug() << "[Reportabug]" << "[githubFinished]" << ":" << "Reply size" << reply->readBufferSize();
ui->lineEdit_password->clear();
ui->lineEdit_title->setText(QString(TAG_TITLE));
ui->textEdit->setPlainText(QString(TAG_BODY));
}
void Reportabug::updateGitreportTab()
{
if (debug) qDebug() << "[Reportabug]" << "[updateGitreportTab]";
}
void Reportabug::replyFinished(QNetworkReply *reply)
{
if (debug) qDebug() << "[Reportabug]" << "[replyFinished]";
if (debug) qDebug() << "[Reportabug]" << "[replyFinished]" << ":" << "Error state" << reply->error();
if (debug) qDebug() << "[Reportabug]" << "[replyFinished]" << ":" << "Reply size" << reply->readBufferSize();
int state = true; int state = true;
QString answer = reply->readAll(); QString answer = reply->readAll();
@ -249,6 +262,79 @@ void Reportabug::replyFinished(QNetworkReply *reply)
QGridLayout *layout = (QGridLayout *)messageBox.layout(); QGridLayout *layout = (QGridLayout *)messageBox.layout();
layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount()); layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount());
int ret = messageBox.exec(); int ret = messageBox.exec();
switch (ret) {
case QMessageBox::Ok:
if (state) close();
break;
case QMessageBox::Retry:
if (state) updateTabs(ui->comboBox->currentIndex());
break;
default:
break;
}
}
void Reportabug::gitreportLoaded(const bool state)
{
if (debug) qDebug() << "[Reportabug]" << "[gitreportLoaded]";
if (debug) qDebug() << "[Reportabug]" << "[gitreportLoaded]" << ":" << "State" << state;
if (state) {
ui->widget_auth->setHidden(false);
ui->widget_title->setHidden(true);
ui->textEdit->setHidden(false);
ui->webView->setHidden(false);
ui->label_password->setText(QApplication::translate("Reportabug", "Email"));
ui->label_password->setToolTip(QApplication::translate("Reportabug", "Your email"));
ui->lineEdit_password->setPlaceholderText(QApplication::translate("Reportabug", "email"));
ui->lineEdit_password->setEchoMode(QLineEdit::Normal);
}
else {
QMessageBox messageBox;
messageBox.setText(QApplication::translate("Reportabug", "Error!"));
messageBox.setInformativeText(QApplication::translate("Reportabug", "An error occurs"));
messageBox.setIcon(QMessageBox::Critical);
messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Retry);
messageBox.setDefaultButton(QMessageBox::Ok);
QSpacerItem *horizontalSpacer = new QSpacerItem(400, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
QGridLayout *layout = (QGridLayout *)messageBox.layout();
layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount());
messageBox.exec();
}
}
void Reportabug::gitreportFinished(const bool state)
{
if (debug) qDebug() << "[Reportabug]" << "[gitreportFinished]";
if (debug) qDebug() << "[Reportabug]" << "[gitreportFinished]" << ":" << "State" << state;
QString messageBody, messageTitle;
QMessageBox::Icon icon = QMessageBox::NoIcon;
if (state) {
messageBody += QApplication::translate("Reportabug", "Message has been sended");
messageTitle = QApplication::translate("Reportabug", "Done!");
icon = QMessageBox::Information;
}
else {
messageBody += QApplication::translate("Reportabug", "An error occurs");
messageTitle = QApplication::translate("Reportabug", "Error!");
icon = QMessageBox::Critical;
}
QMessageBox messageBox;
messageBox.setText(messageTitle);
messageBox.setInformativeText(messageBody);
messageBox.setIcon(icon);
messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Retry);
messageBox.setDefaultButton(QMessageBox::Ok);
QSpacerItem *horizontalSpacer = new QSpacerItem(400, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
QGridLayout *layout = (QGridLayout *)messageBox.layout();
layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount());
int ret = messageBox.exec();
switch (ret) { switch (ret) {
case QMessageBox::Ok: case QMessageBox::Ok:
if (state) close(); if (state) close();
@ -287,11 +373,37 @@ void Reportabug::sendReportUsingGithub()
request.setRawHeader("Content-Length", textSize); request.setRawHeader("Content-Length", textSize);
QNetworkAccessManager *manager = new QNetworkAccessManager; QNetworkAccessManager *manager = new QNetworkAccessManager;
manager->post(request, text); manager->post(request, text);
connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(replyFinished(QNetworkReply *))); disconnect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(githubFinished(QNetworkReply *)));
connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(githubFinished(QNetworkReply *)));
} }
void Reportabug::sendReportUsingGitreport() void Reportabug::sendReportUsingGitreport()
{ {
if (debug) qDebug() << "[Reportabug]" << "[sendReportUsingGitreport]"; if (debug) qDebug() << "[Reportabug]" << "[sendReportUsingGitreport]";
QWebElement document = ui->webView->page()->mainFrame()->documentElement();
QWebElement captcha = document.findFirst(QString("input#captcha"));
QWebElement captchaImg = document.findFirst(QString("img#[alt=captcha]"));
QWebElement captchaKey = document.findFirst(QString("input#captcha_key"));
QWebElement emailInput = document.findFirst(QString("input#email"));
QWebElement textArea = document.findFirst(QString("textarea#details"));
QWebElement usernameInput = document.findFirst(QString("input#name"));
// input
usernameInput.setAttribute(QString("value"), ui->lineEdit_username->text());
emailInput.setAttribute(QString("value"), ui->lineEdit_password->text());
textArea.setPlainText(ui->textEdit->toPlainText());
// captcha
captchaImg.setAttribute(QString("src"), QString("/simple_captcha?code=%1&amp;time=%2")
.arg(QString(CAPTCHA_KEY))
.arg(QString(CAPTCHA_TIME)));
captchaKey.setAttribute(QString("value"), QString(CAPTCHA_KEY));
captcha.setAttribute(QString("value"), QString(CAPTCHA_TEXT));
// send request
document.findFirst(QString("input[name=commit]")).evaluateJavaScript("this.click()");
disconnect(ui->webView, SIGNAL(loadFinished(bool)), this, SLOT(gitreportLoaded(bool)));
disconnect(ui->webView, SIGNAL(loadFinished(bool)), this, SLOT(gitreportFinished(bool)));
connect(ui->webView, SIGNAL(loadFinished(bool)), this, SLOT(gitreportFinished(bool)));
} }

View File

@ -38,17 +38,15 @@ public:
~Reportabug(); ~Reportabug();
public slots: public slots:
// send report
void sendReport(); void sendReport();
// update functions
void updateTabs(const int index);
void updateGithubTab();
void updateGitreportTab();
private slots:
void sendReportUsingGithub(); void sendReportUsingGithub();
void sendReportUsingGitreport(); void sendReportUsingGitreport();
void replyFinished(QNetworkReply *reply); void updateTabs(const int index);
private slots:
void githubFinished(QNetworkReply *reply);
void gitreportFinished(const bool state);
void gitreportLoaded(const bool state);
private: private:
bool debug; bool debug;

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>547</width> <width>543</width>
<height>378</height> <height>374</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -19,114 +19,118 @@
<widget class="QComboBox" name="comboBox"/> <widget class="QComboBox" name="comboBox"/>
</item> </item>
<item> <item>
<widget class="QStackedWidget" name="stackedWidget"> <widget class="QWidget" name="widget_auth" native="true">
<widget class="QWidget" name="page_null"/> <layout class="QHBoxLayout" name="layout_auth">
<widget class="QWidget" name="page_github"> <item>
<layout class="QVBoxLayout" name="verticalLayout_2"> <widget class="QLabel" name="label_username">
<item> <property name="minimumSize">
<layout class="QHBoxLayout" name="layout_auth"> <size>
<item> <width>100</width>
<widget class="QLabel" name="label_username"> <height>0</height>
<property name="minimumSize"> </size>
<size> </property>
<width>100</width> <property name="text">
<height>0</height> <string>Username</string>
</size> </property>
</property> </widget>
<property name="text"> </item>
<string>Username</string> <item>
</property> <widget class="QLineEdit" name="lineEdit_username">
</widget> <property name="toolTip">
</item> <string>Your GitHub account</string>
<item> </property>
<widget class="QLineEdit" name="lineEdit_username"> <property name="placeholderText">
<property name="toolTip"> <string>username</string>
<string>Your GitHub account</string> </property>
</property> </widget>
<property name="placeholderText"> </item>
<string>username</string> <item>
</property> <widget class="QLabel" name="label_password">
</widget> <property name="minimumSize">
</item> <size>
<item> <width>100</width>
<widget class="QLabel" name="label_password"> <height>0</height>
<property name="minimumSize"> </size>
<size> </property>
<width>100</width> <property name="text">
<height>0</height> <string>Password</string>
</size> </property>
</property> </widget>
<property name="text"> </item>
<string>Password</string> <item>
</property> <widget class="QLineEdit" name="lineEdit_password">
</widget> <property name="toolTip">
</item> <string>GitHub account password</string>
<item> </property>
<widget class="QLineEdit" name="lineEdit_password"> <property name="echoMode">
<property name="toolTip"> <enum>QLineEdit::Password</enum>
<string>GitHub account password</string> </property>
</property> <property name="placeholderText">
<property name="echoMode"> <string>password</string>
<enum>QLineEdit::Password</enum> </property>
</property> </widget>
<property name="placeholderText"> </item>
<string>password</string> </layout>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_title">
<item>
<widget class="QLabel" name="label_title">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Title</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_title">
<property name="toolTip">
<string>Title of the report</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTextEdit" name="textEdit">
<property name="toolTip">
<string>Text of the report</string>
</property>
<property name="acceptRichText">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_gitreport">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QWebView" name="webView">
<property name="url">
<url>
<string>about:blank</string>
</url>
</property>
</widget>
</item>
</layout>
</widget>
</widget> </widget>
</item> </item>
<item>
<widget class="QWidget" name="widget_title" native="true">
<layout class="QHBoxLayout" name="layout_title">
<item>
<widget class="QLabel" name="label_title">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Title</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_title">
<property name="toolTip">
<string>Title of the report</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QTextEdit" name="textEdit">
<property name="toolTip">
<string>Text of the report</string>
</property>
<property name="acceptRichText">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QWebView" name="webView">
<property name="url">
<url>
<string>about:blank</string>
</url>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item> <item>
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons"> <property name="standardButtons">