Package: github-webhook-server
github-webhook-serverA Flask-based webhook server for managing GitHub repositories. It handles tasks such as repository setup, branch protection, and webhook configuration.Pre-build container images available in:quay.io/myakove/github-webhook-serverBuild containerWebhook server to manage GitHub repositories.
On start, it will configure the following for each repository:Set branch protection based on config.yamlPrivate repositories are not supported.Build containerUsing podman:podmanbuild--formatdocker-tgithub-webhook-server.Using docker:dockerbuild-tgithub-webhook-server.Setupexample.config.yamldocker-compose-example.yamlGetting startedSetupBefore running the application, ensure to set the following environment variables and configuration file:WEBHOOK_SERVER_LOG_FILE: Path to the log file where the server logs are to be stored.WEBHOOK_SERVER_DATA_DIR: Path to the data directory where theconfig.yamlfile is located.config.yaml: Configuration file that contains settings for the server and repositories, which should be placed in theWEBHOOK_SERVER_DATA_DIRdirectory.Follow the instructions to build the container using either podman or docker as described in the Build container section. Once that is done, proceed with the configurations outlined below.Config fileMinimum config to get startedgithub-app-id:123456webhook_ip:https://IP or FQDNgithub-toekns:-<GITHIB TOKEN1>repositories:my-repository-name:name:my-org/my-repository-nameprotected-branches:main:[]github-app-id: The ID of the GitHub app. Need to add the APP to the repository.name: repository full name (org or user/repository name)webhook_ip: Ip or FQDN where this app will run, this will be added as webhook in the repository settinggithub-toekns: List of admin users token for the repositoriesIfslack_webhook_urlconfigured for the repository a slack massages will be sent to the configured channel
about new releases to pypi, new containers that was pushedslack_webhook_url:https://hooks.slack.com/services/<channel>ifpypiconfigured for the repository a new version will be pushed to pypi on new GitHub releasetoken: pypi token with push permissionstool: The tool to use to build the package, can betwineorpoetrypypi:token:pypi-tokentool:twineiftoxconfigured for the repository a tox job will run on each push and new commitstox: The tox tests to run, can be set of tests separated by,orallto run all tests defined in tox.initox:allTop level array which define the defaults required check runs for all the repositoriesdefault-status-checks:-"WIP"-"dpulls"-"InclusiveLanguage",-"SonarCloudCodeAnalysis"-"can-be-merged"protected-branches:main:[]This tool configure branch protection and set required to be run for each branch to pass before the PR can be mergedif the repository have the file.pre-commit-config.yamlthenpre-commit.ci - prwill be added, can be excluded by
set it inexclude-runsprotected-branches: array of branches to set protectionbranch name: List of required to be run to set for the branch, when empty setdefault-status-checksas requiredinclude-runs: Only include those runs as requiredexclude-runs: Exclude those runs from thedefault-status-checksBy default, we create averified_jobrun, for each PR the owner needs to comment/verifiedto mark the PR as verified
In order to not add this job setverified_jobtofalseverified_job:falseifcontaineris configures for the repository we createbuild-containerrun that will build the container on each
PR push/commit
Once the PR is merged, the container will be build and push to the repositoryusername: User with push permissions to the repositorypassword: The password for the usernamerepository: the repository to push the container, for examplequay.io/myakove/github-webhook-servertag: The container tag to use when pushing the containercontainer:username:usernamepassword:passwordrepository:repository pathtag:latestIfdockeris configured for the repository we log in to docker.io to increase pull rate limitdocker:username:usernamepassword:passwordSupported actionsFollowing actions are done automatically:Add reviewers from OWNER fileSet PR size label.New issue is created for the PR.Issues get closed when PR is merged/closed.Supported user actions via adding comment/verified: to verify a PR/verified cancel: to undo verify/cherry-pick <target_branch_name>: cherry-pick a merged PR against a target branchMultiple target branches are allowed, separated by spacesIf the current PR is nor merged label will be added and once the PR is merged it will be cherry-picked/retest tox: run tox/retest build-container: run build-container/retest python-module-install: run python-module-install command/build-and-push-container: build and push container image (tag will be the PR number).Supported user labelsUsage:/<label name>: add a label to a PR/<label name> cancel: remove labelSupported labels:holdverifiedwiplgtmapproveNoteverified label removed on each new commit push.Cherry-picking is supported only on merged PRsIssuesNew issues can be created for this projecthereMain FunctionalitiesLogging SetupThe webhook server configures custom logging with color-coded log level names to enhance readability. It also supports optional logging to a file when 'WEBHOOK_SERVER_LOG_FILE' is set in the environment. This feature uses a rotating file handler to manage log rotation and is defined in theconstants.pyfile.Webhook CreationWebhooks are automatically created for GitHub repositories based on settings defined inwebhook.py. These webhooks enable real-time integration with GitHub events such as push, pull requests, and more.Usage GuideTo use the webhook server, first prepare theconfig.yamlfile with the necessary repository and server configurations. Set the required environment variables, includingWEBHOOK_SERVER_LOG_FILEandWEBHOOK_SERVER_DATA_DIR. Build and start the server using the instructions in the 'Build container' section.DevelopmentTo run locally you need to export some os environment variablespoetryinstallWEBHOOK_SERVER_DATA_DIR=/tmp/webhook_server_data

mkdir-p$WEBHOOK_SERVER_DATA_DIRcp-fwebhook-server.private-key.pem$WEBHOOK_SERVER_DATA_DIR/webhook-server.private-key.pem
cp-fconfig.yaml$WEBHOOK_SERVER_DATA_DIR/config.yamlexportWEBHOOK_SERVER_PORT=5003exportFLASK_DEBUG=1exportWEBHOOK_SERVER_DATA_DIR=$WEBHOOK_SERVER_DATA_DIRpoetryrunpythonwebhook_server_container/app.py