add token support

This commit is contained in:
arcan1s 2014-07-29 17:38:16 +04:00
parent bc10fc76ab
commit 8c833a8146
10 changed files with 115 additions and 52 deletions

View File

@ -4,7 +4,7 @@ reportabug
Information
-----------
A simple Qt application/library which allows users to create an issue for GitHub projects. It may work over [GitHub](https://github.com) or [GitReport](https://gitreports.com/). For the developer configuration please use `config.h.in` header.
Qt application/library which allows users to create an issue for GitHub projects. It may work over [GitHub](https://github.com) or [GitReport](https://gitreports.com/). For the developer configuration please use `config.h.in` header.
Configuration
-------------
@ -20,7 +20,7 @@ Available variables:
* `TAG_BODY` - default body of an issue. It may be used for both modules.
* `TAG_TITLE` - default title of an issue. It may be used only for GitHub module.
* `TAG_ASSIGNEE` - assign an issue to this account. It may be used only for GitHub module. This tag will work only if user has push access. If it will be empty, it will be ignored.
* `TAG_LABELS` - set this labels to an issue. Labels should be comma separated. It may be used only for GitHub module. This tag will work only if user has push access. If it will be empty, it will be ignored.
* `TAG_LABELS` - set these labels to an issue. Labels should be comma separated. It may be used only for GitHub module. This tag will work only if user has push access. If it will be empty, it will be ignored.
* `TAG_MILESTONE` - set this milestone to an issue. It may be used only for GitHub module. This tag will work only if user has push access. If it will be empty, it will be ignored.
### Send issue over GitHub ###
@ -36,6 +36,14 @@ Available variables:
This module requires `QtNetwork` module. To disable this module use `-DENABLE_GITHUB=0` cmake flag.
### Send issue over GitHub using own token ###
This module requires your access token. Please visit [this page](https://github.com/settings/applications) and generate a new one. Needed scopes are `public_repo` (or `repo` if you will use it for a private repository). Please keep in mind that passing the token in the clear, you may discredit your account. The typical POST request is
curl -X POST -H "Authorization: token token" -d '{"title":"A new bug","body":"Some error occurs"}' https://api.github.com/repos/owner/repo/issues
This module requires `QtNetwork` module. To enable this module set up your token using `-DOWN_GITHUB_TOKEN=0` cmake flag.
### Send issue over GitReport ###
[GitReport](https://gitreports.com/about) is used for creating issue. Please visit [this page](https://gitreports.com/) and set up it for your repository.
@ -105,6 +113,7 @@ Installation
* `-DBUILD_DOCS:BOOL=1` - build developer documentation
* `-DENABLE_GITHUB=0` - disable GitHub module
* `-DENABLE_GITREPORT=0` - disable GitReport module
* `-DOWN_GITHUB_TOKEN=STRING` - use STRING as own GitHub token
* `-DUSE_QT5:BOOL=0` - use Qt4 instead of Qt5 for GUI
Additional information

View File

@ -23,11 +23,21 @@ message (STATUS "Version: ${SUBPROJECT_VERSION}")
message (STATUS "Build date: ${CURRENT_DATE}")
# install options
option (USE_QT5 "Use Qt5 instead of Qt4" ON)
option (BUILD_AS_LIBRARY "Build the application as a shared library" ON)
option (BUILD_DOCS "Build developers documentation" OFF)
option (ENABLE_GITHUB "Enable GitHub module" ON)
option (ENABLE_GITREPORT "Enable GitReport module" ON)
option (USE_QT5 "Use Qt5 instead of Qt4" ON)
set (OWN_GITHUB_TOKEN "" CACHE STRING "Use own GitHub token instead of GitReport")
# set flags
if (OWN_GITHUB_TOKEN STREQUAL "")
set (USE_OWN_TOKEN OFF)
else ()
set (USE_OWN_TOKEN ON)
endif ()
if (USE_OWN_TOKEN)
set (ENABLE_GITREPORT OFF)
endif ()
# flags
if (CMAKE_COMPILER_IS_GNUCXX)

View File

@ -2,7 +2,7 @@
set (SOURCES main.cpp reportabug.cpp)
set (HEADERS reportabug.h)
set (FORMS reportabug.ui)
if (ENABLE_GITHUB)
if (ENABLE_GITHUB OR USE_OWN_TOKEN)
set (SOURCES ${SOURCES} githubmodule.cpp)
set (HEADERS ${HEADERS} githubmodule.h)
endif ()
@ -25,7 +25,7 @@ if (USE_QT5)
add_definitions (${Qt5Widgets_DEFINITIONS})
include_directories (${Qt5Core_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS})
set (QT_USED_LIBRARIES ${Qt5Core_LIBRARIES} ${Qt5Widgets_LIBRARIES})
if (ENABLE_GITHUB)
if (ENABLE_GITHUB OR USE_OWN_TOKEN)
find_package (Qt5Network REQUIRED)
add_definitions (${Qt5Network_DEFINITIONS})
include_directories (${Qt5Network_INCLUDE_DIRS})
@ -48,7 +48,7 @@ if (USE_QT5)
else ()
set (QT_USED_COMPONENTS QtCore QtGui)
if (ENABLE_GITHUB)
if (ENABLE_GITHUB OR USE_OWN_TOKEN)
set (QT_USED_COMPONENTS ${QT_USED_COMPONENTS} QtNetwork)
endif ()
if (ENABLE_GITREPORT)
@ -57,7 +57,7 @@ else ()
find_package(Qt4 COMPONENTS ${QT_USED_COMPONENTS} REQUIRED)
include (${QT_USE_FILE})
set (QT_USED_LIBRARIES ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY})
if (ENABLE_GITHUB)
if (ENABLE_GITHUB OR USE_OWN_TOKEN)
set (QT_USED_LIBRARIES ${QT_USED_LIBRARIES} ${QT_QTNETWORK_LIBRARY})
endif ()
if (ENABLE_GITREPORT)

View File

@ -20,7 +20,7 @@
/*
* main configuration
* Main configuration
*/
// the owner of the source repository
#define OWNER "arcan1s"
@ -35,13 +35,13 @@
#define TAG_MILESTONE ""
// comma separated
#define TAG_LABELS "auto,bug"
// modules. Please use -DENABLE_GITHUB and -DENABLE_GITREPORT cmake flags
// modules. Please use -DENABLE_GITHUB= and -DENABLE_GITREPORT= cmake flags
// DO NOT EDIT THEM!
#cmakedefine ENABLE_GITHUB
#cmakedefine ENABLE_GITREPORT
/*
* configuration of creating an issue using GitHub API
* Configuration of creating an issue using GitHub API
*/
// combobox text
#define GITHUB_COMBOBOX "I want to report a bug using my GitHub account"
@ -50,10 +50,25 @@
#define ISSUES_URL "https://api.github.com/repos/$OWNER/$PROJECT/issues"
/*
* configuration of creating an issue using GitReports
* Configuration of creating an issue using GitHub API and own token
*
* please, visit https://gitreports.com/
* and set up it for your repository
* This module will be used instead of GitReport module.
* To create a token please visit https://github.com/settings/applications
* and generate new one. Needed scopes are public_repo
* (or repo if you will use it for a private repository).
* Please keep in mind that passing the token in the clear,
* you may discredit your account.
*/
// please use -DOWN_GITHUB_TOKEN= cmake flag to define it
// if it is empty, it will be ignored
// DO NOT EDIT IT!
#cmakedefine OWN_GITHUB_TOKEN "@OWN_GITHUB_TOKEN@"
/*
* Configuration of creating an issue using GitReports
*
* Please, visit https://gitreports.com/
* and set up it for your repository.
*/
// combobox text
#define GITREPORT_COMBOBOX "GitHub? I don't understand what do you want from me!"

View File

@ -124,9 +124,14 @@ void GithubModule::sendReportUsingGithub(const QMap<QString, QString> info)
if (debug) qDebug() << "[GithubModule]" << "[sendReportUsingGithub]";
// authentication
QString headerData;
if (info.contains(QString("userdata")))
headerData = QString("token ") + info[QString("userdata")];
else {
QString concatenated = info[QString("username")] + QString(":") + info[QString("password")];
QByteArray userData = concatenated.toLocal8Bit().toBase64();
QString headerData = QString("Basic ") + userData;
headerData = QString("Basic ") + userData;
}
// text
QByteArray text = prepareRequest(info[QString("title")], info[QString("body")]);
QByteArray textSize = QByteArray::number(text.size());

View File

@ -38,7 +38,14 @@ class QNetworkReply;
* [the API page](https://developer.github.com/v3/issues/) for more details.
* This module requires an users authentication. The typical POST request is:
* @code
* curl -X POST -u user:pass -d '{"title":"A new bug","body":"Some error occurs"}' https://api.github.com/repos/owner/repo/issues
* curl -X POST -u user:pass -d '{"title":"A new bug","body":"Some error occurs"}' \
* https://api.github.com/repos/owner/repo/issues
* @endcode
*
* The module also may send request using given token. In this case request is:
* @code
* curl -X POST -H "Authorization: token token" -d '{"title":"A new bug","body":"Some error occurs"}' \
* https://api.github.com/repos/owner/repo/issues
* @endcode
*
* This module depends on QtNetwork module.
@ -67,6 +74,7 @@ public slots:
* body (body of an issue),
* password (GitHub password),
* title (title of an issue),
* userdata (given GitHub token, it is optional key),
* username (GitHub user name),
*/
void sendReportUsingGithub(const QMap<QString, QString> info);

View File

@ -29,9 +29,9 @@
#include <QPushButton>
#include "config.h"
#ifdef ENABLE_GITHUB
#if defined(ENABLE_GITHUB) || defined(OWN_GITHUB_TOKEN)
#include "githubmodule.h"
#endif /* ENABLE_GITHUB */
#endif /* defined(ENABLE_GITHUB) || defined(OWN_GITHUB_TOKEN) */
#ifdef ENABLE_GITREPORT
#include "gitreportmodule.h"
#endif /* ENABLE_GITREPORT */
@ -63,9 +63,9 @@ Reportabug::~Reportabug()
{
if (debug) qDebug() << "[Reportabug]" << "[~Reportabug]";
#ifdef ENABLE_GITHUB
#if defined(ENABLE_GITHUB) || defined(OWN_GITHUB_TOKEN)
delete github;
#endif /* ENABLE_GITHUB */
#endif /* defined(ENABLE_GITHUB) || defined(OWN_GITHUB_TOKEN) */
#ifdef ENABLE_GITREPORT
delete gitreport;
#endif /* ENABLE_GITREPORT */
@ -106,9 +106,9 @@ void Reportabug::createComboBox()
ui->comboBox->clear();
if (modules[0])
ui->comboBox->addItem(QString(GITHUB_COMBOBOX));
if (modules[1])
ui->comboBox->addItem(QString(GITREPORT_COMBOBOX));
ui->comboBox->addItem(QApplication::translate("Reportabug", GITHUB_COMBOBOX));
if (modules[1] || modules[2])
ui->comboBox->addItem(QApplication::translate("Reportabug", GITREPORT_COMBOBOX));
}
@ -120,20 +120,28 @@ int Reportabug::getNumberByIndex(const int index)
if (debug) qDebug() << "[Reportabug]" << "[getNumberByIndex]";
if (debug) qDebug() << "[Reportabug]" << "[getNumberByIndex]" << ":" << "Index" << index;
if (index == -1)
// nothing to do
if ((modules[0]) && (modules[1])) {
if (index == 0)
return 0;
else if (index == 1)
return 1;
}
else if ((modules[0]) && (modules[2])) {
if (index == 0)
return 0;
else if (index == 1)
return 2;
}
else if ((modules[1]) && (modules[2]))
// wtf??
return -1;
else if ((modules[0]) && (modules[1]))
// both are enabled
return index;
else if (modules[0])
// only github is enabled
return 0;
else if (modules[1])
// only gitreport is enabled
return 1;
else
// nothing to do
else if (modules[2])
return 2;
return -1;
}
@ -147,10 +155,13 @@ void Reportabug::initModules()
modules[0] = false;
modules[1] = false;
modules[2] = false;
#if defined(ENABLE_GITHUB) || defined(OWN_GITHUB_TOKEN)
github = new GithubModule(this, debug);
#endif /* defined(ENABLE_GITHUB) || defined(OWN_GITHUB_TOKEN) */
#ifdef ENABLE_GITHUB
modules[0] = true;
github = new GithubModule(this, debug);
#endif /* ENABLE_GITHUB */
#ifdef ENABLE_GITREPORT
modules[1] = true;
@ -158,6 +169,9 @@ void Reportabug::initModules()
// 4 is a magic number. Seriously
ui->verticalLayout->insertWidget(4, gitreport->webView);
#endif /* ENABLE_GITREPORT */
#ifdef OWN_GITHUB_TOKEN
modules[2] = true;
#endif /* OWN_GITHUB_TOKEN */
}
@ -203,10 +217,10 @@ void Reportabug::sendReport()
int number = getNumberByIndex(ui->comboBox->currentIndex());
QMap<QString, QString> info;
info[QString("username")] = ui->lineEdit_username->text();
info[QString("body")] = ui->textEdit->toPlainText();
info[QString("password")] = ui->lineEdit_password->text();
info[QString("title")] = ui->lineEdit_title->text();
info[QString("body")] = ui->textEdit->toPlainText();
info[QString("username")] = ui->lineEdit_username->text();
if (number == -1)
return;
@ -218,6 +232,12 @@ void Reportabug::sendReport()
else if (number == 1)
gitreport->sendReportUsingGitreport(info);
#endif /* ENABLE_GITREPORT */
#ifdef OWN_GITHUB_TOKEN
else if (number == 2) {
info[QString("userdata")] = QString(OWN_GITHUB_TOKEN);
github->sendReportUsingGithub(info);
}
#endif /* OWN_GITHUB_TOKEN */
}
@ -281,4 +301,11 @@ void Reportabug::updateTabs(const int index)
connect(gitreport->webView, SIGNAL(loadFinished(bool)), gitreport, SLOT(gitreportLoaded(bool)));
}
#endif /* ENABLE_GITREPORT */
#ifdef OWN_GITHUB_TOKEN
else if (number == 2) {
ui->widget_auth->setHidden(true);
ui->widget_title->setHidden(false);
ui->textEdit->setHidden(false);
}
#endif /* OWN_GITHUB_TOKEN */
}

View File

@ -84,7 +84,7 @@ private:
/**
* @brief contains information about enabled modules
*/
bool modules[2];
bool modules[3];
/**
* @brief class user interface
*/

View File

@ -109,19 +109,6 @@
</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>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">

View File

@ -16,9 +16,11 @@
#define CMAKE_BUILD_TYPE "@CMAKE_BUILD_TYPE@"
#define CMAKE_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@"
#define SUBPROJECT_USE_QT5 "@USE_QT5@"
#define SUBPROJECT_DOCS "@BUILD_DOCS@"
#define SUBPROJECT_LIBRARY "@BUILD_AS_LIBRARY@"
#define SUBPROJECT_GITHUB_MODULE "@ENABLE_GITHUB@"
#define SUBPROJECT_GITREPORT_MODULE "@ENABLE_GITREPORT@"
#define SUBPROJECT_OWN_GITHUB_TOKEN "@OWN_GITHUB_TOKEN@"
#define SUBPROJECT_USE_QT5 "@USE_QT5@"
#endif /* VERSION_H */