Skip to content

Commit d4c58c1

Browse files
committed
Make set_status check new status is valid for issue
This should prevent me from sweeping all TS issues in status "WP" to a status like "C++26" which is only valid for the IS, not for issues in a TS. Also check the other way around, so that issues in the IS cannot be set to "TS" status. If this gives a false positive (because the <title> happens to match the naive detection of TS issues) the issue status can be set be editing the XML by hand.
1 parent 868f2bd commit d4c58c1

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/set_status.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <string>
1616
#include <chrono>
1717
#include <format>
18+
#include <cstring>
1819

1920
#include <filesystem>
2021
namespace fs = std::filesystem;
@@ -107,6 +108,35 @@ int main(int argc, char const * argv[]) {
107108
throw bad_issue_file{filename, "Corrupt status attribute"};
108109
}
109110
auto old_status = issue_data.substr(k, l-k);
111+
112+
// Do not allow an IS status for TS issues, and vice versa.
113+
if (new_status.starts_with("C++") or new_status == "TS")
114+
{
115+
auto t1 = issue_data.find("<title>", l);
116+
auto t2 = issue_data.find("</title>", l);
117+
if (t1 == std::string::npos or t2 == std::string::npos or t2 < t1)
118+
throw bad_issue_file{filename, "Cannot find <title> element"};
119+
t1 += std::strlen("<title>");
120+
std::string_view title(issue_data);
121+
title = title.substr(t1, t2 - t1);
122+
bool is_ts_issue = false;
123+
if (title.starts_with('['))
124+
{
125+
auto end = title.find(']');
126+
if (end != title.npos)
127+
{
128+
auto tag = title.substr(0, end);
129+
#ifdef __cpp_lib_string_contains
130+
is_ts_issue = tag.contains(".ts");
131+
#else
132+
is_ts_issue = tag.find(".ts") != tag.npos;
133+
#endif
134+
}
135+
}
136+
if (is_ts_issue != (new_status == "TS"))
137+
throw std::runtime_error{std::format("Refusing to set status \"{}\" for issue in {}:\n\t{}: {}", new_status, is_ts_issue ? "a TS" : "the IS", issue_number, title)};
138+
}
139+
110140
issue_data.replace(k, l-k, new_status);
111141

112142
if (lwg::filename_for_status(new_status) != lwg::filename_for_status(old_status)) {

0 commit comments

Comments
 (0)