A GitHub webhook that watches GitHub Issue and Pull Request comments for /prombench <event> [<version>] [<options>]
commands.
On each command it dispatches appropriate repository_dispatch
event to configured repository and notifies the same issue/PR.
See Prometheus GitHub action that responses to prombench comment-monitor dispatches.
Currently, it only supports the issue_comment
event, which can be triggered by either issue or PR.
- Environment Variables
- Setting Up the Webhook Server
- Setting Up the GitHub Webhook
- Extracting Arguments
- Usage and Examples
- Building Docker Image
GITHUB_TOKEN
: GitHub OAuth token used for posting comments and setting labels.- Any other environment variable used within the comment templates in
config.yml
.
To specify the configuration file for comment-monitor
, use the --config
flag.
prefixes:
- prefix: /prombench
help_template: |
Get prombench syntax help here.
eventmaps:
- event_type: prombench_stop
regex_string: (?mi)^/prombench\s+cancel\s*$
comment_template: |
Benchmark cancel is in progress.
label: prombench
How It Works:
- Comments are first checked to see if they start with any of the prefixes specified in
prefixes
. If not, the request is dropped. - If the prefix is matched, but the subsequent content does not match the
regex_string
, a comment with thehelp_template
for that prefix is posted back to the issue/PR. - If a comment matches the
regex_string
,comment-monitor
will trigger arepository_dispatch
event with the specifiedevent_type
. - A comment will also be posted to the issue/PR with the
comment_template
. - Any arguments extracted by the
regex_string
will be passed to theclient_payload
of therepository_dispatch
event.
-
Create a Personal Access Token:
- Generate a personal access token with the scopes
public_repo
andwrite:discussion
. - Set the environment variable
GITHUB_TOKEN
to this token.
- Generate a personal access token with the scopes
-
Configure the Webhook:
- Set the webhook server URL as the webhook URL in the repository settings.
- Set the content type to
application/json
.
- The
regex_string
inconfig.yml
is used to parse comments into separate arguments. - Some internal arguments are automatically set, such as
PR_NUMBER
andLAST_COMMIT_SHA
. - If the
regex_string
includes capturing groups, you must use named groups so that each comment argument is named after the corresponding regex group.
Example:
The following regex creates an argument named RELEASE
:
(?mi)^/prombench\s*(?P<RELEASE>master|main|v[0-9]+\.[0-9]+\.[0-9]+\S*)\s*$
usage: commentMonitor [<flags>]
commentMonitor GitHub Action - Post and monitor GitHub comments.
Flags:
-h, --help Show context-sensitive help (also try --help-long and --help-man).
--webhooksecretfile="./whsecret" Path to webhook secret file.
--config="./config.yml" Filepath to config file.
--port="8080" Port number to run webhook on.
To build the Docker image for comment-monitor
:
docker build -t prominfra/comment-monitor:master .