Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: banish catppuccin/userstyles to the shadow realm #37

Merged
merged 2 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,42 @@ the following environment variables are required:
- `GITHUB_WEBHOOK_SECRET`: the secret you chose when you created the json webhook
- `DISCORD_WEBHOOK`: the regular discord webhook url
- `DISCORD_BOT_WEBHOOK`: the discord webhook url for bot-authored events
- `DISCORD_USERSTYLES_WEBHOOK`: the discord webhook url for all non-bot events on [catppuccin/userstyles](https://github.com/catppuccin/userstyles).
- `DISCORD_ERROR_WEBHOOK`: the discord webhook url for errors

the following environment variables are optional:

- `PORT`: the port to listen on (default: 3000)

## development

To learn how to forward webhook events to a local instance of rockdove, follow the instructions below:

1. Ensure your `.envrc` has the environment variables listed above in the [configuration](#configuration) section.
2. Compile a release build of rockdove and run it:

```shell
cargo build --release
./target/release/rockdove
```

3. Install the `gh` cli webhook forward extension:

```shell
gh extension install cli/gh-webhook
```

4. Allow `gh cli` to create organisation webhooks on your behalf:

```shell
gh auth refresh -h github.com -s admin:org_hook
```

5. Forward the webhook events to your local instance of rockdove:

```shell
gh webhook forward --events='*' --org=catppuccin --url="http://localhost:3000/webhook"
```

6. Finally, visit the [GitHub webhook settings](https://github.com/organizations/catppuccin/settings/hooks)
and paste the `GITHUB_WEBHOOK_SECRET` into the newly created development webhook.
8 changes: 0 additions & 8 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ _default:
listen:
python3 server.py

# Requires the following commands to be run first:
# - gh extension install cli/gh-webhook
# - gh auth refresh -h github.com -s admin:org_hook
#
# Create a development GitHub webhook and forward all webhook events to http://localhost:3000
register_webhook:
gh webhook forward --events='*' --org=catppuccin-rfc --url="http://localhost:3000"

# Create a new issue, close and reopen it in catppuccin-rfc/polybar
issues:
#!/usr/bin/env bash
Expand Down
13 changes: 13 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct Config {
github_webhook_secret: String,
discord_webhook: String,
discord_bot_webhook: String,
discord_userstyles_webhook: String,
discord_error_webhook: String,
#[serde(default = "default_port")]
port: u16,
Expand All @@ -38,6 +39,7 @@ const fn default_port() -> u16 {
struct DiscordHooks {
normal: String,
bot: String,
userstyles: String,
error: String,
}

Expand Down Expand Up @@ -72,6 +74,7 @@ async fn main() -> anyhow::Result<()> {
discord_hooks: DiscordHooks {
normal: config.discord_webhook,
bot: config.discord_bot_webhook,
userstyles: config.discord_userstyles_webhook,
error: config.discord_error_webhook,
},
github_token: GithubToken(Arc::new(config.github_webhook_secret)),
Expand All @@ -92,6 +95,7 @@ async fn main() -> anyhow::Result<()> {
enum HookTarget {
Normal,
Bot,
Userstyles,
None,
}

Expand Down Expand Up @@ -124,6 +128,10 @@ async fn webhook(
info!("hook target is bot");
&app_state.discord_hooks.bot
}
HookTarget::Userstyles => {
info!("hook target is userstyles");
&app_state.discord_hooks.userstyles
}
HookTarget::None => {
info!("no target - ignoring event");
return;
Expand All @@ -148,6 +156,11 @@ fn hook_target(event: &WebhookEvent) -> HookTarget {
}

if let Some(repository) = &event.repository {
// userstyles is a monorepo with a lot of activity so we're adding a separate redirect for it.
if repository.name == "userstyles" {
return HookTarget::Userstyles;
}

if repository.private.unwrap_or(false) {
info!("ignoring private repository event");
return HookTarget::None;
Expand Down