Skip to content

Commit

Permalink
implement issue ID prefix algorithm
Browse files Browse the repository at this point in the history
tests now require the actual abbreviated first words in the issue ID
  • Loading branch information
arnemertz committed Aug 13, 2021
1 parent c4a2892 commit a1f6c84
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/domain/CMakeLists.txt
Expand Up @@ -7,5 +7,6 @@ target_link_libraries(domain
PRIVATE
project_warnings
project_options
CONAN_PKG::range-v3
)
target_include_directories(domain PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
21 changes: 19 additions & 2 deletions src/domain/application_service.cpp
@@ -1,9 +1,26 @@
#include "application_service.hpp"

#include <range/v3/view.hpp>
#include <range/v3/range/conversion.hpp>
#include <string>

using namespace fix::domain;
using namespace std::literals;
namespace rv = ranges::views;

std::string application_service::create(std::string_view title, std::string_view description) { // NOLINT
(void) title;
(void) description;
return "thi-is-a-new-0000000";

// clang-format off
const auto id_prefix = title
| rv::split(' ')
| rv::take(4)
| rv::transform([](auto&& word) {
return word | rv::take(3) | rv::transform([](char c){ return std::tolower(c); });
})
| rv::join('-')
| ranges::to<std::string>;
// clang-format on

return id_prefix + "-0000000"s;
}
2 changes: 1 addition & 1 deletion src/fix_cli/app.cpp
Expand Up @@ -51,7 +51,7 @@ int app::run_command(std::string const& command) {

if (command == "create"sv) {
domain::application_service application_service;
const auto issue_id = application_service.create("", "");
const auto issue_id = application_service.create("this is a new issue", "");
out << fmt::format("Issue created: {}\n", issue_id);
return EXIT_SUCCESS;
}
Expand Down
10 changes: 9 additions & 1 deletion test/domain/application_service_test.cpp
Expand Up @@ -2,9 +2,17 @@

#include "application_service.hpp"

#include <string>
#include <tuple>
using namespace std::literals;

using fix::domain::application_service;

TEST_CASE("Create issue returns issue ID") {
application_service application_service;
CHECK_THAT(application_service.create("this is a new issue", "some text"), Catch::Matches("thi-is-a-new-[0-9a-f]{7}"));
auto const& [title, description, id_prefix]
= GENERATE(std::tuple("this is a new issue", "some text", "thi-is-a-new"),
std::tuple("My first issue in Fix", "Dorem Fixum dolor sit amet", "my-fir-iss-in"));
auto const id_pattern = id_prefix + "-[0-9a-f]{7}"s;
CHECK_THAT(application_service.create(title, description), Catch::Matches(id_pattern));
}

0 comments on commit a1f6c84

Please sign in to comment.