2019-04-20 05:15:30 +02:00
|
|
|
/* This file is part of gitea2rss.
|
2021-04-21 10:32:15 +02:00
|
|
|
* Copyright © 2019-2021 tastytea <tastytea@tastytea.de>
|
2019-04-20 05:15:30 +02:00
|
|
|
*
|
|
|
|
* 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"
|
2021-04-21 10:32:15 +02:00
|
|
|
|
2019-08-12 19:52:31 +02:00
|
|
|
#include <json/json.h>
|
2021-04-21 10:32:15 +02:00
|
|
|
|
|
|
|
#include <iostream>
|
2020-10-27 12:05:50 +01:00
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
namespace gitea2rss
|
|
|
|
{
|
2019-04-20 05:15:30 +02:00
|
|
|
|
|
|
|
using std::cerr;
|
2020-10-27 12:05:50 +01:00
|
|
|
using std::cout;
|
2019-04-20 10:00:15 +02:00
|
|
|
using std::endl;
|
2019-04-20 05:15:30 +02:00
|
|
|
using std::stringstream;
|
|
|
|
|
2019-04-20 07:43:23 +02:00
|
|
|
uint8_t write_tags(const string &url)
|
2019-04-20 05:15:30 +02:00
|
|
|
{
|
|
|
|
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 + "/git/refs"));
|
2019-04-20 06:08:17 +02:00
|
|
|
|
2019-04-20 10:00:15 +02:00
|
|
|
if (cgi)
|
|
|
|
{
|
|
|
|
cout << endl;
|
|
|
|
}
|
|
|
|
|
2019-04-20 05:15:30 +02:00
|
|
|
if (data.str().empty())
|
|
|
|
{
|
2019-04-20 07:43:23 +02:00
|
|
|
cerr << "Error: Could not download tags.\n";
|
2019-04-20 05:15:30 +02:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2021-04-21 10:32:15 +02:00
|
|
|
write_preamble(url, "tags");
|
2019-04-20 10:00:15 +02:00
|
|
|
|
2019-04-20 05:15:30 +02:00
|
|
|
Json::Value json;
|
|
|
|
data >> json;
|
|
|
|
|
2019-04-20 07:43:23 +02:00
|
|
|
for (const Json::Value &ref : json)
|
2019-04-20 05:15:30 +02:00
|
|
|
{
|
2019-04-20 07:43:23 +02:00
|
|
|
if (ref["object"]["type"].asString() != "tag")
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const string name = ref["ref"].asString().substr(10);
|
|
|
|
const string sha = ref["object"]["sha"].asString();
|
|
|
|
|
2019-04-20 05:15:30 +02:00
|
|
|
cout << " <item>\n";
|
2019-04-20 07:43:23 +02:00
|
|
|
write_line(6, "title", get_project(url) + ": " + name);
|
2020-10-27 12:05:50 +01:00
|
|
|
write_line(6, "link", baseurl + "/" += repo + "/src/tag/" += name);
|
2019-04-20 05:15:30 +02:00
|
|
|
write_line(6, "guid isPermaLink=\"false\"",
|
2019-04-20 07:43:23 +02:00
|
|
|
get_domain(url) + " tag " + sha);
|
2019-04-20 05:15:30 +02:00
|
|
|
write_line(6, "description",
|
2020-10-27 12:05:50 +01:00
|
|
|
"\n <![CDATA[<p><strong>" + name
|
|
|
|
+ "</strong> "
|
|
|
|
"on commit "
|
|
|
|
+ sha
|
|
|
|
+ "</p>\n"
|
|
|
|
" <p><a href=\""
|
|
|
|
+ baseurl + "/" + repo + "/archive/" + name + ".tar.gz"
|
|
|
|
+ "\">Download tarball</a></p>]]>\n ");
|
2019-04-20 08:17:01 +02:00
|
|
|
|
2019-04-20 05:15:30 +02:00
|
|
|
cout << " </item>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-10-27 12:05:50 +01:00
|
|
|
|
|
|
|
} // namespace gitea2rss
|