Compare commits
No commits in common. "8e72bedcf1547919794fda5aa1deab7487f44dc1" and "821dcdf277c40f9218a5d8c6ce109bd450b69d13" have entirely different histories.
8e72bedcf1
...
821dcdf277
75
README.md
75
README.md
@ -1,75 +0,0 @@
|
|||||||
# `bebot`
|
|
||||||
|
|
||||||
Bebot is a Gitlab webhook handler that publishes messages to Matrix when
|
|
||||||
interesting things happen in your configured repos.
|
|
||||||
|
|
||||||
Currently-supported Gitlab event types:
|
|
||||||
|
|
||||||
* Push events
|
|
||||||
* Tag push events
|
|
||||||
* Issue events
|
|
||||||
* Merge request events
|
|
||||||
* Pipeline events (only publishes on failure for now)
|
|
||||||
|
|
||||||
## Building
|
|
||||||
|
|
||||||
Bebot is written in Rust, and requires a Rust toolchain in order to
|
|
||||||
build. The usual `cargo build` or `cargo build --release` will do the
|
|
||||||
trick.
|
|
||||||
|
|
||||||
You can also build and install the latest released version of Bebot by
|
|
||||||
running `cargo install bebot`.
|
|
||||||
|
|
||||||
## Setup
|
|
||||||
|
|
||||||
Bebot requires a configuration file in YAML format. See
|
|
||||||
`sample-config.yaml` for all existing configuration options. They
|
|
||||||
should hopefully be fairly self-explanatory, but a few clarifications:
|
|
||||||
|
|
||||||
1. `bind_address` and `bind_port` determine what IP/interface and port
|
|
||||||
the webhook handler will listen on.
|
|
||||||
2. Bebot's webhook will be served from `/hooks/gitlab`. You can use
|
|
||||||
`url_prefix` to prepend further path segments in front of that.
|
|
||||||
3. `user_id` and `password` are for the Matrix user that the bot will
|
|
||||||
sign into Matrix as. Ensure that `user_id` is the full username,
|
|
||||||
including the homeserver.
|
|
||||||
4. `default_room` is the room that Bebot will publish to if not
|
|
||||||
specified in the per-repo configuration.
|
|
||||||
5. `repo_configs` is a map where the key is of the form
|
|
||||||
`$GITLAB_INSTANCE/$NAMESPACE/$REPO`. It is recommended that you use
|
|
||||||
a unique, randomly-generated `token` for each repository. You can
|
|
||||||
specify `room` here as well if you don't want messages to go to
|
|
||||||
`default_room`.
|
|
||||||
|
|
||||||
When setting up the webhook in Gitlab, use the same `token` from the
|
|
||||||
configuration file in the webhook's "Secret token" field. You should
|
|
||||||
only select "Push events", "Tag push events", "Issues events", "Merge
|
|
||||||
request events", and "Pipeline events". You can leave some of these out
|
|
||||||
if you don't want Bebot to publish messages for everything.
|
|
||||||
|
|
||||||
Bebot does not support serving the webhook over TLS, so you will
|
|
||||||
probably want to put it behind a reverse-proxy such as nginx.
|
|
||||||
|
|
||||||
In the `scripts` directory is a `set-webhook.py` script that can set up
|
|
||||||
(or update) webhooks for your repository, automatically generating a
|
|
||||||
token for you. If setting up the webhook for the first time, it will
|
|
||||||
output to stdout a YAML snippet that goes under the `repo_configs`
|
|
||||||
section of the configuration file. If you run the script with no
|
|
||||||
arguments, it will print out usage details.
|
|
||||||
|
|
||||||
## Running
|
|
||||||
|
|
||||||
After you've done all that, simply run Bebot:
|
|
||||||
|
|
||||||
```
|
|
||||||
bebot /path/to/config-file.yaml
|
|
||||||
```
|
|
||||||
|
|
||||||
You can set the `BEBOT_LOG` environment variable to increase or decrease
|
|
||||||
logging verbosity. (Try `debug`, `info`, `warn` `error`, or `off`.)
|
|
||||||
|
|
||||||
### Docker
|
|
||||||
|
|
||||||
A `Dockerfile` is also provided. When running the container it builds,
|
|
||||||
mount the configuration file so it appears inside the container as
|
|
||||||
`/bebot/config/bebot.yaml`.
|
|
@ -1,12 +0,0 @@
|
|||||||
bind_address: 127.0.0.1
|
|
||||||
bind_port: 3000
|
|
||||||
url_prefix: "/bebot"
|
|
||||||
user_id: "@mybebot:example.com"
|
|
||||||
password: "secret-matrix-account-password"
|
|
||||||
default_room: "#my-project-commits:example.com"
|
|
||||||
repo_configs:
|
|
||||||
"gitlab.example.com/myorg/my-cool-app":
|
|
||||||
token: "abcdefg12345"
|
|
||||||
"gitlab.example.com/myuser/some-other-less-cool-app":
|
|
||||||
room: "#my-other-room:example.com"
|
|
||||||
token: "kljaslkdjaklsdjalksd"
|
|
@ -202,8 +202,6 @@ pub enum GitlabEvent {
|
|||||||
user: User,
|
user: User,
|
||||||
project: Project,
|
project: Project,
|
||||||
},
|
},
|
||||||
#[serde(other)]
|
|
||||||
Other,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GitlabEventExt for GitlabEvent {
|
impl GitlabEventExt for GitlabEvent {
|
||||||
@ -214,7 +212,6 @@ impl GitlabEventExt for GitlabEvent {
|
|||||||
GitlabEvent::Issue { project, .. } => project,
|
GitlabEvent::Issue { project, .. } => project,
|
||||||
GitlabEvent::MergeRequest { project, .. } => &project,
|
GitlabEvent::MergeRequest { project, .. } => &project,
|
||||||
GitlabEvent::Pipeline { project, .. } => &project,
|
GitlabEvent::Pipeline { project, .. } => &project,
|
||||||
GitlabEvent::Other => unreachable!("Unsupported event type"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,7 +222,6 @@ impl GitlabEventExt for GitlabEvent {
|
|||||||
GitlabEvent::Issue { .. } => None,
|
GitlabEvent::Issue { .. } => None,
|
||||||
GitlabEvent::MergeRequest { object_attributes, .. } => Some(&object_attributes.target_branch),
|
GitlabEvent::MergeRequest { object_attributes, .. } => Some(&object_attributes.target_branch),
|
||||||
GitlabEvent::Pipeline { object_attributes, .. } => Some(&object_attributes.r#ref),
|
GitlabEvent::Pipeline { object_attributes, .. } => Some(&object_attributes.r#ref),
|
||||||
GitlabEvent::Other => unreachable!("Unsupported event type"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,7 +232,6 @@ impl GitlabEventExt for GitlabEvent {
|
|||||||
GitlabEvent::Issue { user, .. } => &user.name,
|
GitlabEvent::Issue { user, .. } => &user.name,
|
||||||
GitlabEvent::MergeRequest { user, .. } => &user.name,
|
GitlabEvent::MergeRequest { user, .. } => &user.name,
|
||||||
GitlabEvent::Pipeline { user, .. } => &user.name,
|
GitlabEvent::Pipeline { user, .. } => &user.name,
|
||||||
GitlabEvent::Other => unreachable!("Unsupported event type"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,7 +329,6 @@ impl GitlabEventExt for GitlabEvent {
|
|||||||
vec![]
|
vec![]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GitlabEvent::Other => unreachable!("Unsupported event type"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
src/main.rs
12
src/main.rs
@ -185,11 +185,6 @@ async fn run() -> anyhow::Result<()> {
|
|||||||
let event_tx = event_tx.clone();
|
let event_tx = event_tx.clone();
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
match event {
|
|
||||||
GitlabEvent::Other => {
|
|
||||||
warp::reply::with_status("Unsupported Gitlab event type", StatusCode::BAD_REQUEST)
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
let project = event.project();
|
let project = event.project();
|
||||||
let config_key = project.web_url.replace("http://", "").replace("https://", "");
|
let config_key = project.web_url.replace("http://", "").replace("https://", "");
|
||||||
if let Some(repo_config) = config.repo_configs.get(&config_key) {
|
if let Some(repo_config) = config.repo_configs.get(&config_key) {
|
||||||
@ -205,10 +200,7 @@ async fn run() -> anyhow::Result<()> {
|
|||||||
warp::reply::with_status("OK", StatusCode::OK)
|
warp::reply::with_status("OK", StatusCode::OK)
|
||||||
} else {
|
} else {
|
||||||
info!("Channel not configured for repo '{}'", config_key);
|
info!("Channel not configured for repo '{}'", config_key);
|
||||||
warp::reply::with_status(
|
warp::reply::with_status("Matrix room not configured for repo", StatusCode::NOT_FOUND)
|
||||||
"Matrix room not configured for repo",
|
|
||||||
StatusCode::NOT_FOUND,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -216,8 +208,6 @@ async fn run() -> anyhow::Result<()> {
|
|||||||
warp::reply::with_status("Repo not configured", StatusCode::NOT_FOUND)
|
warp::reply::with_status("Repo not configured", StatusCode::NOT_FOUND)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let routes = gitlab.with(warp::log("bebot"));
|
let routes = gitlab.with(warp::log("bebot"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user