diff --git a/sample-config.yaml b/sample-config.yaml
index ee2ef20..a5dd940 100644
--- a/sample-config.yaml
+++ b/sample-config.yaml
@@ -2,57 +2,59 @@
bind_address: 127.0.0.1
# Port the webhook listener should bind to (default is 3000).
bind_port: 3000
-# Optional prefix to serve the webhook path under (default is empty string).
-url_prefix: "/bebot"
# Matrix user to sign in as.
user_id: "@mybebot:example.com"
# Password for Matrix user.
password: "secret-matrix-account-password"
-# Default Matrix room to publish events to.
-default_room: "#my-project-commits:example.com"
-# Default set of events to publish. If left out, all events will be published.
-default_publish_events:
- - name: push
- # Regexes of branch names. Leave out entirely for "all branches".
- branches:
- - '^main$'
- - '^xfce-.+'
- - name: tag_push
- - name: issues
- # See the Gitlab docs for a full list of actions. If left out, all actions
- # will be published.
- actions:
- - open
- - close
- - name: merge_request
- # See the Gitlab docs for a full list of actions. If left out, all actions
- # will be published.
- actions:
- - open
- - merge
- - name: pipeline
- # See the Gitlab docs for a full list of statuses. If left out, all
- # actions will be published.
- statuses:
- - failed
-# Key-value configuration for repositories.
-repo_configs:
- # Keys are the instance name / namespace / repository name
- "gitlab.example.com/myorg/my-cool-app":
- # Each repository should use a unique, randomly-generated token. Enter
- # this token in the webhook configuration's "Secret token" on Gitlab.
- token: "abcdefg12345"
- # You can override the default_room above. Leave out to use the default.
- room: "#my-cool-app-events:example.com"
- # You can override default_events above. Leave out this section to
- # use the defaults.
- publish_events:
- - name: push
- branches:
- - main
- - name: pipeline
- statuses:
- - failed
- "gitlab.example.com/myuser/some-other-less-cool-app":
- token: "kljaslkdjaklsdjalksd"
- # This repo uses the default events and room.
+# All Gitlab-specific settings are under here.
+gitlab:
+ # Optional prefix to serve the webhook path under (default is empty string).
+ url_prefix: "/bebot"
+ # Default Matrix room to publish Gitlab events to.
+ default_room: "#my-project-commits:example.com"
+ # Default set of events to publish. If left out, all events will be published.
+ default_publish_events:
+ - name: push
+ # Regexes of branch names. Leave out entirely for "all branches".
+ branches:
+ - '^main$'
+ - '^xfce-.+'
+ - name: tag_push
+ - name: issues
+ # See the Gitlab docs for a full list of actions. If left out, all actions
+ # will be published.
+ actions:
+ - open
+ - close
+ - name: merge_request
+ # See the Gitlab docs for a full list of actions. If left out, all actions
+ # will be published.
+ actions:
+ - open
+ - merge
+ - name: pipeline
+ # See the Gitlab docs for a full list of statuses. If left out, all
+ # actions will be published.
+ statuses:
+ - failed
+ # Key-value configuration for repositories.
+ repo_configs:
+ # Keys are the instance name / namespace / repository name
+ "gitlab.example.com/myorg/my-cool-app":
+ # Each repository should use a unique, randomly-generated token. Enter
+ # this token in the webhook configuration's "Secret token" on Gitlab.
+ token: "abcdefg12345"
+ # You can override the default_room above. Leave out to use the default.
+ room: "#my-cool-app-events:example.com"
+ # You can override default_events above. Leave out this section to
+ # use the defaults.
+ publish_events:
+ - name: push
+ branches:
+ - main
+ - name: pipeline
+ statuses:
+ - failed
+ "gitlab.example.com/myuser/some-other-less-cool-app":
+ token: "kljaslkdjaklsdjalksd"
+ # This repo uses the default events and room.
diff --git a/src/config.rs b/src/config.rs
index 0a856e3..60512c9 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -14,14 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
-use std::{collections::HashMap, fmt, fs::File, io::BufReader};
+use std::{collections::HashMap, fs::File, io::BufReader};
use anyhow::Context;
-use matrix_sdk::ruma::{OwnedRoomOrAliasId, OwnedUserId, RoomOrAliasId, UserId};
+use matrix_sdk::ruma::{OwnedRoomOrAliasId, OwnedUserId};
use regex::Regex;
-use serde::de;
-use crate::event::{IssueAction, MergeRequestAction, PipelineStatus};
+use crate::gitlab_event::{IssueAction, MergeRequestAction, PipelineStatus};
#[derive(Deserialize)]
#[serde(tag = "name", rename_all = "snake_case")]
@@ -47,111 +46,30 @@ pub enum PublishEvent {
pub struct RepoConfig {
pub token: String,
#[serde(default)]
- #[serde(deserialize_with = "deser_optional_room_or_alias_id")]
+ #[serde(deserialize_with = "crate::matrix::deser_optional_room_or_alias_id")]
pub room: Option,
pub publish_events: Option>,
}
#[derive(Deserialize)]
-pub struct Config {
- pub bind_address: Option,
- pub bind_port: Option,
+pub struct GitlabConfig {
pub url_prefix: Option,
- #[serde(deserialize_with = "deser_user_id")]
- pub user_id: OwnedUserId,
- pub password: String,
#[serde(default)]
- #[serde(deserialize_with = "deser_optional_room_or_alias_id")]
+ #[serde(deserialize_with = "crate::matrix::deser_optional_room_or_alias_id")]
pub default_room: Option,
pub default_publish_events: Option>,
pub repo_configs: HashMap, // key is repo url without scheme; e.g.
// gitlab.xfce.org/xfce/xfdesktop
}
-fn deser_user_id<'de, D>(deserializer: D) -> Result
-where
- D: de::Deserializer<'de>,
-{
- struct UserIdVisitor;
-
- impl<'de> de::Visitor<'de> for UserIdVisitor {
- type Value = OwnedUserId;
-
- fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
- formatter.write_str("a matrix user ID")
- }
-
- fn visit_str(self, v: &str) -> Result
- where
- E: de::Error,
- {
- UserId::parse(v).map_err(E::custom)
- }
- }
-
- deserializer.deserialize_any(UserIdVisitor)
-}
-
-fn deser_room_or_alias_id<'de, D>(deserializer: D) -> Result
-where
- D: de::Deserializer<'de>,
-{
- struct RoomOrAliasIdVisitor;
-
- impl<'de> de::Visitor<'de> for RoomOrAliasIdVisitor {
- type Value = OwnedRoomOrAliasId;
-
- fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
- formatter.write_str("a matrix room ID")
- }
-
- fn visit_str(self, v: &str) -> Result
- where
- E: de::Error,
- {
- RoomOrAliasId::parse(v).map_err(E::custom)
- }
- }
-
- deserializer.deserialize_any(RoomOrAliasIdVisitor)
-}
-
-fn deser_optional_room_or_alias_id<'de, D>(deserializer: D) -> Result