Compare commits
46 Commits
Author | SHA1 | Date |
---|---|---|
tastytea | f57f3b578d | |
tastytea | f5dc5e2359 | |
tastytea | e1c20bd1bd | |
tastytea | 9caeab9b91 | |
tastytea | aabd458e62 | |
tastytea | a1850db226 | |
tastytea | 7438f878c2 | |
tastytea | 6a4e15df81 | |
tastytea | 82261aadfb | |
tastytea | 23031b0dc9 | |
tastytea | f869ed9df2 | |
tastytea | 1e52e8edac | |
tastytea | 5cbbca2111 | |
tastytea | 6b08adce38 | |
tastytea | 98b6572b14 | |
tastytea | f3b97151f1 | |
tastytea | a83a11d8e2 | |
tastytea | c3fb4850ae | |
tastytea | 6dc9c1a740 | |
tastytea | 9c99aafe87 | |
tastytea | 089534e07d | |
tastytea | 0bcad56590 | |
tastytea | c0eb7494e1 | |
tastytea | fa225ff8e7 | |
tastytea | 82bbd03a2c | |
tastytea | 4a40cac16b | |
tastytea | 257d6ff09b | |
tastytea | 15ee493084 | |
tastytea | 8574da33a7 | |
tastytea | 7839cd3658 | |
tastytea | 0a1b9cfcaf | |
tastytea | d9d029b952 | |
tastytea | 51f3c0b4df | |
tastytea | aec946c50f | |
tastytea | 6ef00b689a | |
tastytea | 953c1cf3e7 | |
tastytea | 18a0edb30a | |
tastytea | d25fbccc9f | |
tastytea | 25cce227c1 | |
tastytea | 8cee77f743 | |
tastytea | c67875b75c | |
tastytea | 5906db11da | |
tastytea | 095645ba6e | |
tastytea | d9d28dd707 | |
tastytea | c19f5681a2 | |
tastytea | c7e36a7297 |
|
@ -0,0 +1,131 @@
|
|||
# -*- mode: yaml -*-
|
||||
# Written for clang-format 10.
|
||||
# https://releases.llvm.org/10.0.0/tools/clang/docs/ClangFormatStyleOptions.html
|
||||
---
|
||||
DisableFormat: false
|
||||
Language: Cpp
|
||||
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: false
|
||||
# AlignConsecutiveBitFields: false # clang-format 11
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignConsecutiveMacros: false
|
||||
AlignEscapedNewlines: DontAlign
|
||||
AlignOperands: true # clang-format 11: Align
|
||||
AlignTrailingComments: true
|
||||
AllowAllArgumentsOnNextLine: false
|
||||
AllowAllConstructorInitializersOnNextLine: false
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortBlocksOnASingleLine: Empty
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
# AllowShortEnumsOnASingleLine: false # clang-format 11
|
||||
AllowShortFunctionsOnASingleLine: Empty
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLambdasOnASingleLine: Inline
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BraceWrapping: # If BreakBeforeBraces is set to Custom.
|
||||
AfterCaseLabel: true
|
||||
AfterClass: true
|
||||
AfterControlStatement: Always
|
||||
AfterEnum: true
|
||||
AfterFunction: true
|
||||
AfterNamespace: true
|
||||
AfterStruct: true
|
||||
AfterUnion: true
|
||||
AfterExternBlock: true
|
||||
BeforeCatch: true
|
||||
BeforeElse: true
|
||||
# BeforeLambdaBody: true # clang-format 11
|
||||
# BeforeWhile: true # clang-format 11
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: false
|
||||
SplitEmptyRecord: false
|
||||
SplitEmptyNamespace: false
|
||||
BreakBeforeBinaryOperators: NonAssignment
|
||||
BreakBeforeBraces: Custom
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
BreakInheritanceList: BeforeComma
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 80
|
||||
# CommentPragmas: 'regex'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DeriveLineEnding: true
|
||||
DerivePointerAlignment: false
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
- FOREACH
|
||||
- RANGES_FOR
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IncludeBlocks: Regroup
|
||||
IncludeCategories: # stdlib headers into own group.
|
||||
- Regex: '^[^\.]+$'
|
||||
Priority: 4
|
||||
# IndentCaseBlocks: false # clang-format 11
|
||||
IndentCaseLabels: false
|
||||
# IndentExternBlock: NoIndent # clang-format 11
|
||||
IndentGotoLabels: false
|
||||
IndentPPDirectives: AfterHash
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: false
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
# MacroBlockBegin: 'string'
|
||||
# MacroBlockEnd: 'string'
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
# NamespaceMacros: 'string'
|
||||
PenaltyBreakAssignment: 250
|
||||
PenaltyBreakBeforeFirstCallParameter: 300
|
||||
# PenaltyBreakComment: 300
|
||||
# PenaltyBreakFirstLessLess: 120
|
||||
# PenaltyBreakString: 1000
|
||||
# PenaltyBreakTemplateDeclaration: 10
|
||||
# PenaltyExcessCharacter: 1000000
|
||||
# PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerAlignment: Right
|
||||
# RawStringFormats: # <YAML>
|
||||
ReflowComments: true
|
||||
SortIncludes: true
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: false
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceBeforeSquareBrackets: false
|
||||
SpaceInEmptyBlock: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInConditionalStatement: false
|
||||
SpacesInContainerLiterals: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Auto
|
||||
# StatementMacros:
|
||||
# - Q_UNUSED
|
||||
# - QT_REQUIRE_VERSION
|
||||
TabWidth: 4
|
||||
# TypenameMacros:
|
||||
# - STACK_OF
|
||||
# - LIST
|
||||
UseCRLF: false
|
||||
UseTab: Never
|
||||
# WhitespaceSensitiveMacros: ['string', 'string'] # clang-format 11
|
||||
...
|
92
.drone.yml
92
.drone.yml
|
@ -1,3 +1,4 @@
|
|||
# -*- fill-column: 1000 -*-
|
||||
kind: pipeline
|
||||
name: on_push
|
||||
|
||||
|
@ -12,92 +13,29 @@ trigger:
|
|||
- tag
|
||||
|
||||
steps:
|
||||
- name: gcc5
|
||||
image: debian:stretch-slim
|
||||
pull: always
|
||||
environment:
|
||||
CXX: g++-5
|
||||
CXXFLAGS: -pipe -O2
|
||||
LANG: en_US.utf-8
|
||||
commands:
|
||||
- rm /etc/apt/apt.conf.d/docker-clean
|
||||
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
|
||||
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
|
||||
- echo "deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial main" >> /etc/apt/sources.list.d/ubuntu-toolchain-r.list
|
||||
- apt-get update -q
|
||||
- apt-get install -qy gnupg
|
||||
- gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 0x60c317803a41ba51845e371a1e9377a2ba9ef27f
|
||||
- gpg --armor --export 0x60c317803a41ba51845e371a1e9377a2ba9ef27f | apt-key add -
|
||||
- apt-get update -q
|
||||
- apt-get install -qy -t xenial g++-5
|
||||
- apt-get install -qy cmake libpoco-dev libjsoncpp-dev asciidoc
|
||||
- rm -rf build && mkdir -p build && cd build
|
||||
- cmake ..
|
||||
- make VERBOSE=1
|
||||
volumes:
|
||||
- name: debian-package-cache
|
||||
path: /var/cache/apt/archives
|
||||
|
||||
- name: gcc9
|
||||
image: debian:stretch-slim
|
||||
pull: always
|
||||
environment:
|
||||
CXX: g++-9
|
||||
CXXFLAGS: -pipe -O2
|
||||
LANG: en_US.utf-8
|
||||
commands:
|
||||
- rm /etc/apt/apt.conf.d/docker-clean
|
||||
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
|
||||
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
|
||||
- echo "deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial main" >> /etc/apt/sources.list.d/ubuntu-toolchain-r.list
|
||||
- apt-get update -q
|
||||
- apt-get install -qy gnupg
|
||||
- gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 0x60c317803a41ba51845e371a1e9377a2ba9ef27f
|
||||
- gpg --armor --export 0x60c317803a41ba51845e371a1e9377a2ba9ef27f | apt-key add -
|
||||
- apt-get update -q
|
||||
- apt-get install -qy -t xenial g++-9
|
||||
- apt-get install -qy cmake libpoco-dev libjsoncpp-dev asciidoc
|
||||
- rm -rf build && mkdir -p build && cd build
|
||||
- cmake ..
|
||||
- make VERBOSE=1
|
||||
volumes:
|
||||
- name: debian-package-cache
|
||||
path: /var/cache/apt/archives
|
||||
|
||||
- name: clang3
|
||||
image: debian:stretch-slim
|
||||
pull: always
|
||||
environment:
|
||||
CXX: clang++
|
||||
CXXFLAGS: -pipe -O2
|
||||
LANG: en_US.utf-8
|
||||
commands:
|
||||
- rm /etc/apt/apt.conf.d/docker-clean
|
||||
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
|
||||
- apt-get update -q
|
||||
- apt-get install -qy clang cmake libpoco-dev libjsoncpp-dev asciidoc
|
||||
- rm -rf build && mkdir -p build && cd build
|
||||
- cmake ..
|
||||
- make VERBOSE=1
|
||||
volumes:
|
||||
- name: debian-package-cache
|
||||
path: /var/cache/apt/archives
|
||||
|
||||
- name: clang7
|
||||
- name: GCC 8 / clang 7
|
||||
image: debian:buster-slim
|
||||
pull: always
|
||||
environment:
|
||||
CXX: clang++
|
||||
CXX: g++-8
|
||||
CXXFLAGS: -pipe -O2
|
||||
LANG: en_US.utf-8
|
||||
DEBIAN_FRONTEND: noninteractive
|
||||
commands:
|
||||
- rm /etc/apt/apt.conf.d/docker-clean
|
||||
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
|
||||
- apt-get update -q
|
||||
- apt-get install -qy clang cmake libpoco-dev libjsoncpp-dev asciidoc
|
||||
- apt-get install -qq build-essential clang cmake pkg-config catch libcurl4-openssl-dev libjsoncpp-dev asciidoc
|
||||
- rm -rf build && mkdir -p build && cd build
|
||||
- cmake ..
|
||||
- make VERBOSE=1
|
||||
- cmake -DWITH_TESTS=yes ..
|
||||
- cmake --build .
|
||||
- cd tests && ctest -V
|
||||
- cd ../../
|
||||
- rm -rf build && mkdir -p build && cd build
|
||||
- CXX="clang++" cmake -DWITH_TESTS=yes ..
|
||||
- cmake --build .
|
||||
- cd tests && ctest -V
|
||||
- make install
|
||||
volumes:
|
||||
- name: debian-package-cache
|
||||
path: /var/cache/apt/archives
|
||||
|
@ -106,7 +44,7 @@ steps:
|
|||
image: drillster/drone-email
|
||||
pull: always
|
||||
settings:
|
||||
host: cryptoparty-celle.de
|
||||
host: mail.tzend.de
|
||||
from: drone@tzend.de
|
||||
username:
|
||||
from_secret: email_username
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
# Configuration file for EditorConfig.
|
||||
# More information is available under <https://editorconfig.org/>.
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
max_line_length = 80
|
||||
|
||||
[*.?pp]
|
||||
indent_size = 4
|
||||
tab_width = 4
|
||||
|
||||
[{CMakeLists.txt,*.cmake}]
|
||||
indent_size = 2
|
||||
tab_width = 2
|
|
@ -1,20 +1,11 @@
|
|||
# Support version 3.2 and above, but use policy settings up to 3.14.
|
||||
cmake_minimum_required(VERSION 3.2...3.14)
|
||||
# Ranges are supported from 3.12, set policy to current for < 3.12.
|
||||
if(${CMAKE_VERSION} VERSION_LESS 3.12)
|
||||
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
|
||||
endif()
|
||||
# IMPORTED target CURL::libcurl needs 3.12.
|
||||
cmake_minimum_required(VERSION 3.12...3.18)
|
||||
|
||||
project(gitea2rss
|
||||
VERSION 0.5.1
|
||||
VERSION 0.7.0
|
||||
DESCRIPTION "Generates RSS feeds from Gitea releases or tags."
|
||||
LANGUAGES CXX)
|
||||
|
||||
# DESCRIPTION was introduced in version 3.9.
|
||||
if(NOT (${CMAKE_VERSION} VERSION_LESS 3.9))
|
||||
set(PROJECT_DESCRIPTION
|
||||
"Generates RSS feeds from Gitea releases or tags.")
|
||||
endif()
|
||||
|
||||
option(WITH_MAN "Compile and install manpage." YES)
|
||||
option(WITH_TESTS "Compile tests." NO)
|
||||
|
||||
|
@ -22,28 +13,11 @@ set(CMAKE_CXX_STANDARD 14)
|
|||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
set(DEBUG_CXXFLAGS
|
||||
"-Wall"
|
||||
"-Wextra"
|
||||
"-Wpedantic"
|
||||
"-ftrapv"
|
||||
"-fsanitize=undefined"
|
||||
"-g"
|
||||
"-Og"
|
||||
"-fno-omit-frame-pointer")
|
||||
set(DEBUG_LDFLAGS
|
||||
"-fsanitize=undefined")
|
||||
add_compile_options("$<$<CONFIG:Debug>:${DEBUG_CXXFLAGS}>")
|
||||
# add_link_options was introduced in version 3.13.
|
||||
if(${CMAKE_VERSION} VERSION_LESS 3.13)
|
||||
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${DEBUG_LDFLAGS}")
|
||||
else()
|
||||
add_link_options("$<$<CONFIG:Debug>:${DEBUG_LDFLAGS}>")
|
||||
endif()
|
||||
include(cmake/debug_flags.cmake)
|
||||
|
||||
find_package(jsoncpp CONFIG REQUIRED)
|
||||
# Some distributions do not contain Poco*Config.cmake recipes.
|
||||
find_package(Poco COMPONENTS Foundation Net NetSSL CONFIG)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(jsoncpp REQUIRED IMPORTED_TARGET jsoncpp)
|
||||
find_package(CURL 7.56 REQUIRED)
|
||||
|
||||
add_subdirectory(src)
|
||||
|
||||
|
|
46
README.adoc
46
README.adoc
|
@ -1,26 +1,28 @@
|
|||
= gitea2rss
|
||||
|
||||
*gitea2rss* Generates RSS feeds from https://gitea.io[Gitea] releases or tags.
|
||||
*gitea2rss* Generates RSS feeds from https://gitea.io[Gitea] releases, tags and
|
||||
commits.
|
||||
|
||||
https://rss.schlomp.space/?repo=tastytea/gitea2rss[Subscribe to gitea2rss releases].
|
||||
|
||||
== Usage
|
||||
|
||||
See https://schlomp.space/tastytea/gitea2rss/src/branch/master/man/gitea2rss.1.adoc[manpage].
|
||||
For an example nginx configuration file, see https://schlomp.space/tastytea/gitea2rss/src/branch/master/doc/nginx-example.conf[nginx-example.conf].
|
||||
|
||||
== Install
|
||||
|
||||
=== Gentoo
|
||||
[alt="Packaging status" link=https://repology.org/project/gitea2rss/versions]
|
||||
image::https://repology.org/badge/vertical-allrepos/gitea2rss.svg[]
|
||||
|
||||
Add my https://schlomp.space/tastytea/overlay[repository] and install it from
|
||||
there.
|
||||
=== Gentoo
|
||||
|
||||
[source,shell]
|
||||
----
|
||||
eselect repository enable tastytea
|
||||
echo "www-misc/gitea2rss ~amd64" >> /etc/portage/package.accept_keywords/gitea2rss
|
||||
emaint sync -r tastytea
|
||||
emerge -a dev-util/gitea2rss
|
||||
eselect repository enable guru
|
||||
echo 'www-misc/gitea2rss' >> /etc/portage/package.accept_keywords/gitea2rss
|
||||
emaint sync -r guru
|
||||
emerge -a www-misc/gitea2rss
|
||||
----
|
||||
|
||||
=== From source
|
||||
|
@ -28,10 +30,10 @@ emerge -a dev-util/gitea2rss
|
|||
==== Dependencies
|
||||
|
||||
* Tested OS: Linux
|
||||
* C++ compiler (tested: https://gcc.gnu.org/[gcc] 5/8/9,
|
||||
https://llvm.org/[clang] 3/7)
|
||||
* https://cmake.org/[cmake] (at least: 3.6)
|
||||
* https://pocoproject.org/[POCO] (tested: 1.9 / 1.7)
|
||||
* C++ compiler (tested: https://gcc.gnu.org/[gcc] 8/9/10,
|
||||
https://llvm.org/[clang] 7)
|
||||
* https://cmake.org/[cmake] (at least: 3.12)
|
||||
* https://curl.haxx.se/libcurl/[libcurl] (at least: 7.56)
|
||||
* https://github.com/open-source-parsers/jsoncpp[jsoncpp] (tested: 1.8)
|
||||
* Optional:
|
||||
** Manpage: http://asciidoc.org/[asciidoc] (tested: 8.6)
|
||||
|
@ -40,7 +42,7 @@ emerge -a dev-util/gitea2rss
|
|||
|
||||
[source,shell]
|
||||
----
|
||||
apt-get install build-essential cmake libpoco-dev libjsoncpp-dev asciidoc
|
||||
apt install build-essential cmake libcurl4-openssl-dev libjsoncpp-dev asciidoc
|
||||
----
|
||||
|
||||
==== Get sourcecode
|
||||
|
@ -61,8 +63,7 @@ git clone https://schlomp.space/tastytea/gitea2rss.git
|
|||
|
||||
[source,shell]
|
||||
----
|
||||
mkdir build
|
||||
cd build/
|
||||
mkdir build && cd build
|
||||
cmake ..
|
||||
cmake --build .
|
||||
----
|
||||
|
@ -70,16 +71,7 @@ cmake --build .
|
|||
.cmake options:
|
||||
* `-DCMAKE_BUILD_TYPE=Debug` for a debug build.
|
||||
* `-DWITH_MAN=NO` to not compile the manpage.
|
||||
* `WITH_TESTS=YES` to compile the tests.
|
||||
* `-DWITH_TESTS=YES` to compile the tests.
|
||||
|
||||
You can run the tests with `ctest` inside the build directory. Install with
|
||||
`make install`.
|
||||
|
||||
== Copyright
|
||||
|
||||
----
|
||||
Copyright © 2019 tastytea <tastytea@tastytea.de>.
|
||||
License GPLv3: GNU GPL version 3 <https://www.gnu.org/licenses/gpl-3.0.html>.
|
||||
This program comes with ABSOLUTELY NO WARRANTY. This is free software,
|
||||
and you are welcome to redistribute it under certain conditions.
|
||||
----
|
||||
You can run the tests with `ctest` inside `build/tests`. Install with `make
|
||||
install`.
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
# Set compiler flags for Debug builds.
|
||||
# Only has an effect on GCC/Clang >= 5.0.
|
||||
|
||||
set(tmp_CXXFLAGS "")
|
||||
set(tmp_LDFLAGS "")
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang"
|
||||
AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5")
|
||||
list(APPEND tmp_CXXFLAGS
|
||||
"-Wall"
|
||||
"-Wextra"
|
||||
"-Wpedantic"
|
||||
"-Wuninitialized"
|
||||
"-Wshadow"
|
||||
"-Wnon-virtual-dtor"
|
||||
"-Wconversion"
|
||||
"-Wsign-conversion"
|
||||
"-Wold-style-cast"
|
||||
"-Wzero-as-null-pointer-constant"
|
||||
"-Wmissing-declarations"
|
||||
"-Wcast-align"
|
||||
"-Wunused"
|
||||
"-Woverloaded-virtual"
|
||||
"-Wdouble-promotion"
|
||||
"-Wformat=2"
|
||||
"-ftrapv"
|
||||
"-fsanitize=undefined"
|
||||
"-Og"
|
||||
"-fno-omit-frame-pointer")
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
list(APPEND tmp_CXXFLAGS
|
||||
"-Wlogical-op"
|
||||
"-Wuseless-cast")
|
||||
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6")
|
||||
list(APPEND tmp_CXXFLAGS
|
||||
"-Wmisleading-indentation"
|
||||
"-Wduplicated-cond"
|
||||
"-Wnull-dereference")
|
||||
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "7")
|
||||
list(APPEND tmp_CXXFLAGS
|
||||
"-Wduplicated-branches")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
add_compile_options("$<$<CONFIG:Debug>:${tmp_CXXFLAGS}>")
|
||||
|
||||
list(APPEND tmp_LDFLAGS
|
||||
"-fsanitize=undefined")
|
||||
# add_link_options was introduced in version 3.13.
|
||||
if(${CMAKE_VERSION} VERSION_LESS 3.13)
|
||||
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${tmp_LDFLAGS}")
|
||||
else()
|
||||
add_link_options("$<$<CONFIG:Debug>:${tmp_LDFLAGS}>")
|
||||
endif()
|
||||
else()
|
||||
message(STATUS
|
||||
"No additional compiler flags were set, "
|
||||
"because your compiler was not anticipated.")
|
||||
endif()
|
||||
|
||||
unset(tmp_CXXFLAGS)
|
||||
unset(tmp_LDFLAGS)
|
|
@ -1,25 +0,0 @@
|
|||
# RSS feeds will be available at <https://rss.example.com/?repo=user/project>.
|
||||
|
||||
server {
|
||||
listen 443 ssl;
|
||||
listen [::]:443 ssl;
|
||||
server_name rss.example.com;
|
||||
|
||||
#access_log /var/log/nginx/rss.access_log main;
|
||||
error_log /var/log/nginx/rss.error_log warn;
|
||||
|
||||
ssl_certificate /var/lib/dehydrated/certs/rss.example.com/fullchain.pem;
|
||||
ssl_certificate_key /var/lib/dehydrated/certs/rss.example.com/privkey.pem;
|
||||
|
||||
# Tell clients to cache for 1 hour.
|
||||
expires 1h;
|
||||
|
||||
location / {
|
||||
include /etc/nginx/fastcgi_params;
|
||||
# You may need to change fastcgi_pass.
|
||||
fastcgi_pass unix:/var/run/cgi-fcgiwrap.socket-1;
|
||||
fastcgi_param SCRIPT_FILENAME /usr/bin/gitea2rss;
|
||||
# Base URL of your Gitea instance.
|
||||
fastcgi_param GITEA2RSS_BASEURL "https://git.example.com";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
# Use 100 MiB cache with a 1 MiB memory zone (enough for ~8,000 keys).
|
||||
# Delete data that has not been accessed for 10 minutes.
|
||||
fastcgi_cache_path /var/cache/nginx/gitea2rss levels=1:2 keys_zone=gitea2rss:1m
|
||||
max_size=100m inactive=10m use_temp_path=off;
|
||||
fastcgi_cache_key "$scheme$request_method$host$request_uri";
|
||||
add_header X-Cache $upstream_cache_status;
|
||||
|
||||
server {
|
||||
listen 443 ssl;
|
||||
listen [::]:443 ssl;
|
||||
server_name rss.example.com;
|
||||
|
||||
error_log /var/log/nginx/rss.example.com_log warn;
|
||||
|
||||
ssl_certificate /var/lib/dehydrated/certs/rss.example.com/fullchain.pem;
|
||||
ssl_certificate_key /var/lib/dehydrated/certs/rss.example.com/privkey.pem;
|
||||
|
||||
# Tell clients to cache for 30 minutes.
|
||||
expires 30m;
|
||||
|
||||
location / {
|
||||
include /etc/nginx/fastcgi_params;
|
||||
# You may need to change fastcgi_pass.
|
||||
fastcgi_pass unix:/var/run/cgi-fcgiwrap.socket-1;
|
||||
fastcgi_param SCRIPT_FILENAME /usr/bin/gitea2rss;
|
||||
|
||||
# Base URL of your Gitea instance.
|
||||
fastcgi_param GITEA2RSS_BASEURL "https://git.example.com";
|
||||
|
||||
fastcgi_cache gitea2rss;
|
||||
fastcgi_cache_valid 200 10m; # Cache answers for up to 10 minutes.
|
||||
fastcgi_cache_lock on; # Relay only one identical request at a time.
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
:doctype: manpage
|
||||
:Author: tastytea
|
||||
:Email: tastytea@tastytea.de
|
||||
:Date: 2019-08-09
|
||||
:Date: 2021-04-25
|
||||
:Revision: 0.0.0
|
||||
:man source: gitea2rss
|
||||
:man version: {revision}
|
||||
|
@ -14,7 +14,7 @@ gitea2rss - Generates RSS feeds from Gitea releases or tags.
|
|||
|
||||
== SYNOPSIS
|
||||
|
||||
*gitea2rss* _URL of Gitea project_ [_releases_|_tags_]
|
||||
*gitea2rss* _URL of Gitea project_ [_releases_|_tags_|_commits_]
|
||||
|
||||
== DESCRIPTION
|
||||
|
||||
|
@ -27,15 +27,13 @@ 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`. You can select the type of the
|
||||
_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`.
|
||||
_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_,
|
||||
_link_, _guid_, _pubDate_ and _description_. Since Gitea has no individual pages
|
||||
for each release, _link_ elements in *item* are set to the overview page for
|
||||
releases.
|
||||
_link_, _guid_, _pubDate_ and _description_.
|
||||
|
||||
== GITEA INTEGRATION
|
||||
|
||||
|
@ -52,19 +50,22 @@ this in it:
|
|||
<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"/>
|
||||
<link rel="alternate" type="application/rss+xml"
|
||||
title="Commits of {{.Repository.Name}}"
|
||||
href="https://rss.example.com/?repo={{.Repository.Owner.Name}}/{{.Repository.Name}}&type=commits"/>
|
||||
{{end}}
|
||||
----
|
||||
|
||||
== PROXY SERVERS
|
||||
|
||||
*gitea2rss* supports HTTP proxies set via the environment variable
|
||||
_http_proxy_. Accepted formats are _http://host:port/_ or _host:port_.
|
||||
Since *gitea2rss* is built on libcurl, it respects the same proxy environment
|
||||
variables. See *curl*(1), section _ENVIRONMENT_.
|
||||
|
||||
== EXAMPLES
|
||||
|
||||
`gitea2rss https://git.example.com/user/project tags > repo.rss`
|
||||
|
||||
`http_proxy="http://localhost:8080/" gitea2rss https://git.example.com/user/project`
|
||||
`ALL_PROXY="socks4a://[::1]:9050" gitea2rss https://git.example.com/user/project`
|
||||
|
||||
=== Example RSS feed
|
||||
|
||||
|
@ -95,7 +96,7 @@ _http_proxy_. Accepted formats are _http://host:port/_ or _host:port_.
|
|||
|
||||
== SEE ALSO
|
||||
|
||||
*crontab*(1), *crontab*(5)
|
||||
*crontab*(1), *crontab*(5), *curl*(1)
|
||||
|
||||
== REPORTING BUGS
|
||||
|
||||
|
|
|
@ -11,26 +11,6 @@ target_include_directories(${PROJECT_NAME}
|
|||
PRIVATE "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>")
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE jsoncpp_lib)
|
||||
|
||||
# If no Poco*Config.cmake recipes are found, look for headers in standard dirs.
|
||||
if(PocoNetSSL_FOUND)
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE Poco::Foundation Poco::Net Poco::NetSSL)
|
||||
else()
|
||||
find_file(Poco_h NAMES "Poco/Poco.h"
|
||||
PATHS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}")
|
||||
|
||||
if("${Poco_h}" STREQUAL "Poco_h-NOTFOUND")
|
||||
message(FATAL_ERROR "Could not find POCO.")
|
||||
else()
|
||||
message(WARNING
|
||||
"Your distribution of POCO doesn't contain the *Config.cmake recipes, "
|
||||
"but the files seem to be in the standard directories. "
|
||||
"Let's hope this works.")
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE PocoFoundation PocoNet PocoNetSSL)
|
||||
endif()
|
||||
endif()
|
||||
PRIVATE PkgConfig::jsoncpp CURL::libcurl)
|
||||
|
||||
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
/* This file is part of gitea2rss.
|
||||
* Copyright © 2021 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 "gitea2rss.hpp"
|
||||
|
||||
#include <json/json.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
namespace gitea2rss
|
||||
{
|
||||
|
||||
using std::cerr;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::stringstream;
|
||||
|
||||
uint8_t write_commits(const string &url)
|
||||
{
|
||||
const string baseurl = get_baseurl(url);
|
||||
const string repo = get_repo(url);
|
||||
stringstream data(get_http(baseurl + "/api/v1/repos/" + repo + "/commits"));
|
||||
|
||||
if (cgi)
|
||||
{
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
if (data.str().empty())
|
||||
{
|
||||
cerr << "Error: Could not download commits.\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
write_preamble(url, "commits");
|
||||
|
||||
Json::Value json;
|
||||
data >> json;
|
||||
|
||||
for (const Json::Value &commit : json)
|
||||
{
|
||||
const string sha = commit["sha"].asString();
|
||||
string message = escape_some_html(
|
||||
commit["commit"]["message"].asString());
|
||||
const string title = message.substr(0, message.find('\n'));
|
||||
{
|
||||
size_t pos{};
|
||||
while ((pos = message.find('\n')) != string::npos)
|
||||
{
|
||||
message.replace(pos, 1, "<br>");
|
||||
}
|
||||
}
|
||||
const string commit_url = commit["html_url"].asString();
|
||||
const string author = commit["commit"]["author"]["email"].asString()
|
||||
+ " ("
|
||||
+ commit["commit"]["author"]["name"].asString()
|
||||
+ ")";
|
||||
const string date = strtime(
|
||||
commit["commit"]["author"]["date"].asString());
|
||||
|
||||
cout << " <item>\n";
|
||||
write_line(6, "title", get_project(url) + ": " + title);
|
||||
write_line(6, "link", commit_url);
|
||||
write_line(6, "guid isPermaLink=\"false\"",
|
||||
get_domain(url) + " commit " + sha);
|
||||
write_line(6, "author", author);
|
||||
write_line(6, "pubDate", date);
|
||||
write_line(6, "description",
|
||||
"\n <![CDATA[<p>" + message + "</p>]]>\n ");
|
||||
cout << " </item>\n";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace gitea2rss
|
|
@ -16,4 +16,9 @@
|
|||
|
||||
#include "gitea2rss.hpp"
|
||||
|
||||
namespace gitea2rss
|
||||
{
|
||||
|
||||
bool cgi = false;
|
||||
|
||||
} // namespace gitea2rss
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* This file is part of gitea2rss.
|
||||
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
||||
* Copyright © 2019-2021 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
|
||||
|
@ -17,31 +17,34 @@
|
|||
#ifndef GITEA2RSS_HPP
|
||||
#define GITEA2RSS_HPP
|
||||
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
#include <cstdint>
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
|
||||
namespace gitea2rss
|
||||
{
|
||||
|
||||
using std::string;
|
||||
using std::chrono::system_clock;
|
||||
using std::uint8_t;
|
||||
using std::chrono::system_clock;
|
||||
|
||||
extern bool cgi;
|
||||
|
||||
//! Set proxy from environment variable `http_proxy`.
|
||||
void set_proxy();
|
||||
|
||||
//! Fetch HTTP document.
|
||||
const string get_http(const string &url);
|
||||
string get_http(const string &url);
|
||||
|
||||
// CURL receive function.
|
||||
size_t writer_body(char *data, size_t size, size_t nmemb);
|
||||
|
||||
//! 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.
|
||||
const string strtime(const string &time);
|
||||
string strtime(const string &time);
|
||||
|
||||
//! Write line of XML.
|
||||
void write_line(const uint8_t spaces, const string &tag, const string &value);
|
||||
void write_line(uint8_t spaces, const string &tag, const string &value);
|
||||
|
||||
//! Write the RSS preamble and channel data.
|
||||
void write_preamble(const string &url, const string &type);
|
||||
|
@ -52,19 +55,27 @@ uint8_t write_releases(const string &url);
|
|||
//! Write tags.
|
||||
uint8_t write_tags(const string &url);
|
||||
|
||||
//! Write commits.
|
||||
uint8_t write_commits(const string &url);
|
||||
|
||||
//! @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.
|
||||
const string get_domain(const string &url);
|
||||
string get_domain(const string &url);
|
||||
|
||||
//! 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.
|
||||
const string get_project(const string &url);
|
||||
string get_project(const string &url);
|
||||
|
||||
//! Escape some characters to named HTML entities.
|
||||
const string escape_some_html(string html);
|
||||
string escape_some_html(string html);
|
||||
|
||||
#endif // GITEA2RSS_HPP
|
||||
//! Return environment variable or "" if it is not set.
|
||||
string get_env_var(const string &variable);
|
||||
|
||||
} // namespace gitea2rss
|
||||
|
||||
#endif // GITEA2RSS_HPP
|
||||
|
|
209
src/http.cpp
209
src/http.cpp
|
@ -1,5 +1,5 @@
|
|||
/* 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
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -14,145 +14,112 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <exception>
|
||||
#include <memory>
|
||||
#include <Poco/Net/HTTPClientSession.h>
|
||||
#include <Poco/Net/HTTPSClientSession.h>
|
||||
#include <Poco/Net/HTTPRequest.h>
|
||||
#include <Poco/Net/HTTPResponse.h>
|
||||
#include <Poco/StreamCopier.h>
|
||||
#include <Poco/URI.h>
|
||||
#include <Poco/Exception.h>
|
||||
#include <Poco/Environment.h>
|
||||
#include "version.hpp"
|
||||
#include "gitea2rss.hpp"
|
||||
#include "version.hpp"
|
||||
#include <curl/curl.h>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
namespace gitea2rss
|
||||
{
|
||||
|
||||
using std::cout;
|
||||
using std::cerr;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::istream;
|
||||
using std::unique_ptr;
|
||||
using std::make_unique;
|
||||
using Poco::Net::HTTPClientSession;
|
||||
using Poco::Net::HTTPSClientSession;
|
||||
using Poco::Net::HTTPRequest;
|
||||
using Poco::Net::HTTPResponse;
|
||||
using Poco::Net::HTTPMessage;
|
||||
using Poco::StreamCopier;
|
||||
using Poco::Environment;
|
||||
using std::runtime_error;
|
||||
using std::to_string;
|
||||
|
||||
void set_proxy()
|
||||
string buffer_body;
|
||||
|
||||
string get_http(const string &url)
|
||||
{
|
||||
try
|
||||
{
|
||||
HTTPClientSession::ProxyConfig proxy;
|
||||
string proxy_env = Environment::get("http_proxy");
|
||||
size_t pos;
|
||||
|
||||
// Only keep text between // and /.
|
||||
if ((pos = proxy_env.find("//")) != string::npos)
|
||||
curl_global_init(CURL_GLOBAL_ALL); // NOLINT(hicpp-signed-bitwise)
|
||||
CURL *connection{curl_easy_init()};
|
||||
if (connection == nullptr)
|
||||
{
|
||||
proxy_env = proxy_env.substr(pos + 2);
|
||||
}
|
||||
if ((pos = proxy_env.find('/')) != string::npos)
|
||||
{
|
||||
proxy_env = proxy_env.substr(0, pos);
|
||||
throw runtime_error{"Failed to initialize curl."};
|
||||
}
|
||||
|
||||
if ((pos = proxy_env.find(':')) != string::npos)
|
||||
char buffer_error[256];
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
||||
curl_easy_setopt(connection, CURLOPT_ERRORBUFFER, buffer_error);
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
||||
curl_easy_setopt(connection, CURLOPT_WRITEFUNCTION, writer_body);
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
||||
CURLcode code{curl_easy_setopt(connection, CURLOPT_FOLLOWLOCATION, 1L)};
|
||||
if (code != CURLE_OK)
|
||||
{
|
||||
proxy.host = proxy_env.substr(0, pos);
|
||||
proxy.port = std::stoi(proxy_env.substr(pos + 1));
|
||||
throw runtime_error{"HTTP is not supported."};
|
||||
}
|
||||
else
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
||||
curl_easy_setopt(connection, CURLOPT_MAXREDIRS, 5L);
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
||||
code = curl_easy_setopt(connection, CURLOPT_USERAGENT,
|
||||
(string("gitea2rss/") += version).c_str());
|
||||
if (code != CURLE_OK)
|
||||
{
|
||||
proxy.host = proxy_env;
|
||||
throw runtime_error{"Failed to set User-Agent."};
|
||||
}
|
||||
|
||||
HTTPClientSession::setGlobalProxyConfig(proxy);
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
||||
curl_easy_setopt(connection, CURLOPT_HTTPGET, 1L);
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
||||
code = curl_easy_setopt(connection, CURLOPT_URL, url.c_str());
|
||||
if (code != CURLE_OK)
|
||||
{
|
||||
throw runtime_error{"Couldn't set URL: " + to_string(code)};
|
||||
}
|
||||
|
||||
code = curl_easy_perform(connection);
|
||||
if (code != CURLE_OK)
|
||||
{
|
||||
throw runtime_error{"libcurl error: " + to_string(code)};
|
||||
}
|
||||
|
||||
long http_status{0}; // NOLINT(google-runtime-int)
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
|
||||
curl_easy_getinfo(connection, CURLINFO_RESPONSE_CODE, &http_status);
|
||||
|
||||
curl_easy_cleanup(connection);
|
||||
|
||||
if (http_status == 200)
|
||||
{
|
||||
return buffer_body;
|
||||
}
|
||||
|
||||
if (cgi)
|
||||
{
|
||||
cout << "Status: " << http_status << endl;
|
||||
}
|
||||
throw runtime_error{"HTTP error: " + to_string(http_status)};
|
||||
}
|
||||
catch (const std::exception &)
|
||||
catch (const runtime_error &e)
|
||||
{
|
||||
// No proxy found, no problem.
|
||||
}
|
||||
}
|
||||
|
||||
const string get_http(const string &url)
|
||||
{
|
||||
try
|
||||
{
|
||||
Poco::URI poco_uri(url);
|
||||
string path = poco_uri.getPathAndQuery();
|
||||
if (path.empty())
|
||||
{
|
||||
path = "/";
|
||||
}
|
||||
|
||||
unique_ptr<HTTPClientSession> session;
|
||||
if (poco_uri.getScheme() == "https")
|
||||
{
|
||||
session = make_unique<HTTPSClientSession>(poco_uri.getHost(),
|
||||
poco_uri.getPort());
|
||||
}
|
||||
else if (poco_uri.getScheme() == "http")
|
||||
{
|
||||
session = make_unique<HTTPClientSession>(poco_uri.getHost(),
|
||||
poco_uri.getPort());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw Poco::Exception("Protocol not supported.");
|
||||
}
|
||||
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
|
||||
request.set("User-Agent", string("gitea2rss/") + global::version);
|
||||
|
||||
HTTPResponse response;
|
||||
|
||||
session->sendRequest(request);
|
||||
istream &rs = session->receiveResponse(response);
|
||||
|
||||
// Not using the constants because some are too new for Debian stretch.
|
||||
switch (response.getStatus())
|
||||
{
|
||||
case 301: // HTTPResponse::HTTP_MOVED_PERMANENTLY
|
||||
case 308: // HTTPResponse::HTTP_PERMANENT_REDIRECT
|
||||
case 302: // HTTPResponse::HTTP_FOUND
|
||||
case 303: // HTTPResponse::HTTP_SEE_OTHER
|
||||
case 307: // HTTPResponse::HTTP_TEMPORARY_REDIRECT
|
||||
{
|
||||
string location = response.get("Location");
|
||||
if (location.substr(0, 4) != "http")
|
||||
{
|
||||
location = poco_uri.getScheme() + "://" + poco_uri.getHost()
|
||||
+ location;
|
||||
}
|
||||
return get_http(location);
|
||||
}
|
||||
case HTTPResponse::HTTP_OK:
|
||||
{
|
||||
string answer;
|
||||
StreamCopier::copyToString(rs, answer);
|
||||
return answer;
|
||||
}
|
||||
default:
|
||||
{
|
||||
if (cgi)
|
||||
{
|
||||
cout << "Status: " << response.getStatus() << endl;
|
||||
}
|
||||
cerr << "HTTP Error: " << response.getStatus() << endl;
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const Poco::Exception &e)
|
||||
{
|
||||
cerr << "Error: " << e.displayText() << endl;
|
||||
cerr << "Error: " << e.what() << endl;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
size_t writer_body(char *data, size_t size, size_t nmemb)
|
||||
{
|
||||
if (data == nullptr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
buffer_body.append(data, size * nmemb);
|
||||
|
||||
return size * nmemb;
|
||||
}
|
||||
|
||||
} // namespace gitea2rss
|
||||
|
|
37
src/main.cpp
37
src/main.cpp
|
@ -1,5 +1,5 @@
|
|||
/* This file is part of gitea2rss.
|
||||
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
||||
* Copyright © 2019-2021 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
|
||||
|
@ -14,33 +14,27 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "gitea2rss.hpp"
|
||||
#include "version.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <Poco/Net/NetSSL.h>
|
||||
#include <Poco/Environment.h>
|
||||
#include "version.hpp"
|
||||
#include "gitea2rss.hpp"
|
||||
|
||||
using std::cout;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
using std::cout;
|
||||
using std::string;
|
||||
using std::chrono::system_clock;
|
||||
using Poco::Environment;
|
||||
using namespace gitea2rss;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const string query = Environment::get("QUERY_STRING", "");
|
||||
|
||||
const string query{get_env_var("QUERY_STRING")};
|
||||
string url;
|
||||
string type = "releases";
|
||||
|
||||
Poco::Net::initializeSSL();
|
||||
|
||||
set_proxy();
|
||||
|
||||
if (!query.empty())
|
||||
{
|
||||
const string baseurl = Environment::get("GITEA2RSS_BASEURL", "");
|
||||
const string baseurl{get_env_var("GITEA2RSS_BASEURL")};
|
||||
if (baseurl.empty())
|
||||
{
|
||||
cout << "Status: 500 Internal Server Error\n\n";
|
||||
|
@ -72,15 +66,18 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
else if (argc < 2)
|
||||
{
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
||||
cerr << "usage: " << argv[0]
|
||||
<< " URL of Gitea project [releases|tags]\n";
|
||||
<< " URL of Gitea project [releases|tags|commits]\n";
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
||||
url = argv[1];
|
||||
if (argc > 2)
|
||||
{
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
||||
type = argv[2];
|
||||
}
|
||||
}
|
||||
|
@ -94,6 +91,10 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
ret = write_tags(url);
|
||||
}
|
||||
else if (type == "commits")
|
||||
{
|
||||
ret = write_commits(url);
|
||||
}
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
|
@ -101,9 +102,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
cout << " </channel>\n"
|
||||
"</rss>\n";
|
||||
|
||||
Poco::Net::uninitializeSSL();
|
||||
"</rss>\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* 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
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <jsoncpp/json/json.h>
|
||||
#include "gitea2rss.hpp"
|
||||
#include <iostream>
|
||||
#include <json/json.h>
|
||||
#include <sstream>
|
||||
|
||||
using std::cout;
|
||||
using std::cerr;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::stringstream;
|
||||
|
||||
namespace gitea2rss
|
||||
{
|
||||
|
||||
uint8_t write_releases(const string &url)
|
||||
{
|
||||
const string baseurl = get_baseurl(url);
|
||||
const string repo = get_repo(url);
|
||||
stringstream data(get_http(baseurl + "/api/v1/repos/"
|
||||
+ repo + "/releases"));
|
||||
stringstream data(
|
||||
get_http(baseurl + "/api/v1/repos/" + repo + "/releases"));
|
||||
|
||||
if (cgi)
|
||||
{
|
||||
|
@ -53,19 +56,27 @@ uint8_t write_releases(const string &url)
|
|||
const string body = escape_some_html(release["body"].asString());
|
||||
|
||||
cout << " <item>\n";
|
||||
write_line(6, "title", get_project(url) + ": "
|
||||
+ release["name"].asString());
|
||||
write_line(6, "link", baseurl + "/" + repo + "/releases");
|
||||
write_line(6, "title",
|
||||
get_project(url) + ": " + release["name"].asString());
|
||||
write_line(6, "link",
|
||||
((baseurl + "/" += repo) += "/releases/tag/") +=
|
||||
release["tag_name"].asString());
|
||||
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",
|
||||
"\n <![CDATA[<p><strong>" + type + "</strong></p>\n"
|
||||
"<pre>" + body + "</pre>\n"
|
||||
" <p><a href=\"" + release["tarball_url"].asString()
|
||||
+ "\">Download tarball</a></p>]]>\n ");
|
||||
"\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;
|
||||
}
|
||||
|
||||
} // namespace gitea2rss
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* This file is part of gitea2rss.
|
||||
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
||||
* Copyright © 2019-2021 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
|
||||
|
@ -14,43 +14,47 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
#include <regex>
|
||||
#include "gitea2rss.hpp"
|
||||
|
||||
const string get_baseurl(const string &url)
|
||||
#include <cstdlib>
|
||||
#include <map>
|
||||
#include <regex>
|
||||
|
||||
namespace gitea2rss
|
||||
{
|
||||
|
||||
using std::getenv;
|
||||
|
||||
string get_baseurl(const string &url)
|
||||
{
|
||||
const size_t pos = url.find('/', 8);
|
||||
return url.substr(0, pos);
|
||||
}
|
||||
|
||||
const string get_domain(const string &url)
|
||||
string get_domain(const string &url)
|
||||
{
|
||||
const string baseurl = get_baseurl(url);
|
||||
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;
|
||||
return url.substr(pos);
|
||||
}
|
||||
|
||||
const string get_project(const string &url)
|
||||
string get_project(const string &url)
|
||||
{
|
||||
const string repo = get_repo(url);
|
||||
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));
|
||||
html = std::regex_replace(html, re, pair.second);
|
||||
|
@ -58,3 +62,15 @@ const string escape_some_html(string html)
|
|||
|
||||
return html;
|
||||
}
|
||||
|
||||
string get_env_var(const string &variable)
|
||||
{
|
||||
const char *env{getenv(variable.c_str())};
|
||||
if (env != nullptr)
|
||||
{
|
||||
return env;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
} // namespace gitea2rss
|
||||
|
|
38
src/tags.cpp
38
src/tags.cpp
|
@ -1,5 +1,5 @@
|
|||
/* This file is part of gitea2rss.
|
||||
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
||||
* Copyright © 2019-2021 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
|
||||
|
@ -14,13 +14,18 @@
|
|||
* 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;
|
||||
#include <json/json.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
namespace gitea2rss
|
||||
{
|
||||
|
||||
using std::cerr;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::stringstream;
|
||||
|
||||
|
@ -28,8 +33,8 @@ 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"));
|
||||
stringstream data(
|
||||
get_http(baseurl + "/api/v1/repos/" + repo + "/git/refs"));
|
||||
|
||||
if (cgi)
|
||||
{
|
||||
|
@ -42,7 +47,7 @@ uint8_t write_tags(const string &url)
|
|||
return 2;
|
||||
}
|
||||
|
||||
write_preamble(url, "releases");
|
||||
write_preamble(url, "tags");
|
||||
|
||||
Json::Value json;
|
||||
data >> json;
|
||||
|
@ -59,18 +64,23 @@ uint8_t write_tags(const string &url)
|
|||
|
||||
cout << " <item>\n";
|
||||
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\"",
|
||||
get_domain(url) + " tag " + sha);
|
||||
write_line(6, "description",
|
||||
"\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 ");
|
||||
"\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 ");
|
||||
|
||||
cout << " </item>\n";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace gitea2rss
|
||||
|
|
42
src/time.cpp
42
src/time.cpp
|
@ -1,5 +1,5 @@
|
|||
/* 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
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -14,25 +14,49 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <iomanip>
|
||||
#include "gitea2rss.hpp"
|
||||
|
||||
const string strtime(const system_clock::time_point &timepoint)
|
||||
#include <ctime>
|
||||
#include <iomanip>
|
||||
#include <string>
|
||||
|
||||
namespace gitea2rss
|
||||
{
|
||||
|
||||
string strtime(const system_clock::time_point &timepoint)
|
||||
{
|
||||
constexpr uint16_t bufsize = 1024;
|
||||
std::time_t time = system_clock::to_time_t(timepoint);
|
||||
std::tm *tm;
|
||||
tm = std::gmtime(&time);
|
||||
std::tm *tm{std::gmtime(&time)};
|
||||
char buffer[bufsize];
|
||||
std::strftime(buffer, bufsize, "%a, %d %b %Y %T %z", tm);
|
||||
return static_cast<const string>(buffer);
|
||||
}
|
||||
|
||||
const string strtime(const string &time)
|
||||
string strtime(const string &time)
|
||||
{
|
||||
// FIXME: Do this more elegantly.
|
||||
std::tm tm = {};
|
||||
tm.tm_isdst = -1; // Detect daylight saving time.
|
||||
tm.tm_isdst = -1; // Detect daylight saving time.
|
||||
std::stringstream ss(time);
|
||||
ss >> std::get_time(&tm, "%Y-%m-%dT%T"); // Assume time is UTC.
|
||||
return strtime(system_clock::from_time_t(timegm(&tm)));
|
||||
ss >> std::get_time(&tm, "%Y-%m-%dT%T");
|
||||
std::time_t time_tmp = timegm(&tm);
|
||||
|
||||
constexpr size_t zone_start = 19;
|
||||
if (time[zone_start] == '+')
|
||||
{
|
||||
string zone = time.substr(zone_start + 1);
|
||||
time_tmp -= std::stol(zone.substr(0, 2)) * 60 * 60;
|
||||
time_tmp -= std::stol(zone.substr(3)) * 60;
|
||||
}
|
||||
else if (time[zone_start] == '+')
|
||||
{
|
||||
string zone = time.substr(zone_start + 1);
|
||||
time_tmp += std::stol(zone.substr(0, 2)) * 60 * 60;
|
||||
time_tmp += std::stol(zone.substr(3)) * 60;
|
||||
}
|
||||
|
||||
return strtime(system_clock::from_time_t(time_tmp));
|
||||
}
|
||||
|
||||
} // namespace gitea2rss
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
#ifndef 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
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* 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
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -14,14 +14,16 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "gitea2rss.hpp"
|
||||
#include "version.hpp"
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <regex>
|
||||
#include <Poco/Environment.h>
|
||||
#include "version.hpp"
|
||||
#include "gitea2rss.hpp"
|
||||
|
||||
namespace gitea2rss
|
||||
{
|
||||
|
||||
using std::cout;
|
||||
using Poco::Environment;
|
||||
|
||||
void write_line(const uint8_t spaces, const string &tag, const string &value)
|
||||
{
|
||||
|
@ -44,9 +46,9 @@ void write_line(const uint8_t spaces, const string &tag, const string &value)
|
|||
|
||||
void write_preamble(const string &url, const string &type)
|
||||
{
|
||||
const string request_uri = Environment::get("REQUEST_URI", "");
|
||||
const string server_name = Environment::get("SERVER_NAME", "");
|
||||
const string https = Environment::get("HTTPS", "");
|
||||
const string request_uri{get_env_var("REQUEST_URI")};
|
||||
const string server_name{get_env_var("SERVER_NAME")};
|
||||
const string https{get_env_var("HTTPS")};
|
||||
string selfurl;
|
||||
|
||||
if (!request_uri.empty() && !server_name.empty())
|
||||
|
@ -64,16 +66,18 @@ void write_preamble(const string &url, const string &type)
|
|||
}
|
||||
|
||||
cout << "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n"
|
||||
" <channel>\n";
|
||||
" <channel>\n";
|
||||
if (cgi)
|
||||
{
|
||||
cout << " <atom:link href=\"" + selfurl
|
||||
+ "\" rel=\"self\" type=\"application/rss+xml\"/>\n";
|
||||
+ "\" rel=\"self\" type=\"application/rss+xml\"/>\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, "generator", string("gitea2rss ") + version);
|
||||
write_line(4, "lastBuildDate", strtime(system_clock::now()));
|
||||
}
|
||||
|
||||
} // namespace gitea2rss
|
||||
|
|
|
@ -9,7 +9,7 @@ target_include_directories(${PROJECT_NAME}_testlib
|
|||
"$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/src>")
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}_testlib
|
||||
PRIVATE Poco::Foundation Poco::Net Poco::NetSSL jsoncpp_lib)
|
||||
PRIVATE CURL::libcurl PkgConfig::jsoncpp)
|
||||
|
||||
file(GLOB sources_tests test_*.cpp)
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* This file is part of gitea2rss.
|
||||
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
||||
* Copyright © 2019-2021 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
|
||||
|
@ -14,23 +14,26 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <catch.hpp>
|
||||
#include "gitea2rss.hpp"
|
||||
|
||||
#include <catch.hpp>
|
||||
|
||||
#include <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
|
||||
= escape_some_html("<p><small>.</small></p>");
|
||||
const string escaped = escape_some_html("<p><small>.</small></p>");
|
||||
|
||||
THEN ("The HTML is escaped")
|
||||
THEN("The HTML is escaped")
|
||||
{
|
||||
REQUIRE(escaped ==
|
||||
"<p><small>.</small></p>");
|
||||
REQUIRE(escaped
|
||||
== "<p><small>.</"
|
||||
"small></p>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* 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
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -14,31 +14,32 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <catch.hpp>
|
||||
#include "gitea2rss.hpp"
|
||||
#include <catch.hpp>
|
||||
#include <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
|
||||
= get_baseurl("https://git.example.com/user/project");
|
||||
const string baseurl =
|
||||
get_baseurl("https://git.example.com/user/project");
|
||||
|
||||
THEN ("The base URL is correctly returned")
|
||||
THEN("The base URL is correctly returned")
|
||||
{
|
||||
REQUIRE(baseurl == "https://git.example.com");
|
||||
}
|
||||
}
|
||||
|
||||
WHEN ("HTTP URL")
|
||||
WHEN("HTTP URL")
|
||||
{
|
||||
const string baseurl
|
||||
= get_baseurl("http://git.example.com/user/project");
|
||||
const string baseurl =
|
||||
get_baseurl("http://git.example.com/user/project");
|
||||
|
||||
THEN ("The base URL is correctly returned")
|
||||
THEN("The base URL is correctly returned")
|
||||
{
|
||||
REQUIRE(baseurl == "http://git.example.com");
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* 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
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -14,20 +14,21 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <catch.hpp>
|
||||
#include "gitea2rss.hpp"
|
||||
#include <catch.hpp>
|
||||
#include <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
|
||||
= get_domain("https://git.example.com/user/project");
|
||||
const string domain =
|
||||
get_domain("https://git.example.com/user/project");
|
||||
|
||||
THEN ("The domain is correctly returned")
|
||||
THEN("The domain is correctly returned")
|
||||
{
|
||||
REQUIRE(domain == "git.example.com");
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* 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
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -14,31 +14,32 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <catch.hpp>
|
||||
#include "gitea2rss.hpp"
|
||||
#include <catch.hpp>
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
using namespace gitea2rss;
|
||||
|
||||
SCENARIO ("get_http() works as expected", "[http]")
|
||||
SCENARIO("get_http() works as expected", "[http]")
|
||||
{
|
||||
WHEN ("URL is valid")
|
||||
WHEN("URL is valid")
|
||||
{
|
||||
const string answer = get_http("https://ip.tastytea.de/");
|
||||
|
||||
THEN ("Answer is not empty")
|
||||
THEN("Answer is not empty")
|
||||
{
|
||||
REQUIRE(answer != "");
|
||||
REQUIRE(!answer.empty());
|
||||
}
|
||||
}
|
||||
|
||||
WHEN ("URL is invalid")
|
||||
WHEN("URL is invalid")
|
||||
{
|
||||
const string answer = get_http("https://url.invalid/");
|
||||
|
||||
THEN ("Answer is empty")
|
||||
THEN("Answer is empty")
|
||||
{
|
||||
REQUIRE(answer == "");
|
||||
REQUIRE(answer.empty());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* 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
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -14,20 +14,21 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <catch.hpp>
|
||||
#include "gitea2rss.hpp"
|
||||
#include <catch.hpp>
|
||||
#include <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
|
||||
= get_project("https://git.example.com/user/project");
|
||||
const string project =
|
||||
get_project("https://git.example.com/user/project");
|
||||
|
||||
THEN ("The project is correctly returned")
|
||||
THEN("The project is correctly returned")
|
||||
{
|
||||
REQUIRE(project == "project");
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* 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
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <catch.hpp>
|
||||
#include "gitea2rss.hpp"
|
||||
#include <catch.hpp>
|
||||
#include <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
|
||||
= get_repo("https://git.example.com/user/project");
|
||||
const string repo = get_repo("https://git.example.com/user/project");
|
||||
|
||||
THEN ("The repo is correctly returned")
|
||||
THEN("The repo is correctly returned")
|
||||
{
|
||||
REQUIRE(repo == "user/project");
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* 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
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -14,33 +14,32 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <catch.hpp>
|
||||
#include "gitea2rss.hpp"
|
||||
#include <catch.hpp>
|
||||
#include <chrono>
|
||||
#include <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;
|
||||
const string time
|
||||
= strtime(tp);
|
||||
const string time = strtime(tp);
|
||||
|
||||
THEN ("The time is returned in the correct format")
|
||||
THEN("The time is returned in the correct format")
|
||||
{
|
||||
REQUIRE(time == "Thu, 01 Jan 1970 00:00:00 +0000");
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN ("Time as ISO 8601 string")
|
||||
GIVEN("Time as ISO 8601 string")
|
||||
{
|
||||
const string time
|
||||
= strtime("1970-01-01T00:00:00+0000");
|
||||
const string time = 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")
|
||||
{
|
||||
REQUIRE(time == "Thu, 01 Jan 1970 00:00:00 +0000");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue