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
#define OWNER "arcan1s"
// project name
#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
#define TAG_TITLE "A new bug"
#define TAG_BODY "Some error occurs"
@ -43,6 +36,17 @@
// comma separated
#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
*
@ -56,6 +60,10 @@
// public link; in the most cases do not touch it
// available tags are $PROJECT, $OWNER
#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 */

View File

@ -25,6 +25,8 @@
#include <QNetworkRequest>
#include <QPushButton>
#include <QUrl>
#include <QWebElement>
#include <QWebFrame>
#include "config.h"
@ -174,39 +176,50 @@ void Reportabug::updateTabs(const int index)
if (debug) qDebug() << "[Reportabug]" << "[updateTabs]" << ":" << "Index" << index;
int number = getNumberByIndex(index);
ui->stackedWidget->setCurrentIndex(number + 1);
if (number == -1)
return;
else if (number == 0)
updateGithubTab();
else if (number == 1)
updateGitreportTab();
}
void Reportabug::updateGithubTab()
{
if (debug) qDebug() << "[Reportabug]" << "[updateGithubTab]";
if (number == -1) {
ui->widget_auth->setHidden(true);
ui->widget_title->setHidden(true);
ui->textEdit->setHidden(true);
ui->webView->setHidden(true);
}
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::updateGitreportTab()
void Reportabug::githubFinished(QNetworkReply *reply)
{
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();
if (debug) qDebug() << "[Reportabug]" << "[githubFinished]";
if (debug) qDebug() << "[Reportabug]" << "[githubFinished]" << ":" << "Error state" << reply->error();
if (debug) qDebug() << "[Reportabug]" << "[githubFinished]" << ":" << "Reply size" << reply->readBufferSize();
int state = true;
QString answer = reply->readAll();
@ -249,6 +262,79 @@ void Reportabug::replyFinished(QNetworkReply *reply)
QGridLayout *layout = (QGridLayout *)messageBox.layout();
layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount());
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) {
case QMessageBox::Ok:
if (state) close();
@ -287,11 +373,37 @@ void Reportabug::sendReportUsingGithub()
request.setRawHeader("Content-Length", textSize);
QNetworkAccessManager *manager = new QNetworkAccessManager;
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()
{
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();
public slots:
// send report
void sendReport();
// update functions
void updateTabs(const int index);
void updateGithubTab();
void updateGitreportTab();
private slots:
void sendReportUsingGithub();
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:
bool debug;

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>547</width>
<height>378</height>
<width>543</width>
<height>374</height>
</rect>
</property>
<property name="windowTitle">
@ -19,11 +19,7 @@
<widget class="QComboBox" name="comboBox"/>
</item>
<item>
<widget class="QStackedWidget" name="stackedWidget">
<widget class="QWidget" name="page_null"/>
<widget class="QWidget" name="page_github">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QWidget" name="widget_auth" native="true">
<layout class="QHBoxLayout" name="layout_auth">
<item>
<widget class="QLabel" name="label_username">
@ -75,8 +71,10 @@
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_title" native="true">
<layout class="QHBoxLayout" name="layout_title">
<item>
<widget class="QLabel" name="label_title">
@ -99,6 +97,7 @@
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QTextEdit" name="textEdit">
@ -110,10 +109,6 @@
</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">
@ -123,9 +118,18 @@
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<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>
<widget class="QDialogButtonBox" name="buttonBox">