Use namespace, fix some warnings.
This commit is contained in:
parent
fa225ff8e7
commit
c0eb7494e1
|
@ -16,4 +16,9 @@
|
||||||
|
|
||||||
#include "gitea2rss.hpp"
|
#include "gitea2rss.hpp"
|
||||||
|
|
||||||
|
namespace gitea2rss
|
||||||
|
{
|
||||||
|
|
||||||
bool cgi = false;
|
bool cgi = false;
|
||||||
|
|
||||||
|
} // namespace gitea2rss
|
||||||
|
|
|
@ -22,6 +22,9 @@
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
namespace gitea2rss
|
||||||
|
{
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::uint8_t;
|
using std::uint8_t;
|
||||||
using std::chrono::system_clock;
|
using std::chrono::system_clock;
|
||||||
|
@ -35,10 +38,10 @@ string get_http(const string &url);
|
||||||
size_t writer_body(char *data, size_t size, size_t nmemb);
|
size_t writer_body(char *data, size_t size, size_t nmemb);
|
||||||
|
|
||||||
//! Convert time_point to RFC 822 compliant time string.
|
//! Convert time_point to RFC 822 compliant time string.
|
||||||
const string strtime(const system_clock::time_point &timepoint);
|
string strtime(const system_clock::time_point &timepoint);
|
||||||
|
|
||||||
//! Convert ISO 8601 time string to RFC 822 time string.
|
//! Convert ISO 8601 time string to RFC 822 time string.
|
||||||
const string strtime(const string &time);
|
string strtime(const string &time);
|
||||||
|
|
||||||
//! Write line of XML.
|
//! Write line of XML.
|
||||||
void write_line(uint8_t spaces, const string &tag, const string &value);
|
void write_line(uint8_t spaces, const string &tag, const string &value);
|
||||||
|
@ -53,21 +56,23 @@ uint8_t write_releases(const string &url);
|
||||||
uint8_t write_tags(const string &url);
|
uint8_t write_tags(const string &url);
|
||||||
|
|
||||||
//! @brief Get the base URL, without trailing slash.
|
//! @brief Get the base URL, without trailing slash.
|
||||||
const string get_baseurl(const string &url);
|
string get_baseurl(const string &url);
|
||||||
|
|
||||||
//! Get the domain name.
|
//! Get the domain name.
|
||||||
const string get_domain(const string &url);
|
string get_domain(const string &url);
|
||||||
|
|
||||||
//! Get the full name of the repo (user/project).
|
//! Get the full name of the repo (user/project).
|
||||||
const string get_repo(const string &url);
|
string get_repo(const string &url);
|
||||||
|
|
||||||
//! Get the project name.
|
//! Get the project name.
|
||||||
const string get_project(const string &url);
|
string get_project(const string &url);
|
||||||
|
|
||||||
//! Escape some characters to named HTML entities.
|
//! Escape some characters to named HTML entities.
|
||||||
const string escape_some_html(string html);
|
string escape_some_html(string html);
|
||||||
|
|
||||||
//! Return environment variable or "" if it is not set.
|
//! Return environment variable or "" if it is not set.
|
||||||
string get_env_var(const string &variable);
|
string get_env_var(const string &variable);
|
||||||
|
|
||||||
|
} // namespace gitea2rss
|
||||||
|
|
||||||
#endif // GITEA2RSS_HPP
|
#endif // GITEA2RSS_HPP
|
||||||
|
|
13
src/http.cpp
13
src/http.cpp
|
@ -22,6 +22,9 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
namespace gitea2rss
|
||||||
|
{
|
||||||
|
|
||||||
using std::cerr;
|
using std::cerr;
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
|
@ -49,6 +52,7 @@ string get_http(const string &url)
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
||||||
curl_easy_setopt(connection, CURLOPT_WRITEFUNCTION, writer_body);
|
curl_easy_setopt(connection, CURLOPT_WRITEFUNCTION, writer_body);
|
||||||
|
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
||||||
CURLcode code{curl_easy_setopt(connection, CURLOPT_FOLLOWLOCATION, 1L)};
|
CURLcode code{curl_easy_setopt(connection, CURLOPT_FOLLOWLOCATION, 1L)};
|
||||||
if (code != CURLE_OK)
|
if (code != CURLE_OK)
|
||||||
{
|
{
|
||||||
|
@ -57,9 +61,9 @@ string get_http(const string &url)
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
||||||
curl_easy_setopt(connection, CURLOPT_MAXREDIRS, 5L);
|
curl_easy_setopt(connection, CURLOPT_MAXREDIRS, 5L);
|
||||||
|
|
||||||
code =
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
||||||
curl_easy_setopt(connection, CURLOPT_USERAGENT,
|
code = curl_easy_setopt(connection, CURLOPT_USERAGENT,
|
||||||
(string("gitea2rss/") += global::version).c_str());
|
(string("gitea2rss/") += version).c_str());
|
||||||
if (code != CURLE_OK)
|
if (code != CURLE_OK)
|
||||||
{
|
{
|
||||||
throw runtime_error{"Failed to set User-Agent."};
|
throw runtime_error{"Failed to set User-Agent."};
|
||||||
|
@ -68,6 +72,7 @@ string get_http(const string &url)
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
||||||
curl_easy_setopt(connection, CURLOPT_HTTPGET, 1L);
|
curl_easy_setopt(connection, CURLOPT_HTTPGET, 1L);
|
||||||
|
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
||||||
code = curl_easy_setopt(connection, CURLOPT_URL, url.c_str());
|
code = curl_easy_setopt(connection, CURLOPT_URL, url.c_str());
|
||||||
if (code != CURLE_OK)
|
if (code != CURLE_OK)
|
||||||
{
|
{
|
||||||
|
@ -116,3 +121,5 @@ size_t writer_body(char *data, size_t size, size_t nmemb)
|
||||||
|
|
||||||
return size * nmemb;
|
return size * nmemb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace gitea2rss
|
||||||
|
|
|
@ -21,9 +21,8 @@
|
||||||
|
|
||||||
using std::cerr;
|
using std::cerr;
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::endl;
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::chrono::system_clock;
|
using namespace gitea2rss;
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -66,15 +65,18 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
else if (argc < 2)
|
else if (argc < 2)
|
||||||
{
|
{
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
||||||
cerr << "usage: " << argv[0]
|
cerr << "usage: " << argv[0]
|
||||||
<< " URL of Gitea project [releases|tags]\n";
|
<< " URL of Gitea project [releases|tags]\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
||||||
url = argv[1];
|
url = argv[1];
|
||||||
if (argc > 2)
|
if (argc > 2)
|
||||||
{
|
{
|
||||||
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
||||||
type = argv[2];
|
type = argv[2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* This file is part of gitea2rss.
|
/* This file is part of gitea2rss.
|
||||||
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
* Copyright © 2019, 2020 tastytea <tastytea@tastytea.de>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -14,22 +14,25 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <json/json.h>
|
|
||||||
#include "gitea2rss.hpp"
|
#include "gitea2rss.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
#include <json/json.h>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
using std::cout;
|
|
||||||
using std::cerr;
|
using std::cerr;
|
||||||
|
using std::cout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
using std::stringstream;
|
using std::stringstream;
|
||||||
|
|
||||||
|
namespace gitea2rss
|
||||||
|
{
|
||||||
|
|
||||||
uint8_t write_releases(const string &url)
|
uint8_t write_releases(const string &url)
|
||||||
{
|
{
|
||||||
const string baseurl = get_baseurl(url);
|
const string baseurl = get_baseurl(url);
|
||||||
const string repo = get_repo(url);
|
const string repo = get_repo(url);
|
||||||
stringstream data(get_http(baseurl + "/api/v1/repos/"
|
stringstream data(
|
||||||
+ repo + "/releases"));
|
get_http(baseurl + "/api/v1/repos/" + repo + "/releases"));
|
||||||
|
|
||||||
if (cgi)
|
if (cgi)
|
||||||
{
|
{
|
||||||
|
@ -53,19 +56,25 @@ uint8_t write_releases(const string &url)
|
||||||
const string body = escape_some_html(release["body"].asString());
|
const string body = escape_some_html(release["body"].asString());
|
||||||
|
|
||||||
cout << " <item>\n";
|
cout << " <item>\n";
|
||||||
write_line(6, "title", get_project(url) + ": "
|
write_line(6, "title",
|
||||||
+ release["name"].asString());
|
get_project(url) + ": " + release["name"].asString());
|
||||||
write_line(6, "link", baseurl + "/" + repo + "/releases");
|
write_line(6, "link", (baseurl + "/" += repo) += "/releases");
|
||||||
write_line(6, "guid isPermaLink=\"false\"",
|
write_line(6, "guid isPermaLink=\"false\"",
|
||||||
get_domain(url) + " release " + release["id"].asString());
|
get_domain(url) + " release " + release["id"].asString());
|
||||||
write_line(6, "pubDate", strtime(release["published_at"].asString()));
|
write_line(6, "pubDate", strtime(release["published_at"].asString()));
|
||||||
write_line(6, "description",
|
write_line(6, "description",
|
||||||
"\n <![CDATA[<p><strong>" + type + "</strong></p>\n"
|
"\n <![CDATA[<p><strong>" + type
|
||||||
"<pre>" + body + "</pre>\n"
|
+ "</strong></p>\n"
|
||||||
" <p><a href=\"" + release["tarball_url"].asString()
|
"<pre>"
|
||||||
|
+ body
|
||||||
|
+ "</pre>\n"
|
||||||
|
" <p><a href=\""
|
||||||
|
+ release["tarball_url"].asString()
|
||||||
+ "\">Download tarball</a></p>]]>\n ");
|
+ "\">Download tarball</a></p>]]>\n ");
|
||||||
cout << " </item>\n";
|
cout << " </item>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace gitea2rss
|
||||||
|
|
|
@ -19,38 +19,41 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
|
namespace gitea2rss
|
||||||
|
{
|
||||||
|
|
||||||
using std::getenv;
|
using std::getenv;
|
||||||
|
|
||||||
const string get_baseurl(const string &url)
|
string get_baseurl(const string &url)
|
||||||
{
|
{
|
||||||
const size_t pos = url.find('/', 8);
|
const size_t pos = url.find('/', 8);
|
||||||
return url.substr(0, pos);
|
return url.substr(0, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
const string get_domain(const string &url)
|
string get_domain(const string &url)
|
||||||
{
|
{
|
||||||
const string baseurl = get_baseurl(url);
|
const string baseurl = get_baseurl(url);
|
||||||
return baseurl.substr(baseurl.rfind('/') + 1);
|
return baseurl.substr(baseurl.rfind('/') + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const string get_repo(const string &url)
|
string get_repo(const string &url)
|
||||||
{
|
{
|
||||||
const size_t pos = url.find('/', 8) + 1;
|
const size_t pos = url.find('/', 8) + 1;
|
||||||
return url.substr(pos);
|
return url.substr(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
const string get_project(const string &url)
|
string get_project(const string &url)
|
||||||
{
|
{
|
||||||
const string repo = get_repo(url);
|
const string repo = get_repo(url);
|
||||||
return repo.substr(repo.find('/') + 1);
|
return repo.substr(repo.find('/') + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const string escape_some_html(string html)
|
string escape_some_html(string html)
|
||||||
{
|
{
|
||||||
const std::map<const char, const string> names = {{'<', "<"},
|
const std::map<const char, const string> names = {{'<', "<"},
|
||||||
{'>', ">"}};
|
{'>', ">"}};
|
||||||
|
|
||||||
for (auto &pair : names)
|
for (const auto &pair : names)
|
||||||
{
|
{
|
||||||
const std::regex re(string(1, pair.first));
|
const std::regex re(string(1, pair.first));
|
||||||
html = std::regex_replace(html, re, pair.second);
|
html = std::regex_replace(html, re, pair.second);
|
||||||
|
@ -68,3 +71,5 @@ string get_env_var(const string &variable)
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace gitea2rss
|
||||||
|
|
28
src/tags.cpp
28
src/tags.cpp
|
@ -1,5 +1,5 @@
|
||||||
/* This file is part of gitea2rss.
|
/* This file is part of gitea2rss.
|
||||||
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
* Copyright © 2019, 2020 tastytea <tastytea@tastytea.de>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -14,13 +14,16 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <json/json.h>
|
|
||||||
#include "gitea2rss.hpp"
|
#include "gitea2rss.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
#include <json/json.h>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
namespace gitea2rss
|
||||||
|
{
|
||||||
|
|
||||||
using std::cout;
|
|
||||||
using std::cerr;
|
using std::cerr;
|
||||||
|
using std::cout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
using std::stringstream;
|
using std::stringstream;
|
||||||
|
|
||||||
|
@ -28,8 +31,8 @@ uint8_t write_tags(const string &url)
|
||||||
{
|
{
|
||||||
const string baseurl = get_baseurl(url);
|
const string baseurl = get_baseurl(url);
|
||||||
const string repo = get_repo(url);
|
const string repo = get_repo(url);
|
||||||
stringstream data(get_http(baseurl + "/api/v1/repos/"
|
stringstream data(
|
||||||
+ repo + "/git/refs"));
|
get_http(baseurl + "/api/v1/repos/" + repo + "/git/refs"));
|
||||||
|
|
||||||
if (cgi)
|
if (cgi)
|
||||||
{
|
{
|
||||||
|
@ -59,12 +62,15 @@ uint8_t write_tags(const string &url)
|
||||||
|
|
||||||
cout << " <item>\n";
|
cout << " <item>\n";
|
||||||
write_line(6, "title", get_project(url) + ": " + name);
|
write_line(6, "title", get_project(url) + ": " + name);
|
||||||
write_line(6, "link", baseurl + "/" + repo + "/src/tag/" + name);
|
write_line(6, "link", baseurl + "/" += repo + "/src/tag/" += name);
|
||||||
write_line(6, "guid isPermaLink=\"false\"",
|
write_line(6, "guid isPermaLink=\"false\"",
|
||||||
get_domain(url) + " tag " + sha);
|
get_domain(url) + " tag " + sha);
|
||||||
write_line(6, "description",
|
write_line(6, "description",
|
||||||
"\n <![CDATA[<p><strong>" + name + "</strong> "
|
"\n <![CDATA[<p><strong>" + name
|
||||||
"on commit " + sha + "</p>\n"
|
+ "</strong> "
|
||||||
|
"on commit "
|
||||||
|
+ sha
|
||||||
|
+ "</p>\n"
|
||||||
" <p><a href=\""
|
" <p><a href=\""
|
||||||
+ baseurl + "/" + repo + "/archive/" + name + ".tar.gz"
|
+ baseurl + "/" + repo + "/archive/" + name + ".tar.gz"
|
||||||
+ "\">Download tarball</a></p>]]>\n ");
|
+ "\">Download tarball</a></p>]]>\n ");
|
||||||
|
@ -74,3 +80,5 @@ uint8_t write_tags(const string &url)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace gitea2rss
|
||||||
|
|
16
src/time.cpp
16
src/time.cpp
|
@ -1,5 +1,5 @@
|
||||||
/* This file is part of gitea2rss.
|
/* This file is part of gitea2rss.
|
||||||
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
* Copyright © 2019, 2020 tastytea <tastytea@tastytea.de>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -14,21 +14,23 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iomanip>
|
|
||||||
#include "gitea2rss.hpp"
|
#include "gitea2rss.hpp"
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
const string strtime(const system_clock::time_point &timepoint)
|
namespace gitea2rss
|
||||||
|
{
|
||||||
|
|
||||||
|
string strtime(const system_clock::time_point &timepoint)
|
||||||
{
|
{
|
||||||
constexpr uint16_t bufsize = 1024;
|
constexpr uint16_t bufsize = 1024;
|
||||||
std::time_t time = system_clock::to_time_t(timepoint);
|
std::time_t time = system_clock::to_time_t(timepoint);
|
||||||
std::tm *tm;
|
std::tm *tm{std::gmtime(&time)};
|
||||||
tm = std::gmtime(&time);
|
|
||||||
char buffer[bufsize];
|
char buffer[bufsize];
|
||||||
std::strftime(buffer, bufsize, "%a, %d %b %Y %T %z", tm);
|
std::strftime(buffer, bufsize, "%a, %d %b %Y %T %z", tm);
|
||||||
return static_cast<const string>(buffer);
|
return static_cast<const string>(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
const string strtime(const string &time)
|
string strtime(const string &time)
|
||||||
{
|
{
|
||||||
std::tm tm = {};
|
std::tm tm = {};
|
||||||
tm.tm_isdst = -1; // Detect daylight saving time.
|
tm.tm_isdst = -1; // Detect daylight saving time.
|
||||||
|
@ -36,3 +38,5 @@ const string strtime(const string &time)
|
||||||
ss >> std::get_time(&tm, "%Y-%m-%dT%T"); // Assume time is UTC.
|
ss >> std::get_time(&tm, "%Y-%m-%dT%T"); // Assume time is UTC.
|
||||||
return strtime(system_clock::from_time_t(timegm(&tm)));
|
return strtime(system_clock::from_time_t(timegm(&tm)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace gitea2rss
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
#ifndef VERSION_HPP
|
#ifndef VERSION_HPP
|
||||||
#define VERSION_HPP
|
#define VERSION_HPP
|
||||||
|
|
||||||
namespace global
|
namespace gitea2rss
|
||||||
{
|
{
|
||||||
|
|
||||||
static constexpr char version[] = "@PROJECT_VERSION@";
|
static constexpr char version[] = "@PROJECT_VERSION@";
|
||||||
}
|
|
||||||
|
} // namespace gitea2rss
|
||||||
|
|
||||||
#endif // VERSION_HPP
|
#endif // VERSION_HPP
|
||||||
|
|
|
@ -20,8 +20,10 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
|
namespace gitea2rss
|
||||||
|
{
|
||||||
|
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::getenv;
|
|
||||||
|
|
||||||
void write_line(const uint8_t spaces, const string &tag, const string &value)
|
void write_line(const uint8_t spaces, const string &tag, const string &value)
|
||||||
{
|
{
|
||||||
|
@ -74,6 +76,8 @@ void write_preamble(const string &url, const string &type)
|
||||||
write_line(4, "title", get_project(url) + " " + type);
|
write_line(4, "title", get_project(url) + " " + type);
|
||||||
write_line(4, "link", url);
|
write_line(4, "link", url);
|
||||||
write_line(4, "description", "List of " + type + " of " + get_repo(url));
|
write_line(4, "description", "List of " + type + " of " + get_repo(url));
|
||||||
write_line(4, "generator", string("gitea2rss ") + global::version);
|
write_line(4, "generator", string("gitea2rss ") + version);
|
||||||
write_line(4, "lastBuildDate", strtime(system_clock::now()));
|
write_line(4, "lastBuildDate", strtime(system_clock::now()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace gitea2rss
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* This file is part of gitea2rss.
|
/* This file is part of gitea2rss.
|
||||||
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
* Copyright © 2019, 2020 tastytea <tastytea@tastytea.de>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -14,23 +14,23 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <catch.hpp>
|
|
||||||
#include "gitea2rss.hpp"
|
#include "gitea2rss.hpp"
|
||||||
|
#include <catch.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
using namespace gitea2rss;
|
||||||
|
|
||||||
SCENARIO("escape_some_html() works as expected", "[strings]")
|
SCENARIO("escape_some_html() works as expected", "[strings]")
|
||||||
{
|
{
|
||||||
WHEN("String with escape-able characters")
|
WHEN("String with escape-able characters")
|
||||||
{
|
{
|
||||||
const string escaped
|
const string escaped = escape_some_html("<p><small>.</small></p>");
|
||||||
= escape_some_html("<p><small>.</small></p>");
|
|
||||||
|
|
||||||
THEN("The HTML is escaped")
|
THEN("The HTML is escaped")
|
||||||
{
|
{
|
||||||
REQUIRE(escaped ==
|
REQUIRE(escaped
|
||||||
"<p><small>.</small></p>");
|
== "<p><small>.</small></p>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* This file is part of gitea2rss.
|
/* This file is part of gitea2rss.
|
||||||
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
* Copyright © 2019, 2020 tastytea <tastytea@tastytea.de>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -14,18 +14,19 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <catch.hpp>
|
|
||||||
#include "gitea2rss.hpp"
|
#include "gitea2rss.hpp"
|
||||||
|
#include <catch.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
using namespace gitea2rss;
|
||||||
|
|
||||||
SCENARIO("get_baseurl() works as expected", "[strings]")
|
SCENARIO("get_baseurl() works as expected", "[strings]")
|
||||||
{
|
{
|
||||||
WHEN("HTTPS URL")
|
WHEN("HTTPS URL")
|
||||||
{
|
{
|
||||||
const string baseurl
|
const string baseurl =
|
||||||
= get_baseurl("https://git.example.com/user/project");
|
get_baseurl("https://git.example.com/user/project");
|
||||||
|
|
||||||
THEN("The base URL is correctly returned")
|
THEN("The base URL is correctly returned")
|
||||||
{
|
{
|
||||||
|
@ -35,8 +36,8 @@ SCENARIO ("get_baseurl() works as expected", "[strings]")
|
||||||
|
|
||||||
WHEN("HTTP URL")
|
WHEN("HTTP URL")
|
||||||
{
|
{
|
||||||
const string baseurl
|
const string baseurl =
|
||||||
= get_baseurl("http://git.example.com/user/project");
|
get_baseurl("http://git.example.com/user/project");
|
||||||
|
|
||||||
THEN("The base URL is correctly returned")
|
THEN("The base URL is correctly returned")
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* This file is part of gitea2rss.
|
/* This file is part of gitea2rss.
|
||||||
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
* Copyright © 2019, 2020 tastytea <tastytea@tastytea.de>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -14,18 +14,19 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <catch.hpp>
|
|
||||||
#include "gitea2rss.hpp"
|
#include "gitea2rss.hpp"
|
||||||
|
#include <catch.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
using namespace gitea2rss;
|
||||||
|
|
||||||
SCENARIO("get_domain() works as expected", "[strings]")
|
SCENARIO("get_domain() works as expected", "[strings]")
|
||||||
{
|
{
|
||||||
WHEN("HTTPS URL is valid")
|
WHEN("HTTPS URL is valid")
|
||||||
{
|
{
|
||||||
const string domain
|
const string domain =
|
||||||
= get_domain("https://git.example.com/user/project");
|
get_domain("https://git.example.com/user/project");
|
||||||
|
|
||||||
THEN("The domain is correctly returned")
|
THEN("The domain is correctly returned")
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* This file is part of gitea2rss.
|
/* This file is part of gitea2rss.
|
||||||
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
* Copyright © 2019, 2020 tastytea <tastytea@tastytea.de>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -14,11 +14,12 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <catch.hpp>
|
|
||||||
#include "gitea2rss.hpp"
|
#include "gitea2rss.hpp"
|
||||||
|
#include <catch.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
using namespace gitea2rss;
|
||||||
|
|
||||||
SCENARIO("get_http() works as expected", "[http]")
|
SCENARIO("get_http() works as expected", "[http]")
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* This file is part of gitea2rss.
|
/* This file is part of gitea2rss.
|
||||||
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
* Copyright © 2019, 2020 tastytea <tastytea@tastytea.de>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -14,18 +14,19 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <catch.hpp>
|
|
||||||
#include "gitea2rss.hpp"
|
#include "gitea2rss.hpp"
|
||||||
|
#include <catch.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
using namespace gitea2rss;
|
||||||
|
|
||||||
SCENARIO("get_project() works as expected", "[strings]")
|
SCENARIO("get_project() works as expected", "[strings]")
|
||||||
{
|
{
|
||||||
WHEN("HTTPS URL is valid")
|
WHEN("HTTPS URL is valid")
|
||||||
{
|
{
|
||||||
const string project
|
const string project =
|
||||||
= get_project("https://git.example.com/user/project");
|
get_project("https://git.example.com/user/project");
|
||||||
|
|
||||||
THEN("The project is correctly returned")
|
THEN("The project is correctly returned")
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* This file is part of gitea2rss.
|
/* This file is part of gitea2rss.
|
||||||
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
* Copyright © 2019, 2020 tastytea <tastytea@tastytea.de>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -14,18 +14,18 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <catch.hpp>
|
|
||||||
#include "gitea2rss.hpp"
|
#include "gitea2rss.hpp"
|
||||||
|
#include <catch.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
using namespace gitea2rss;
|
||||||
|
|
||||||
SCENARIO("get_repo() works as expected", "[strings]")
|
SCENARIO("get_repo() works as expected", "[strings]")
|
||||||
{
|
{
|
||||||
WHEN("HTTPS URL is valid")
|
WHEN("HTTPS URL is valid")
|
||||||
{
|
{
|
||||||
const string repo
|
const string repo = get_repo("https://git.example.com/user/project");
|
||||||
= get_repo("https://git.example.com/user/project");
|
|
||||||
|
|
||||||
THEN("The repo is correctly returned")
|
THEN("The repo is correctly returned")
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* This file is part of gitea2rss.
|
/* This file is part of gitea2rss.
|
||||||
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
* Copyright © 2019, 2020 tastytea <tastytea@tastytea.de>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -14,20 +14,20 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <chrono>
|
|
||||||
#include <catch.hpp>
|
|
||||||
#include "gitea2rss.hpp"
|
#include "gitea2rss.hpp"
|
||||||
|
#include <catch.hpp>
|
||||||
|
#include <chrono>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
using namespace gitea2rss;
|
||||||
|
|
||||||
SCENARIO("strtime() works as expected", "[time]")
|
SCENARIO("strtime() works as expected", "[time]")
|
||||||
{
|
{
|
||||||
GIVEN("Time as time_point")
|
GIVEN("Time as time_point")
|
||||||
{
|
{
|
||||||
std::chrono::system_clock::time_point tp;
|
std::chrono::system_clock::time_point tp;
|
||||||
const string time
|
const string time = strtime(tp);
|
||||||
= strtime(tp);
|
|
||||||
|
|
||||||
THEN("The time is returned in the correct format")
|
THEN("The time is returned in the correct format")
|
||||||
{
|
{
|
||||||
|
@ -37,8 +37,7 @@ SCENARIO ("strtime() works as expected", "[time]")
|
||||||
|
|
||||||
GIVEN("Time as ISO 8601 string")
|
GIVEN("Time as ISO 8601 string")
|
||||||
{
|
{
|
||||||
const string time
|
const string time = strtime("1970-01-01T00:00:00+0000");
|
||||||
= strtime("1970-01-01T00:00:00+0000");
|
|
||||||
|
|
||||||
THEN("The time is returned in the correct format")
|
THEN("The time is returned in the correct format")
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue