Skip to content

Commit a1f6c84

Browse files
committed
implement issue ID prefix algorithm
tests now require the actual abbreviated first words in the issue ID
1 parent c4a2892 commit a1f6c84

4 files changed

Lines changed: 30 additions & 4 deletions

File tree

‎src/domain/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ target_link_libraries(domain
77
PRIVATE
88
project_warnings
99
project_options
10+
CONAN_PKG::range-v3
1011
)
1112
target_include_directories(domain PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)

‎src/domain/application_service.cpp‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
#include "application_service.hpp"
22

3+
#include <range/v3/view.hpp>
4+
#include <range/v3/range/conversion.hpp>
5+
#include <string>
6+
37
using namespace fix::domain;
8+
using namespace std::literals;
9+
namespace rv = ranges::views;
410

511
std::string application_service::create(std::string_view title, std::string_view description) { // NOLINT
6-
(void) title;
712
(void) description;
8-
return "thi-is-a-new-0000000";
13+
14+
// clang-format off
15+
const auto id_prefix = title
16+
| rv::split(' ')
17+
| rv::take(4)
18+
| rv::transform([](auto&& word) {
19+
return word | rv::take(3) | rv::transform([](char c){ return std::tolower(c); });
20+
})
21+
| rv::join('-')
22+
| ranges::to<std::string>;
23+
// clang-format on
24+
25+
return id_prefix + "-0000000"s;
926
}

‎src/fix_cli/app.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ int app::run_command(std::string const& command) {
5151

5252
if (command == "create"sv) {
5353
domain::application_service application_service;
54-
const auto issue_id = application_service.create("", "");
54+
const auto issue_id = application_service.create("this is a new issue", "");
5555
out << fmt::format("Issue created: {}\n", issue_id);
5656
return EXIT_SUCCESS;
5757
}

‎test/domain/application_service_test.cpp‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22

33
#include "application_service.hpp"
44

5+
#include <string>
6+
#include <tuple>
7+
using namespace std::literals;
8+
59
using fix::domain::application_service;
610

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

0 commit comments

Comments
 (0)