ADD: first version of project

This commit is contained in:
Dominik Meyer 2020-12-26 16:39:29 +01:00
parent b48b957b4f
commit b3165878a5
No known key found for this signature in database
GPG Key ID: B4C312B600606B64
5 changed files with 327 additions and 0 deletions

45
CMakeLists.txt Normal file
View File

@ -0,0 +1,45 @@
# This file is part of the BuildIt software distribution (https://gitcloud.federationhq.de/byterazor/buildit)
# Copyright (c) 2020 Dominik Meyer <dmeyer@federationhq.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/>.
cmake_minimum_required (VERSION 3.1 FATAL_ERROR)
project (buildIt-server VERSION 0.1.0 LANGUAGES CXX)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules )
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
include(doxygen)
build_docs(PROCESS_DOXYFILE DOXYFILE_PATH "docs/Doxyfile.in" )
include(compdb)
# provide all source files for the server
set(REPOBADGE_SOURCES
include/repoBadge.hpp
src/svg.hpp
src/repoBadge.cpp
)
add_library(repobadge STATIC ${REPOBADGE_SOURCES})
target_include_directories(repobadge
PUBLIC
include
PRIVATE
src
)
add_executable(badge src/main.cpp)
target_link_libraries(badge repobadge)

23
docs/Doxyfile.in Normal file
View File

@ -0,0 +1,23 @@
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = @PROJECT_NAME@
PROJECT_NUMBER = "@GIT_BRANCH@ @GIT_COMMIT_HASH@"
PROJECT_BRIEF = "library and executable for generating repository badges"
OUTPUT_DIRECTORY = @CMAKE_CURRENT_BINARY_DIR@/doxygen/
OUTPUT_LANGUAGE = English
BRIEF_MEMBER_DESC = YES
REPEAT_BRIEF = YES
ALWAYS_DETAILED_SEC = NO
INLINE_INHERITED_MEMB = NO
FULL_PATH_NAMES = NO
MULTILINE_CPP_IS_BRIEF = NO
TAB_SIZE = 4
MARKDOWN_SUPPORT = YES
GENERATE_TODOLIST = YES
GENERATE_TESTLIST = YES
GENERATE_BUGLIST = YES
GENERATE_DEPRECATEDLIST= YES
INPUT = @CMAKE_CURRENT_SOURCE_DIR@/README.md @CMAKE_CURRENT_SOURCE_DIR@/src/ @CMAKE_CURRENT_SOURCE_DIR@/include
INPUT_ENCODING = UTF-8
FILE_PATTERNS = *.hpp *.cpp *.md
USE_MDFILE_AS_MAINPAGE = README.md
RECURSIVE = YES

106
include/repoBadge.hpp Normal file
View File

@ -0,0 +1,106 @@
#pragma once
/*
* This file is part of the BuildIt software distribution (https://gitea.federationhq.de/byterazor/repobadge)
* Copyright (c) 2020 Dominik Meyer <dmeyer@federationhq.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/>.
*/
/** @file */
#include <string>
#include <sstream>
/**
* @brief namespace for all repoBadge related classes and datatypes
*/
namespace repoBadge
{
/**
* @brief some default values for colors
*/
enum class BadgeColor
{
BLUE,
BRIGHTGREEN,
GREEN,
LIGHTGREY,
ORANGE,
RED,
YELLOW,
YELLOWGREEN
};
/**
* @brief class representing a repository badge
*
* a repository badge is used to highlight the build status of a repository,
* the code coverage of the tests, or any other metric you can come up with
* for your repository.
*
* a repository badge consist of a left part used for describing the metric
* and a right part used as the value of the metric. The right part is
* highlighted by a different background color.
*/
class Badge
{
private:
/// the string used for the left part of the badge
std::string left_;
/// the string used for the right part of the badge
std::string right_;
/// the background color used for the right part of the badge
std::string color_;
public:
/**
* @brief create a badge with the default color BRIGHTGREEN
*
* @param left - the word used for the left part of the badge
* @param right - the word used for the right part of the badge
*/
Badge(const std::string &left, const std::string &right) : Badge(left,right,BadgeColor::BRIGHTGREEN) {}
/**
* @brief create a badge with the color given as a hex rgb string
*
* @param left - the word used for the left part of the badge
* @param right - the word used for the right part of the badge
* @param color - the background color used for the right part of the badge given in hex rgb (#007ec6)
*/
Badge(const std::string &left, const std::string &right,const std::string &color) : left_(left), right_(right), color_(color){};
/**
* @brief create a badge with the color given as one of the default enums
*
* @param left - the word used for the left part of the badge
* @param right - the word used for the right part of the badge
* @param color - the background color used for the right part of the badge given ad an repoBadge::BadgeColor enum
*/
Badge(const std::string &left, const std::string &right, BadgeColor color);
/**
* @brief create the svg file and return it as a string
*
* @return - the svg file
*/
std::string create();
}; //
}; // namespace repoBadge

