feat: support setting wiki page parent
This commit is contained in:
parent
030814bae6
commit
086b293cb1
@ -160,7 +160,10 @@ namespace Redmine
|
||||
* @param page - the name of the page
|
||||
* @param content - the content of the page
|
||||
*/
|
||||
void updateWikiPage(const std::string &projectIdentifier, const std::string &page, const std::string &content);
|
||||
void updateWikiPage(const std::string &projectIdentifier,
|
||||
const std::string &page,
|
||||
const std::string &content,
|
||||
const std::string &parentPage);
|
||||
|
||||
/**
|
||||
* @brief update a Wiki Page on the redmine server with attachments
|
||||
@ -170,7 +173,7 @@ namespace Redmine
|
||||
* @param attachements - vector of attachment paths
|
||||
* @param content - the content of the page
|
||||
*/
|
||||
void updateWikiPage(const std::string &projectIdentifier, const std::string &page, const std::string &content, const std::vector<std::string> &attachments );
|
||||
void updateWikiPage(const std::string &projectIdentifier, const std::string &page, const std::string &content, const std::string &parentPage, const std::vector<std::string> &attachments );
|
||||
|
||||
/**
|
||||
* @brief delete a Wiki Page on the redmine server
|
||||
|
@ -28,7 +28,8 @@
|
||||
Command::Wiki::Wiki(RedmineCLI::Redmine *r)
|
||||
:
|
||||
redmine_(r),
|
||||
output_(TEXT)
|
||||
output_(TEXT),
|
||||
parentPage_("")
|
||||
{
|
||||
|
||||
CLI::App* wiki = redmine_->getCLI().add_subcommand("wiki",
|
||||
@ -55,6 +56,7 @@ output_(TEXT)
|
||||
updatePage_->add_option("-c,--content", content_,"the new content of the wiki page");
|
||||
updatePage_->add_option("-f,--file", filePath_,"the new content of the wiki page as a file");
|
||||
updatePage_->add_option("-a",attachments_,"list of file paths to attach to the wiki page");
|
||||
updatePage_->add_option("--parent",parentPage_,"the name of the parent wiki page");
|
||||
updatePage_->callback([&](){updateWikiPage_();});
|
||||
}
|
||||
|
||||
@ -93,7 +95,7 @@ void Command::Wiki::updateWikiPage_()
|
||||
|
||||
|
||||
if (!content_.empty()) {
|
||||
client.updateWikiPage(projectIdentifier_, pageIdentifier_, content_);
|
||||
client.updateWikiPage(projectIdentifier_, pageIdentifier_, content_, parentPage_, attachments_);
|
||||
}
|
||||
else if (!filePath_.empty())
|
||||
{
|
||||
@ -106,7 +108,7 @@ void Command::Wiki::updateWikiPage_()
|
||||
|
||||
std::ifstream file(filePath_);
|
||||
std::string content((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
|
||||
client.updateWikiPage(projectIdentifier_, pageIdentifier_, content, attachments_);
|
||||
client.updateWikiPage(projectIdentifier_, pageIdentifier_, content, parentPage_, attachments_);
|
||||
}
|
||||
|
||||
|
||||
|
@ -74,6 +74,9 @@ namespace Command
|
||||
|
||||
/// command line argument file path for attachments
|
||||
std::vector<std::string> attachments_;
|
||||
|
||||
/// command line argument to set the parent page name
|
||||
std::string parentPage_;
|
||||
|
||||
/// pointer to the getPage subcommand
|
||||
CLI::App* getPage_;
|
||||
|
@ -279,38 +279,46 @@ void Redmine::API::uploadFileToProject(const std::uint64_t projectId, const std:
|
||||
return wiki["wiki_page"]["text"].get<std::string>();
|
||||
}
|
||||
|
||||
void Redmine::API::updateWikiPage(const std::string &projectIdentifier, const std::string &page, const std::string &content, const std::vector<std::string> &attachments )
|
||||
{
|
||||
nlohmann::json wikiPage;
|
||||
wikiPage["wiki_page"]["text"] = content;
|
||||
wikiPage["wiki_page"]["uploads"]=nlohmann::json::array();
|
||||
void Redmine::API::updateWikiPage(
|
||||
const std::string &projectIdentifier, const std::string &page,
|
||||
const std::string &content, const std::string &parentPage,
|
||||
const std::vector<std::string> &attachments) {
|
||||
nlohmann::json wikiPage;
|
||||
wikiPage["wiki_page"]["text"] = content;
|
||||
wikiPage["wiki_page"]["uploads"] = nlohmann::json::array();
|
||||
|
||||
if (!parentPage.empty())
|
||||
{
|
||||
wikiPage["wiki_page"]["parent_title"] = parentPage;
|
||||
}
|
||||
|
||||
for (auto attachment : attachments)
|
||||
{
|
||||
std::filesystem::path attachmentPath = attachment;
|
||||
if (!std::filesystem::exists(attachmentPath))
|
||||
{
|
||||
LOG_S(ERROR) << "Attachment " << attachmentPath.string() << " does not exist.";
|
||||
throw std::runtime_error("Attachment " + attachmentPath.string() + " does not exist.");
|
||||
}
|
||||
for (auto attachment : attachments) {
|
||||
std::filesystem::path attachmentPath = attachment;
|
||||
if (!std::filesystem::exists(attachmentPath)) {
|
||||
LOG_S(ERROR) << "Attachment " << attachmentPath.string()
|
||||
<< " does not exist.";
|
||||
throw std::runtime_error("Attachment " + attachmentPath.string() +
|
||||
" does not exist.");
|
||||
}
|
||||
|
||||
std::string token = upload(attachmentPath, attachmentPath.filename().string());
|
||||
nlohmann::json attachmentJson;
|
||||
attachmentJson["token"] = token;
|
||||
attachmentJson["filename"] = attachmentPath.filename().string();
|
||||
|
||||
wikiPage["wiki_page"]["uploads"].push_back(attachmentJson);
|
||||
}
|
||||
std::string token =
|
||||
upload(attachmentPath, attachmentPath.filename().string());
|
||||
nlohmann::json attachmentJson;
|
||||
attachmentJson["token"] = token;
|
||||
attachmentJson["filename"] = attachmentPath.filename().string();
|
||||
|
||||
put("/projects/" + projectIdentifier + "/wiki/" + page + ".json", wikiPage);
|
||||
wikiPage["wiki_page"]["uploads"].push_back(attachmentJson);
|
||||
}
|
||||
|
||||
put("/projects/" + projectIdentifier + "/wiki/" + page + ".json", wikiPage);
|
||||
}
|
||||
|
||||
void Redmine::API::updateWikiPage(const std::string& project, const std::string& page, const std::string &content)
|
||||
{
|
||||
std::vector<std::string> attachments;
|
||||
|
||||
updateWikiPage(project, page, content, attachments);
|
||||
void Redmine::API::updateWikiPage(
|
||||
const std::string &project, const std::string &page,
|
||||
const std::string &content, const std::string &parentPage) {
|
||||
std::vector<std::string> attachments;
|
||||
|
||||
updateWikiPage(project, page, content, parentPage, attachments);
|
||||
}
|
||||
|
||||
void Redmine::API::deleteWikiPage(const std::string& project, const std::string& page)
|
||||
|
Loading…
x
Reference in New Issue
Block a user