gitea2rss/src/releases.cpp

81 lines
2.5 KiB
C++
Raw Normal View History

/* This file is part of gitea2rss.
2020-10-27 12:05:50 +01:00
* Copyright © 2019, 2020 tastytea <tastytea@tastytea.de>
*
* 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
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2020-10-27 12:05:50 +01:00
#include "gitea2rss.hpp"
#include <iostream>
#include <json/json.h>
2020-10-27 12:05:50 +01:00
#include <sstream>
using std::cerr;
2020-10-27 12:05:50 +01:00
using std::cout;
using std::endl;
using std::stringstream;
2020-10-27 12:05:50 +01:00
namespace gitea2rss
{
2019-04-20 07:43:23 +02:00
uint8_t write_releases(const string &url)
{
const string baseurl = get_baseurl(url);
const string repo = get_repo(url);
2020-10-27 12:05:50 +01:00
stringstream data(
get_http(baseurl + "/api/v1/repos/" + repo + "/releases"));
2019-04-20 06:08:17 +02:00
if (cgi)
{
cout << endl;
}
if (data.str().empty())
{
cerr << "Error: Could not download releases.\n";
return 2;
}
write_preamble(url, "releases");
Json::Value json;
data >> json;
for (const Json::Value &release : json)
{
const bool prerelease = release["prerelease"].asBool();
const string type = (prerelease ? "Pre-Release" : "Stable");
const string body = escape_some_html(release["body"].asString());
2019-04-20 07:43:23 +02:00
cout << " <item>\n";
2020-10-27 12:05:50 +01:00
write_line(6, "title",
get_project(url) + ": " + release["name"].asString());
write_line(6, "link", (baseurl + "/" += repo) += "/releases");
write_line(6, "guid isPermaLink=\"false\"",
get_domain(url) + " release " + release["id"].asString());
write_line(6, "pubDate", strtime(release["published_at"].asString()));
write_line(6, "description",
2020-10-27 12:05:50 +01:00
"\n <![CDATA[<p><strong>" + type
+ "</strong></p>\n"
"<pre>"
+ body
+ "</pre>\n"
" <p><a href=\""
+ release["tarball_url"].asString()
+ "\">Download tarball</a></p>]]>\n ");
cout << " </item>\n";
}
return 0;
}
2020-10-27 12:05:50 +01:00
} // namespace gitea2rss