61
src/main.cpp Normal file
View File

@ -0,0 +1,61 @@
/*
* This file is part of the BuildIt software distribution (https://gitea.federationhq.de/byterazor/repobadge)
* Copyright (c) 2020 Dominik Meyer <dmeyer@federationhq.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 <repoBadge.hpp>
#include <iostream>
void usage(std::string name)
{
std::cout << "USAGE: " << name << " <left string> <right string> <color>" << std::endl;
std::cout << " color is optional" << std::endl;
}
int main(int argc, char **argv)
{
// check for help request
if (argc == 2)
{
if (std::string(argv[1]) == "-h" || std::string(argv[1]) == "--help")
{
usage(argv[0]);
return 0;
}
}
else if (argc == 3)
{
std::string left(argv[1]);
std::string right(argv[2]);
repoBadge::Badge badge(left, right, repoBadge::BadgeColor::BRIGHTGREEN);
std::cout << badge.create();
}
else if (argc == 4)
{
std::string left(argv[1]);
std::string right(argv[2]);
std::string color(argv[3]);
repoBadge::Badge badge(left, right, color );
std::cout << badge.create();
}
else
{
std::cerr << "Error: parameter missing" << std::endl;
usage(std::string(argv[0]));
return 1;
}
};

92
src/repoBadge.cpp Normal file
View File

@ -0,0 +1,92 @@
/*
* This file is part of the BuildIt software distribution (https://gitea.federationhq.de/byterazor/repobadge)
* Copyright (c) 2020 Dominik Meyer <dmeyer@federationhq.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/>.
*/
/** @file */
#include <repoBadge.hpp>
#include <sstream>
repoBadge::Badge::Badge(const std::string &left, const std::string &right, BadgeColor color) : left_(left), right_(right)
{
switch(color)
{
case BadgeColor::BLUE:
color_="#007ec6";
break;
case BadgeColor::BRIGHTGREEN:
color_="#4c1";
break;
case BadgeColor::GREEN:
color_="#97CA00";
break;
case BadgeColor::YELLOWGREEN:
color_="#a4a61d";
break;
case BadgeColor::LIGHTGREY:
color_="#9f9f9f";
break;
case BadgeColor::ORANGE:
color_="#fe7d37";
break;
case BadgeColor::RED:
color_="#e05d44";
break;
case BadgeColor::YELLOW:
color_="#dfb317";
break;
};
}
std::string repoBadge::Badge::create()
{
std::stringstream stream;
// we use 82.5 pixes as the maxim character with for the used font-family
// hopefully this will be enough
int widthL = (82.5 * (float)left_.length())/ 11.0;
int widthR = (82.5 * (float)right_.length())/ 11.0;
int width = widthL + widthR + 20;
/*
* simple generation of the image
*/
stream << "<?xml version=\"1.0\"?>\n";
stream << "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\""<<width<<"\" height=\"20\">\n";
stream << "<linearGradient id=\"a\" x2=\"0\" y2=\"100%\">\n";
stream << " <stop offset=\"0\" stop-color=\"#bbb\" stop-opacity=\".1\"/>\n";
stream << " <stop offset=\"2\" stop-opacity=\".1\"/>\n";
stream << "</linearGradient>\n";
stream << "\n";
stream << "<rect rx=\"3\" width=\""<<(widthL+10)<<"\" height=\"20\" fill=\"#555\"/> <!-- Comment -->\n";
stream << "<rect rx=\"3\" x=\""<<(widthL+10)<<"\" width=\""<<(widthR+10)<<"\" height=\"20\" fill=\""<<color_<<"\"/>\n";
stream << "\n";
stream << "<path fill=\""<<color_<<"\" d=\"M"<<widthL+10-2 << " 0h4v20h-4z\"/>\n";
stream << "<rect rx=\"3\" width=\""<<width<<"\" height=\"20\" fill=\"url(#a)\"/>\n";
stream << "<g fill=\"#fff\" text-anchor=\"middle\" font-family=\"DejaVu Sans,Verdana,Geneva,sans-serif\" font-size=\"11\">\n";
stream << " <text x=\""<< (widthL+10)/2 <<"\" y=\"15\" fill=\"#010101\" fill-opacity=\".3\">"<<left_<<"</text>\n";
stream << " <text x=\""<< (widthL+10)/2 <<"\" y=\"14\">"<<left_<<"</text>\n";
stream << " <text x=\""<< (widthL+10) + ((widthR+10)/2) << "\" y=\"15\" fill=\"#010101\" fill-opacity=\".3\">"<<right_<<"</text>\n";
stream << " <text x=\""<< (widthL+10) + ((widthR+10)/2) << "\" y=\"14\">"<<right_<<"</text>\n";
stream << "</g>\n";
stream << "</svg>\n";
return stream.str();
}