From b3165878a5c998864337eb64a038de805defa09c Mon Sep 17 00:00:00 2001 From: Dominik Meyer Date: Sat, 26 Dec 2020 16:39:29 +0100 Subject: [PATCH] ADD: first version of project --- CMakeLists.txt | 45 ++++++++++++++++++ docs/Doxyfile.in | 23 +++++++++ include/repoBadge.hpp | 106 ++++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 61 ++++++++++++++++++++++++ src/repoBadge.cpp | 92 ++++++++++++++++++++++++++++++++++++ 5 files changed, 327 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 docs/Doxyfile.in create mode 100644 include/repoBadge.hpp create mode 100644 src/main.cpp create mode 100644 src/repoBadge.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2e7d877 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,45 @@ +# This file is part of the BuildIt software distribution (https://gitcloud.federationhq.de/byterazor/buildit) +# Copyright (c) 2020 Dominik Meyer . +# +# 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 . + +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) diff --git a/docs/Doxyfile.in b/docs/Doxyfile.in new file mode 100644 index 0000000..a091d31 --- /dev/null +++ b/docs/Doxyfile.in @@ -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 diff --git a/include/repoBadge.hpp b/include/repoBadge.hpp new file mode 100644 index 0000000..d182c82 --- /dev/null +++ b/include/repoBadge.hpp @@ -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 . + * + * 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 . + */ + + /** @file */ + #include + #include + + /** + * @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 diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..955d551 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,61 @@ +/* + * This file is part of the BuildIt software distribution (https://gitea.federationhq.de/byterazor/repobadge) + * Copyright (c) 2020 Dominik Meyer . + * + * 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 . + */ + #include + #include + + void usage(std::string name) + { + std::cout << "USAGE: " << name << " " << 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; + } + + }; diff --git a/src/repoBadge.cpp b/src/repoBadge.cpp new file mode 100644 index 0000000..8e93f20 --- /dev/null +++ b/src/repoBadge.cpp @@ -0,0 +1,92 @@ +/* + * This file is part of the BuildIt software distribution (https://gitea.federationhq.de/byterazor/repobadge) + * Copyright (c) 2020 Dominik Meyer . + * + * 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 . + */ + + /** @file */ + #include + #include + + 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 << "\n"; + stream << "\n"; + stream << "\n"; + stream << " \n"; + stream << " \n"; + stream << "\n"; + stream << "\n"; + stream << " \n"; + stream << "\n"; + stream << "\n"; + stream << "\n"; + stream << "\n"; + stream << "\n"; + stream << " "<\n"; + stream << " "<\n"; + stream << " "<\n"; + stream << " "<\n"; + stream << "\n"; + stream << "\n"; + + + return stream.str(); + }