mirror of
https://github.com/arcan1s/reportabug.git
synced 2025-07-13 21:35:47 +00:00
add support of github
This commit is contained in:
@ -25,7 +25,7 @@ if (USE_QT5)
|
|||||||
add_executable (${SUBPROJECT} ${UI_HEADERS} ${HEADERS} ${SOURCES} ${MOC_SOURCES})
|
add_executable (${SUBPROJECT} ${UI_HEADERS} ${HEADERS} ${SOURCES} ${MOC_SOURCES})
|
||||||
target_link_libraries (${SUBPROJECT} ${Qt5Widgets_LIBRARIES} ${Qt5Core_LIBRARIES})
|
target_link_libraries (${SUBPROJECT} ${Qt5Widgets_LIBRARIES} ${Qt5Core_LIBRARIES})
|
||||||
else ()
|
else ()
|
||||||
find_package (Qt4 REQUIRED)
|
find_package(Qt4 COMPONENTS QtCore QtGui QtNetwork REQUIRED)
|
||||||
include (${QT_USE_FILE})
|
include (${QT_USE_FILE})
|
||||||
qt4_wrap_cpp (MOC_SOURCES ${HEADERS})
|
qt4_wrap_cpp (MOC_SOURCES ${HEADERS})
|
||||||
qt4_wrap_ui (UI_HEADERS ${FORMS})
|
qt4_wrap_ui (UI_HEADERS ${FORMS})
|
||||||
|
@ -41,12 +41,12 @@
|
|||||||
#define TAG_ASSIGNEE "$OWNER"
|
#define TAG_ASSIGNEE "$OWNER"
|
||||||
#define TAG_MILESTONE ""
|
#define TAG_MILESTONE ""
|
||||||
// comma separated
|
// comma separated
|
||||||
#define TAG_LABELS "auto"
|
#define TAG_LABELS "auto,bug"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* configuration of creating an issue using GitReports
|
* configuration of creating an issue using GitReports
|
||||||
*
|
*
|
||||||
* please, visit the following site: https://gitreports.com/
|
* please, visit https://gitreports.com/
|
||||||
* and set up it for your repository
|
* and set up it for your repository
|
||||||
*/
|
*/
|
||||||
// enable this function
|
// enable this function
|
||||||
|
@ -19,7 +19,12 @@
|
|||||||
#include "ui_reportabug.h"
|
#include "ui_reportabug.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QNetworkRequest>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
@ -46,7 +51,6 @@ void Reportabug::createActions()
|
|||||||
connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateTabs(int)));
|
connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateTabs(int)));
|
||||||
connect(ui->buttonBox->button(QDialogButtonBox::Close), SIGNAL(clicked(bool)), this, SLOT(close()));
|
connect(ui->buttonBox->button(QDialogButtonBox::Close), SIGNAL(clicked(bool)), this, SLOT(close()));
|
||||||
connect(ui->buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked(bool)), this, SLOT(sendReport()));
|
connect(ui->buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked(bool)), this, SLOT(sendReport()));
|
||||||
connect(ui->buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked(bool)), this, SLOT(close()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -88,17 +92,72 @@ void Reportabug::keyPressEvent(QKeyEvent *pressedKey)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString Reportabug::parseCmd(QString line,
|
||||||
|
const QString password,
|
||||||
|
const QString text,
|
||||||
|
const QString username)
|
||||||
|
{
|
||||||
|
if (line.contains(QString("$ISSUES_URL")))
|
||||||
|
line = line.split(QString("$ISSUES_URL"))[0] +
|
||||||
|
parseString(QString(ISSUES_URL)) +
|
||||||
|
line.split(QString("$ISSUES_URL"))[1];
|
||||||
|
if (line.contains(QString("$PASSWORD")))
|
||||||
|
line = line.split(QString("$PASSWORD"))[0] +
|
||||||
|
password +
|
||||||
|
line.split(QString("$PASSWORD"))[1];
|
||||||
|
if (line.contains(QString("$TEXT")))
|
||||||
|
line = line.split(QString("$TEXT"))[0] +
|
||||||
|
text +
|
||||||
|
line.split(QString("$TEXT"))[1];
|
||||||
|
if (line.contains(QString("$USERNAME")))
|
||||||
|
line = line.split(QString("$USERNAME"))[0] +
|
||||||
|
username +
|
||||||
|
line.split(QString("$USERNAME"))[1];
|
||||||
|
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QString Reportabug::parseString(QString line)
|
QString Reportabug::parseString(QString line)
|
||||||
{
|
{
|
||||||
if (line.contains(QString("$OWNER")))
|
if (line.contains(QString("$OWNER")))
|
||||||
line = line.split(QString("$OWNER"))[0] + QString(OWNER) + line.split(QString("$OWNER"))[1];
|
line = line.split(QString("$OWNER"))[0] +
|
||||||
|
QString(OWNER) +
|
||||||
|
line.split(QString("$OWNER"))[1];
|
||||||
if (line.contains(QString("$PROJECT")))
|
if (line.contains(QString("$PROJECT")))
|
||||||
line = line.split(QString("$PROJECT"))[0] + QString(PROJECT) + line.split(QString("$PROJECT"))[1];
|
line = line.split(QString("$PROJECT"))[0] +
|
||||||
|
QString(PROJECT) +
|
||||||
|
line.split(QString("$PROJECT"))[1];
|
||||||
|
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QByteArray Reportabug::prepareRequest(const QString title, const QString body)
|
||||||
|
{
|
||||||
|
QStringList requestList;
|
||||||
|
requestList.append(QString("\"title\":\"") + title + QString("\""));
|
||||||
|
requestList.append(QString("\"body\":\"") + body + QString("\""));
|
||||||
|
if (!QString(TAG_ASSIGNEE).isEmpty())
|
||||||
|
requestList.append(QString("\"assignee\":\"") + parseString(QString(TAG_ASSIGNEE)) + QString("\""));
|
||||||
|
if (!QString(TAG_MILESTONE).isEmpty())
|
||||||
|
requestList.append(QString("\"milestone\":") + QString(TAG_MILESTONE));
|
||||||
|
if (!QString(TAG_LABELS).isEmpty()) {
|
||||||
|
QStringList labels = QString(TAG_LABELS).split(QChar(','));
|
||||||
|
for (int i=0; i<labels.count(); i++)
|
||||||
|
labels[i] = QString("\"") + labels[i] + QString("\"");
|
||||||
|
requestList.append(QString("\"labels\":[") + labels.join(QChar(',')) + QString("]"));
|
||||||
|
}
|
||||||
|
|
||||||
|
QString request;
|
||||||
|
request += QString("{");
|
||||||
|
request += requestList.join(QChar(','));
|
||||||
|
request += QString("}");
|
||||||
|
|
||||||
|
return request.toLatin1();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Reportabug::sendReport()
|
void Reportabug::sendReport()
|
||||||
{
|
{
|
||||||
int number = getNumberByIndex(ui->comboBox->currentIndex());
|
int number = getNumberByIndex(ui->comboBox->currentIndex());
|
||||||
@ -118,15 +177,18 @@ void Reportabug::updateTabs(const int index)
|
|||||||
if (number == -1)
|
if (number == -1)
|
||||||
return;
|
return;
|
||||||
else if (number == 0)
|
else if (number == 0)
|
||||||
sendReportUsingGithub();
|
updateGithubTab();
|
||||||
else if (number == 1)
|
else if (number == 1)
|
||||||
sendReportUsingGitreport();
|
updateGitreportTab();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Reportabug::updateGithubTab()
|
void Reportabug::updateGithubTab()
|
||||||
{
|
{
|
||||||
|
ui->lineEdit_username->clear();
|
||||||
|
ui->lineEdit_password->clear();
|
||||||
|
ui->lineEdit_title->setText(QString(TAG_TITLE));
|
||||||
|
ui->plainTextEdit->setPlainText(QString(TAG_BODY));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -136,9 +198,85 @@ void Reportabug::updateGitreportTab()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Reportabug::replyFinished(QNetworkReply *reply)
|
||||||
|
{
|
||||||
|
int state = true;
|
||||||
|
QString answer = reply->readAll();
|
||||||
|
QString messageBody, messageTitle;
|
||||||
|
QMessageBox::Icon icon = QMessageBox::NoIcon;
|
||||||
|
if (answer.contains(QString("\"html_url\":"))) {
|
||||||
|
QString url;
|
||||||
|
for (int i=0; i<answer.split(QChar(',')).count(); i++)
|
||||||
|
if (answer.split(QChar(','))[i].split(QChar(':'))[0] == QString("\"html_url\"")) {
|
||||||
|
url = answer.split(QChar(','))[i].split(QString("\"html_url\":"))[1].remove(QChar('"'));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
messageBody += QString("%1\n").arg(QApplication::translate("Reportabug", "Message has been sended"));
|
||||||
|
messageBody += QString("Url: %2").arg(url);
|
||||||
|
messageTitle = QApplication::translate("Reportabug", "Done!");
|
||||||
|
icon = QMessageBox::Information;
|
||||||
|
state = true;
|
||||||
|
}
|
||||||
|
else if (answer.contains(QString("\"Bad credentials\""))) {
|
||||||
|
messageBody += QApplication::translate("Reportabug", "Incorrect username or password");
|
||||||
|
messageTitle = QApplication::translate("Reportabug", "Error!");
|
||||||
|
icon = QMessageBox::Critical;
|
||||||
|
state = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
messageBody += QApplication::translate("Reportabug", "An error occurs");
|
||||||
|
messageTitle = QApplication::translate("Reportabug", "Error!");
|
||||||
|
icon = QMessageBox::Critical;
|
||||||
|
state = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
break;
|
||||||
|
case QMessageBox::Retry:
|
||||||
|
if (state) updateTabs(ui->comboBox->currentIndex());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Reportabug::sendReportUsingGithub()
|
void Reportabug::sendReportUsingGithub()
|
||||||
{
|
{
|
||||||
|
// authorization
|
||||||
|
QString username = ui->lineEdit_username->text();
|
||||||
|
QString password = ui->lineEdit_password->text();
|
||||||
|
QString concatenated = username + QString(":") + password;
|
||||||
|
QByteArray userData = concatenated.toLocal8Bit().toBase64();
|
||||||
|
QString headerData = QString("Basic ") + userData;
|
||||||
|
// text
|
||||||
|
QString title = ui->lineEdit_title->text();
|
||||||
|
QString body = ui->plainTextEdit->toPlainText();
|
||||||
|
QByteArray text = prepareRequest(title, body);
|
||||||
|
QByteArray textSize = QByteArray::number(text.size());
|
||||||
|
// sending request
|
||||||
|
QNetworkRequest request = QNetworkRequest(parseString(QString(ISSUES_URL)));
|
||||||
|
request.setRawHeader("Authorization", headerData.toLocal8Bit());
|
||||||
|
request.setRawHeader("User-Agent", "reportabug");
|
||||||
|
request.setRawHeader("Host", "api.github.com");
|
||||||
|
request.setRawHeader("Accept", "*/*");
|
||||||
|
request.setRawHeader("Content-Type", "application/vnd.github.VERSION.raw+json");
|
||||||
|
request.setRawHeader("Content-Length", textSize);
|
||||||
|
QNetworkAccessManager *manager = new QNetworkAccessManager;
|
||||||
|
manager->post(request, text);
|
||||||
|
connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(replyFinished(QNetworkReply *)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
|
||||||
|
|
||||||
|
class QNetworkReply;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class Reportabug;
|
class Reportabug;
|
||||||
}
|
}
|
||||||
@ -45,6 +47,7 @@ public slots:
|
|||||||
private slots:
|
private slots:
|
||||||
void sendReportUsingGithub();
|
void sendReportUsingGithub();
|
||||||
void sendReportUsingGitreport();
|
void sendReportUsingGitreport();
|
||||||
|
void replyFinished(QNetworkReply *reply);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::Reportabug *ui;
|
Ui::Reportabug *ui;
|
||||||
@ -53,7 +56,12 @@ private:
|
|||||||
int getNumberByIndex(const int index);
|
int getNumberByIndex(const int index);
|
||||||
// ESC pressed event
|
// ESC pressed event
|
||||||
void keyPressEvent(QKeyEvent *pressedKey);
|
void keyPressEvent(QKeyEvent *pressedKey);
|
||||||
|
QString parseCmd(QString line,
|
||||||
|
const QString password = QString(),
|
||||||
|
const QString text = QString(),
|
||||||
|
const QString username = QString());
|
||||||
QString parseString(QString line);
|
QString parseString(QString line);
|
||||||
|
QByteArray prepareRequest(const QString title, const QString body);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,6 +43,9 @@
|
|||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Your GitHub account</string>
|
<string>Your GitHub account</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>username</string>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
@ -66,6 +69,9 @@
|
|||||||
<property name="echoMode">
|
<property name="echoMode">
|
||||||
<enum>QLineEdit::Password</enum>
|
<enum>QLineEdit::Password</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>password</string>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
Reference in New Issue
Block a user