Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
90a1e2d
Revert "Handle missing chats properly"
linyinfeng Sep 22, 2025
95ef6b0
Refactor repository management
linyinfeng Sep 21, 2025
c04c083
WIP
linyinfeng Sep 22, 2025
acd5ef2
Full refactor
linyinfeng Sep 22, 2025
1a0f903
Better repo creation test
linyinfeng Sep 22, 2025
407a86c
Better default repo settings
linyinfeng Sep 22, 2025
dfde2e1
Fix repo remove
linyinfeng Sep 22, 2025
d5fa7b9
Small fixes
linyinfeng Sep 22, 2025
9994971
Fix branch regex
linyinfeng Sep 22, 2025
a79071a
Add bracket to regex templates
linyinfeng Sep 22, 2025
0331f3e
Enforce allow list
linyinfeng Sep 22, 2025
317ae23
Fix duplicated message
linyinfeng Sep 22, 2025
9750f30
Lock poll refactor
linyinfeng Sep 22, 2025
b2ec20d
Add index for cache
linyinfeng Sep 22, 2025
41dcac7
Check PR closing
linyinfeng Sep 22, 2025
5439d9f
Issue tracking
linyinfeng Sep 22, 2025
5c4b795
Add alias for pr_issues
linyinfeng Sep 22, 2025
704eeb7
Refactor more "pull requests" to "pr/issues"
linyinfeng Sep 22, 2025
fcdfc05
Improve message format
linyinfeng Sep 22, 2025
61c07c9
Fix pr check logic
linyinfeng Sep 23, 2025
3c4a787
Improve command interface
linyinfeng Sep 23, 2025
a44f2a1
Better help text
linyinfeng Sep 23, 2025
2f3f30a
flake.lock: Update
linyinfeng Sep 23, 2025
1a729d1
Bump version and cargo update
linyinfeng Sep 23, 2025
16d5325
Report all clap errors in expandable blockquote
linyinfeng Sep 23, 2025
a01c3b9
Cleanup dependencies
linyinfeng Sep 23, 2025
25eb1d2
Basic migration guide and version check
linyinfeng Sep 23, 2025
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
43 changes: 30 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
name = "commit-notifier"
authors = [ "Lin Yinfeng <lin.yinfeng@outlook.com>" ]
version = "0.1.3"
version = "0.2.0"
edition = "2024"
description = """
A simple bot tracking commits in branches
A simple bot tracking git commits/PRs/issues/branches
"""

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -22,12 +22,13 @@ thiserror = "*"
clap = { version = "*", features = [ "cargo", "derive" ] }
regex = "*"
serde_json = "*"
serde_regex = "*"
serde = "*"
cron = "*"
chrono = "*"
once_cell = "*"
fs4 = "*"
octocrab = "*"
url = "*"
scopeguard = "*"
lockable = "*"
version-compare = "*"
76 changes: 70 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ A simple telegram bot monitoring commit status.
```console
$ commit-notifier" \
--working-dir /var/lib/commit-notifier \
--cron "0 */5 * * * *"
--cron "0 */5 * * * *" \
--admin-chat-id="{YOUR_ADMIN_CHAT_ID}"
```

