diff --git a/README.md b/README.md index bc65798..b28e9f2 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/sources/CMakeLists.txt b/sources/CMakeLists.txt index 359204d..2925c6f 100644 --- a/sources/CMakeLists.txt +++ b/sources/CMakeLists.txt @@ -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) diff --git a/sources/src/CMakeLists.txt b/sources/src/CMakeLists.txt index c60cba6..1ada67b 100644 --- a/sources/src/CMakeLists.txt +++ b/sources/src/CMakeLists.txt @@ -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) diff --git a/sources/src/config.h.in b/sources/src/config.h.in index 19593ab..00c7314 100644 --- a/sources/src/config.h.in +++ b/sources/src/config.h.in @@ -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!" diff --git a/sources/src/githubmodule.cpp b/sources/src/githubmodule.cpp index 61ed5df..3ea7f5a 100644 --- a/sources/src/githubmodule.cpp +++ b/sources/src/githubmodule.cpp @@ -124,9 +124,14 @@ void GithubModule::sendReportUsingGithub(const QMap info) if (debug) qDebug() << "[GithubModule]" << "[sendReportUsingGithub]"; // authentication - QString concatenated = info[QString("username")] + QString(":") + info[QString("password")]; - QByteArray userData = concatenated.toLocal8Bit().toBase64(); - QString headerData = QString("Basic ") + userData; + 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(); + headerData = QString("Basic ") + userData; + } // text QByteArray text = prepareRequest(info[QString("title")], info[QString("body")]); QByteArray textSize = QByteArray::number(text.size()); diff --git a/sources/src/githubmodule.h b/sources/src/githubmodule.h index b709f31..81d3aa8 100644 --- a/sources/src/githubmodule.h +++ b/sources/src/githubmodule.h @@ -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 info); diff --git a/sources/src/reportabug.cpp b/sources/src/reportabug.cpp index c1bce8d..38b9db6 100644 --- a/sources/src/reportabug.cpp +++ b/sources/src/reportabug.cpp @@ -29,9 +29,9 @@ #include #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,21 +120,29 @@ 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 - return -1; + 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 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 */ } diff --git a/sources/src/reportabug.h b/sources/src/reportabug.h index 6171e1e..bb5905e 100644 --- a/sources/src/reportabug.h +++ b/sources/src/reportabug.h @@ -84,7 +84,7 @@ private: /** * @brief contains information about enabled modules */ - bool modules[2]; + bool modules[3]; /** * @brief class user interface */ diff --git a/sources/src/reportabug.ui b/sources/src/reportabug.ui index eb8e9c0..aac9412 100644 --- a/sources/src/reportabug.ui +++ b/sources/src/reportabug.ui @@ -109,19 +109,6 @@ - - - - Qt::Vertical - - - - 20 - 40 - - - - diff --git a/sources/version.h.in b/sources/version.h.in index 024eb9d..7a9abfc 100644 --- a/sources/version.h.in +++ b/sources/version.h.in @@ -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 */