This commit is contained in:
parent
f3825dbe50
commit
888a7e6ae8
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required (VERSION 3.2)
|
||||
project(gitea2rss
|
||||
VERSION 0.3.1
|
||||
VERSION 0.4.0
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
= gitea2rss
|
||||
|
||||
*gitea2rss* Generates RSS feeds from https://gitea.io[Gitea] releases.
|
||||
*gitea2rss* Generates RSS feeds from https://gitea.io[Gitea] releases or tags.
|
||||
|
||||
https://rss.schlomp.space/?repo=tastytea/gitea2rss[Subscribe to gitea2rss releases].
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
:doctype: manpage
|
||||
:Author: tastytea
|
||||
:Email: tastytea@tastytea.de
|
||||
:Date: 2019-04-18
|
||||
:Date: 2019-04-20
|
||||
:Revision: 0.0.0
|
||||
:man source: gitea2rss
|
||||
:man version: {revision}
|
||||
|
@ -14,19 +14,22 @@ gitea2rss - Generates RSS feeds from Gitea releases.
|
|||
|
||||
== SYNOPSIS
|
||||
|
||||
*gitea2rss* _URL of Gitea project_
|
||||
*gitea2rss* _URL of Gitea project_ [_releases_|_tags_]
|
||||
|
||||
== DESCRIPTION
|
||||
|
||||
gitea2rss fetches the releases from the Gitea API, converts the data into an RSS
|
||||
feed and dumps it to stdout. You can use it as a CGI script to generate the
|
||||
feeds dynamically or simply use cron to generate the feeds at fixed intervals.
|
||||
gitea2rss fetches the releases (default) or tags from the Gitea API,
|
||||
converts the data into an RSS feed and dumps it to stdout. You can use it as a
|
||||
CGI script to generate the feeds dynamically or simply use cron to generate the
|
||||
feeds at fixed intervals.
|
||||
|
||||
If you want to use gitea2rss as a CGI script, you have to set
|
||||
*GITEA2RSS_BASEURL* to the basis URL of your instance, without the trailing
|
||||
slash. For example: _https://git.example.com_. The *QUERY_STRING* must contain
|
||||
_repo=user/project_. The feed-URL for alice's project, cooltool, would be:
|
||||
`https://rss.example.com/?repo=alice/cooltool`.
|
||||
`https://rss.example.com/?repo=alice/cooltool`. You can select the type of the
|
||||
feed by appending `&type=` at the end of the URL. For example:
|
||||
`https://rss.example.com/?repo=alice/cooltool&type=tags`.
|
||||
|
||||
The generated RSS feed contains the *channel* elements _title_, _link_,
|
||||
_description_, _generator_ and _lastBuildDate_ and the *item* elements _title_,
|
||||
|
@ -46,6 +49,9 @@ this in it:
|
|||
<link rel="alternate" type="application/rss+xml"
|
||||
title="Releases of {{.Repository.Name}}"
|
||||
href="https://rss.example.com/?repo={{.Repository.Owner.Name}}/{{.Repository.Name}}"/>
|
||||
<link rel="alternate" type="application/rss+xml"
|
||||
title="Tags of {{.Repository.Name}}"
|
||||
href="https://rss.example.com/?repo={{.Repository.Owner.Name}}/{{.Repository.Name}}&type=tags"/>
|
||||
{{end}}
|
||||
----
|
||||
|
||||
|
@ -56,7 +62,7 @@ variables. See *curl*(1), section _ENVIRONMENT_.
|
|||
|
||||
== EXAMPLES
|
||||
|
||||
`gitea2rss https://git.example.com/user/project > repo.rss`
|
||||
`gitea2rss https://git.example.com/user/project tags > repo.rss`
|
||||
|
||||
`https_proxy="socks4a://user:pass@localhost:9050/" gitea2rss
|
||||
https://git.example.com/user/project`
|
||||
|
|
|
@ -41,7 +41,10 @@ const string strtime(const string &time);
|
|||
void write_line(const uint8_t spaces, const string &tag, const string &value);
|
||||
|
||||
//! Write releases.
|
||||
uint8_t releases(const string &url);
|
||||
uint8_t write_releases(const string &url);
|
||||
|
||||
//! Write tags.
|
||||
uint8_t write_tags(const string &url);
|
||||
|
||||
//! @brief Get the base URL, without trailing slash.
|
||||
const string get_baseurl(const string &url);
|
||||
|
|
24
src/main.cpp
24
src/main.cpp
|
@ -89,20 +89,23 @@ int main(int argc, char *argv[])
|
|||
cout << endl;
|
||||
}
|
||||
|
||||
const string now = strtime(system_clock::now());
|
||||
cout << "<rss version=\"2.0\">\n"
|
||||
" <channel>\n";
|
||||
|
||||
cout <<
|
||||
"<rss version=\"2.0\">\n"
|
||||
" <channel>\n"
|
||||
" <title>" << get_project(url) << " " << type << "</title>\n"
|
||||
" <link>" << url << "</link>\n"
|
||||
" <generator>gitea2rss " << global::version << "</generator>\n"
|
||||
" <lastBuildDate>" << now << "</lastBuildDate>\n";
|
||||
write_line(4, "title", get_project(url) + " " + type);
|
||||
write_line(4, "link", url);
|
||||
write_line(4, "description", "List of " + type + " of " + get_repo(url));
|
||||
write_line(4, "generator", string("gitea2rss ") + global::version);
|
||||
write_line(4, "lastBuildDate", strtime(system_clock::now()));
|
||||
|
||||
uint8_t ret = 0;
|
||||
if (type == "releases")
|
||||
{
|
||||
ret = releases(url);
|
||||
ret = write_releases(url);
|
||||
}
|
||||
else if (type == "tags")
|
||||
{
|
||||
ret = write_tags(url);
|
||||
}
|
||||
|
||||
if (ret != 0)
|
||||
|
@ -110,8 +113,7 @@ int main(int argc, char *argv[])
|
|||
return ret;
|
||||
}
|
||||
|
||||
cout <<
|
||||
" </channel>\n"
|
||||
cout << " </channel>\n"
|
||||
"</rss>\n";
|
||||
|
||||
curlpp::terminate();
|
||||
|
|
|
@ -23,7 +23,7 @@ using std::cout;
|
|||
using std::cerr;
|
||||
using std::stringstream;
|
||||
|
||||
uint8_t releases(const string &url)
|
||||
uint8_t write_releases(const string &url)
|
||||
{
|
||||
const string baseurl = get_baseurl(url);
|
||||
const string repo = get_repo(url);
|
||||
|
@ -43,8 +43,10 @@ uint8_t releases(const string &url)
|
|||
{
|
||||
const bool prerelease = release["prerelease"].asBool();
|
||||
const string type = (prerelease ? "Pre-Release" : "Stable");
|
||||
|
||||
cout << " <item>\n";
|
||||
write_line(6, "title", get_project(url) + ": " + release["name"].asString());
|
||||
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());
|
||||
|
@ -53,7 +55,7 @@ uint8_t releases(const string &url)
|
|||
"\n <![CDATA[<p><strong>" + type + "</strong></p>\n"
|
||||
"<pre>" + release["body"].asString() + "</pre>\n"
|
||||
" <p><a href=\"" + release["tarball_url"].asString()
|
||||
+ "\">Download tarball</a></p>" + "]]>\n ");
|
||||
+ "\">Download tarball</a></p>]]>\n ");
|
||||
cout << " </item>\n";
|
||||
}
|
||||
|
64
src/tags.cpp
Normal file
64
src/tags.cpp
Normal file
|
@ -0,0 +1,64 @@
|
|||
/* This file is part of gitea2rss.
|
||||
* Copyright © 2019 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/>.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <jsoncpp/json/json.h>
|
||||
#include "gitea2rss.hpp"
|
||||
|
||||
using std::cout;
|
||||
using std::cerr;
|
||||
using std::stringstream;
|
||||
|
||||
uint8_t write_tags(const string &url)
|
||||
{
|
||||
const string baseurl = get_baseurl(url);
|
||||
const string repo = get_repo(url);
|
||||
stringstream data(get_http(baseurl + "/api/v1/repos/"
|
||||
+ repo + "/git/refs"));
|
||||
|
||||
if (data.str().empty())
|
||||
{
|
||||
cerr << "Error: Could not download tags.\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
Json::Value json;
|
||||
data >> json;
|
||||
|
||||
for (const Json::Value &ref : json)
|
||||
{
|
||||
if (ref["object"]["type"].asString() != "tag")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
const string name = ref["ref"].asString().substr(10);
|
||||
const string sha = ref["object"]["sha"].asString();
|
||||
|
||||
cout << " <item>\n";
|
||||
write_line(6, "title", get_project(url) + ": " + name);
|
||||
write_line(6, "link", baseurl + "/" + repo + "/src/tag/" + name);
|
||||
write_line(6, "guid isPermaLink=\"false\"",
|
||||
get_domain(url) + " tag " + sha);
|
||||
write_line(6, "description",
|
||||
"\n <![CDATA[<p><strong>" + name + "</strong> "
|
||||
"with checksum " + sha + "</p>]]>\n ");
|
||||
cout << " </item>\n";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user