#pragma once #include #include #include #include #include #include #include struct ProjectSettings { // *** Administrative settings *** // IRC channel to announce to std::string channel; // name extracted from notify/$user std::string credential_name; // Authorized accounts can edit the event list std::set authorized_accounts; // *** User settings *** // Events to announce std::set events; // Whether to announce events bool enabled; auto to_toml() const -> toml::table; static auto from_toml(const toml::table &v) -> ProjectSettings; }; struct WebhookSettings { std::string host; std::string service; std::map credentials; std::map projects; auto to_toml() const -> toml::table; static auto from_toml(const toml::table &v) -> WebhookSettings; }; struct WebhookEvent { std::string channel; std::string message; }; class GithubWebhook { // IRC connection to announce on; could be empty std::shared_ptr connection_; // Buffered events in case connection was inactive when event was received std::vector events_; // Actually write the event to the connection. // Only call when there is a connection. auto write_event(WebhookEvent event) -> void; public: WebhookSettings settings_; GithubWebhook(WebhookSettings settings) : settings_(std::move(settings)) { } // Either emit the event now or save it until a connection is set auto add_event(WebhookEvent event) -> void { if (connection_) { write_event(std::move(event)); } else { events_.emplace_back(std::move(event)); } } auto set_connection(std::shared_ptr connection) -> void { connection_ = std::move(connection); for (auto &&event : events_) { write_event(event); } events_.clear(); } auto clear_connection() -> void { connection_.reset(); } }; auto start_webhook(boost::asio::io_context &io, const char *) -> std::shared_ptr;