Automatic check will be triggered based on the cron expression. In the example, `0 */5 * * * *` means "at every 5th minute". cron documentation: <https://docs.rs/cron/latest/cron>.
Expand All @@ -44,6 +45,7 @@ My instance: <https://github.com/linyinfeng/dotfiles/blob/main/nixos/profiles/se
services.commit-notifier = {
enable = true;
cron = "0 */5 * * * *";
adminChatId = "{YOUR_ADMIN_CHAT_ID}";
tokenFiles = {
telegramBot = /path/to/telegram/bot/token;
github = /path/to/github/token;
Expand Down Expand Up @@ -71,7 +73,7 @@ The telegram bot has only one command `/notifier`. But this command provides a f

## Allow List

Since the bot can clone any git repository into its working directory, only manually allowed users/groups can access the bot.
Currently the bot use `GITHUB_TOKEN` to check status for issues/pull requests, so only manually allowed users/groups can access the bot.

The bot in a new chat returns this kind of error:

Expand All @@ -92,15 +94,77 @@ Currently, the bot does not have an admin interface in telegram. So adding chats
* For direct chat:

```console
$ cd {WORKING_DIR}
$ mkdir 888888888 # chat id
$ mkdir -p {WORKING_DIR}/chats/888888888 # chat id
```

* For group chat

```console
$ cd {WORKING_DIR}
$ mkdir _1008888888888 # chat id (replace "-" with "_")
$ mkdir -p {WORKING_DIR}/chats/_1008888888888 # chat id (replace "-" with "_")
```

**Make sure the new directory is writable by `commit-notifier`.** All data (repositories, settings, check results) related to the chat will be saved in the directory.

## Migration Guide

### From `0.1.x` to `0.2.0`

There are several differences between `0.1.x` and `0.2.x`.

* In `0.1.x`, chats data are saved at `{WORKING_DIR}`; in `0.2.x`, chats data are saved in `{WORKING_DIR}/chats`.
* In `0.1.x`, repositories and their settings are managed by every chat; in `0.2.x`, repositories and their settings are saved in `{WORKING_DIR}/repositories`, and can only managed by the admin chat. Also, in `0.2.x`, repositories are shared between all chats.
* In `0.1.x`, caches are built in a per-commit manner; in `0.2.x`, caches are built in a per-branch manner, including every branch matches `--branch-regex`.

#### How to migrate

1. Backup old `{WORKING_DIR}` to `{BACKUP_DIR}`.
2. Start the bot.
3. Check old configurations in `{BACKUP_DIR}`, find all repositories.
4. In admin chat, manually run `/notifier repo-add ...` for each repositories.
5. Properly configure each repositories.

* Use `/notifier repo-edit ...` to set branch regex. Use `/notifier condition-add ...` to set conditions.

* Or just edit `repositories/{REPO_NAME}/settings.json` manually.

<details>
<summary>An example configuration for nixpkgs</summary>

```json
{
"branch_regex": "^(master|nixos-unstable|nixpkgs-unstable|staging|release-\\d\\d\\.\\d\\d|nixos-\\d\\d\\.\\d\\d)$",
"github_info": {
"owner": "nixos",
"repo": "nixpkgs"
},
"conditions": {
"in-nixos-release": {
"condition": {
"InBranch": {
"branch_regex": "^nixos-\\d\\d\\.\\d\\d$"
}
}
},
"in-nixos-unstable": {
"condition": {
"InBranch": {
"branch_regex": "^nixos-unstable$"
}
}
},
"master-to-staging": {
"condition": {
"SuppressFromTo": {
"from_regex": "main",
"to_regex": "staging(-next)?"
}
}
}
}
}
```

</details>

6. Wait for the first update (first-time cache building can be slow). Restart the bot to trigger update immediately.
7. Restore chat configurations. `rsync --recursive {BACKUP_DIR}/ {WORKING_DIR}/chats/ --exclude cache.sqlite --exclude lock --exclude repo --verbose` (trailing `/` is important.)
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion nixos/commit-notifier.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ in {
Update cron expression.
'';
};
adminChatId = lib.mkOption {
type = lib.types.str;
description = ''
Chat id of the admin chat.
'';
};
tokenFiles = {
telegramBot = lib.mkOption {
type = lib.types.str;
Expand Down Expand Up @@ -61,7 +67,8 @@ in {

"${cfg.package}/bin/commit-notifier" \
--working-dir /var/lib/commit-notifier \
--cron "${cfg.cron}"
--cron "${cfg.cron}" \
--admin-chat-id="${cfg.adminChatId}"
'';

path = [
Expand Down
53 changes: 0 additions & 53 deletions src/cache.rs

This file was deleted.

Loading