{"id":13875886,"url":"https://github.com/RedL0tus/trigger","last_synced_at":"2025-07-16T10:32:11.394Z","repository":{"id":57670618,"uuid":"163705801","full_name":"RedL0tus/trigger","owner":"RedL0tus","description":"Yet another GitHub/GitLab webhook listener","archived":false,"fork":false,"pushed_at":"2023-01-04T07:29:23.000Z","size":88,"stargazers_count":28,"open_issues_count":0,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-19T08:53:54.449Z","etag":null,"topics":["github-webhook-listener","gitlab-webhooks","hyper","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RedL0tus.png","metadata":{"files":{"readme":"README-zh_CN.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-01T00:58:14.000Z","updated_at":"2024-10-06T20:04:28.000Z","dependencies_parsed_at":"2023-02-02T03:31:59.019Z","dependency_job_id":null,"html_url":"https://github.com/RedL0tus/trigger","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedL0tus%2Ftrigger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedL0tus%2Ftrigger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedL0tus%2Ftrigger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedL0tus%2Ftrigger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RedL0tus","download_url":"https://codeload.github.com/RedL0tus/trigger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226122303,"owners_count":17576920,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["github-webhook-listener","gitlab-webhooks","hyper","rust"],"created_at":"2024-08-06T06:00:48.935Z","updated_at":"2024-11-24T03:31:30.367Z","avatar_url":"https://github.com/RedL0tus.png","language":"Rust","readme":"trigger.rs\n==========\n\n[![license](https://img.shields.io/github/license/RedL0tus/trigger.svg)](LICENSE)\n[![crates.io](http://meritbadge.herokuapp.com/trigger)](https://crates.io/crates/trigger)\n[![Travis-CI](https://travis-ci.org/RedL0tus/trigger.svg?branch=master)](https://travis-ci.org/RedL0tus/trigger)\n\n[English(Chinglish)](README.md), **简体中文**\n\n\n又一个 GitHub/GitLab Webhook 监听轮子，根据收到的事件执行配置文件里设定的的 shell 命令。\n\n基于 [rifling](https://crates.io/crates/rifling)。\n\n安装\n-------\n\n - 使用 `cargo`：\n   ```bash\n   cargo install trigger\n   ```\n\n - 从 [GitHub release](https://github.com/RedL0tus/trigger/releases) 下载二进制（仅 Linux）, and move it to your `PATH`.\n\n使用方法\n--------\n\n命令行帮助信息：\n```bash\ntrigger --help\n```\n\n（暂时还没有中文的帮助输出）\n\n```\ntrigger 版本号\n\n又一个 GitHub/GitLab 监听程序\n\n使用方法:\n    trigger [选项]\n\nFLAGS:\n    -h, --help       打印帮助信息\n    -V, --version    打印版本信息\n\nOPTIONS:\n    -c, --config \u003c文件名\u003e    设置配置文件名（默认为： trigger.yaml）\n```\n\n启动 trigger：\n```bash\ntrigger --config \"\u003c配置文件的路径\u003e\"\n```\n\n或者启用 debug 日志：\n```bash\nTRIGGER_LOG=debug trigger --config \"\u003c配置文件的路径\u003e\"\n```\n\n此处的 debug 可以换成任意你想要的 log level（有 error、warn、info、debug、trace）。\n\n配置\n----\n\nTrigger 使用 YAML 格式的配置文件\n\n示例:\n\n```yaml\nsettings:\n  host: 0.0.0.0:4567    # 监听的地址\n  secret: \"secret\"      # GitHub/GitLab 上设置的密钥（可选）\n  print_commands: false # 是否打印命令（可选，默认为否）\n  capture_output: false # 是否捕捉命令的输出（可选，默认为否）\n  exit_on_error: true   # 是否在命令出错时退出（可选，命令为否）\n  kotomei: true         # 是否提醒你去提醒 @kotomei 去准备考试（可选，默认为是）\n\nevents:\n  common: |\n    set -e;\n    PAYLOAD='{payload}';\n    function get_prop {\n      echo $(echo ${PAYLOAD} | jq $1 | tr -d '\"');\n    }\n    SENDER=$(get_prop '.sender.login');\n    SENDER_ID=$(get_prop '.sender.id');\n  all: echo \"This command will be executed in all the events, the current event is {event}\";\n  push: echo \"User \\\"{SENDER}\\\" with ID \\\"{SENDER_ID}\\\" pushed to this repository\";\n  watch: |\n    ACTION=$(get_prop '.action');\n    echo \"GitHub user \\\"${SENDER}\\\" with ID \\\"${SENDER_ID}\\\" ${ACTION} watching this repository\";\n  else: echo \"\\\"${SENDER}\\\" with ID \\\"${SENDER_ID}\\\" sent {event} event\";\n```\n\n - 尽管密钥不是必须的，还是很建议设置一个。\n - `events.common` 里设置的命令在每次收到事件之后执行，可以在这里设置一些共用的函数等等。\n - `events.all` 里设置的命令会在收到任何事件之后执行。 \n - 所有可用的事件可以在[这里（GitHub, 英语）](https://developer.github.com/webhooks/#events)和[这里（GitLab，英语）](https://docs.gitlab.com/ee/user/project/integrations/webhooks.html#events)看到。\n   - 注意：设置使用 GitLab 相关的事件的时候需要把文档里列出的事件名称里的空格换成下划线，并且保证全小写。\n     - 比如文档中的 `Push Hook` 事件在设置里要写成 `push_hook`。\n - `events.else` 里设置的命令会在没有在配置里找到符合的事件时执行。\n - `{payload}` 占位符会在执行时被替换为未经解释的 payload body。\n   - 在使用是请用请用单引号包裹住它以免得出现问题（因为 JSON 里有使用双引号）。\n   - 可以使用 `jq` 来解析它，就像上面的示例里那样。\n - 其它的占位符（如果请求里没有对应的内容的话将会被替换为 `unknown`）：\n   - `{id}` 会被替换为事件的 UUID（仅 GitHub 会提供）。\n   - `{event}` 会被替换为事件的名称。\n   - `{signature}` 会被替换为请求的签名（GitHub 会使用 HMAC 算法进行签名，GitLab 则是直接明文传输设置的密钥）。\n   - `{request_body}` 会被替换为收到的请求的 body 部分（有可能是 `x-www-form-urlencoded` 的格式）。\n\n\n因为 trigger 本身不支持 HTTPS，建议使用 nginx 等等的逆向代理程序进行代理。\n```nginx\nlocation /hook {\n    proxy_pass http://0.0.0.0:4567/;\n}\n```\n\nDocker\n------\n\n1. 如果要在 Docker 中使用 trigger，先从 Docker Hub 获取镜像：\n    ```bash\n    docker pull kaymw/trigger\n    ```\n2. 像正常情况那样准备配置文件。\n3. 启动容器：\n    ```bash\n    docker run --volume $PWD:/work trigger trigger --config trigger.yaml\n    ```\n注意：这个 Docker 镜像的默认工作路径是 `/work`，默认端口为 `4567`，建议使用逆向代理程序代理。\n\n感谢: @musnow\n\n       \n其它 Snippets\n-------------\nSystemd unit (`trigger.service`):\n```systemd\n[Unit]\nDescription=Yet another GitHub Webhook listener\nAfter=network-online.target\n\n[Service]\nType=simple\nWorkingDirectory=/path/to/your/config/\nExecStart=/path/to/trigger /path/to/your/config/file.yaml\nRestart=always\nRestartSec=3\n\n[Install]\nWantedBy=multi-user.target\n\n# 　ｓｙ\n# ｓｔｅ\n# ｍｄ\n```\n\n许可信息与感谢\n--------------\n\nTrigger 以 MIT 协议进行授权，更多信息详见 [LICENSE](LICENSE) 文件。\n\n\nTrigger 使用 [pretty_env_logger](https://github.com/seanmonstar/pretty-env-logger) 和 [log](https://github.com/rust-lang-nursery/log) 输出 log。  \nTrigger 使用 [yaml-rust](https://github.com/chyh1990/yaml-rust) 来解析 YAML。  \nTrigger 使用 [hyper](https://github.com/hyperium/hyper) 来处理 HTTP 请求。  \nTrigger 使用 [run_script](https://github.com/sagiegurari/run_script) 执行 shell 脚本。 \n","funding_links":[],"categories":["Rust","rust"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRedL0tus%2Ftrigger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRedL0tus%2Ftrigger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRedL0tus%2Ftrigger/lists"}