Categorygithub.com/s3kkt/github-releases-bot

# README

GitHub updates watcher for Telegram

Motivation

We often use fixed versions of opensource code when describing our infrastructure as a code to avoid accidental updates.
When there are a lot of such repositories used, it becomes almost impossible to keep track of updates, so this tool appeared.
Of course, you can subscribe to RSS feeds or e-mail notifications, but this is not applicable for team work.

Project based on go-telegram-bot-api.

You can add my telegram bot or run your own.

Requirements:

  • GitHub account to access API
  • Telegram account to interact with Telegram API
  • Postgresql instance to store Bot data
  • Docker
  • Golang 1.20

Configuration

You can use both config.yml and environment variables to set up github-releases-bot. If environment variables set, they are prior.

Get GitHub token

Use the official GitHub documentation to create your personal token.

Get Telegram token

According to the official Telegram documentation:

Creating a new bot Use the /newbot command to create a new bot. @BotFather will ask you for a name and username, then generate an authentication token for your new bot.

  • The name of your bot is displayed in contact details and elsewhere.
  • The username is a short name, used in search, mentions and t.me links. Usernames are 5-32 characters long and not case sensitive – but may only include Latin characters, numbers, and underscores. Your bot's username must end in 'bot’, like 'tetris_bot' or 'TetrisBot'.
  • The token is a string, like 110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw, which is required to authorize the bot and send requests to the Bot API. Keep your token secure and store it safely, it can be used by anyone to control your bot.

config.yml example

# your GitHub token with read repos rights
github_token: "*****"

# telegram token given by BotFather
telegram_token: "*****"

# set `debug` to `true` to view debug messages from go-telegram-bot-api
debug: false

# Interval to chech repos updates. Be careful! There are GitHub API limitations in 5000 requests per hour.
update_interval: 10m

# Database settings. For now only Postgres is supported.
database:
  user: "github-bot"
  pass: "VeryStrongPassword"
  host: "127.0.0.1"
  port: 5432
  dbname: "github-bot-db"

Environment variables

All config settings can be overwritten by environment variables

Config keyEnvironment variableType
github_tokenBOT_GITHUB_TOKENstring
telegram_tokenBOT_TELEGRAM_TOKENstring
debugBOT_DEBUGbool
update_intervalBOT_UPDATE_INTERVALtime in s(seconds), h(hours), d(days)
database.userBOT_DB_USERstring
database.passBOT_DB_PASSstring
database.hostBOT_DB_HOSTstring
database.portBOT_DB_PORTint
database.dbnameBOT_DB_NAMEstring

Flags

FlagDescriptionDefault
-configpath to .yml config file-
-migrationsif true, only migrations will be applied, bot will not startfalse
-cloudif true, bot will use database connection string formatted to use Google cloud SQL instance, described in main.tffalse

Database

For now only Postgres is supported. github-releases-bot needs minimal instance of Postgres (2 CPU cores, 4 GB RAM, 5 GB disk).

Migrations

Before we start we need to prepare database. To run migrations you can:

  1. Install go migrations package and run migrations manually:
git clone https://github.com/s3kkt/github-releases-bot.git && cd github-releases-bot
go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
export DB_URL="postgres://<db-user>:<password>@<db-host>:<db-port>/<db-name>?sslmode=disable"
migrate -database ${DB_URL} -path ./internal/database/migrations up

Run bot

Docker-compose

You can run test installation of github-releases-bot via docker-compose.

  1. Prepare bot environment variables as described above and put it in configs/.env subfolder of this project
  2. Check your database port
  3. Run docker-compose up command:
docker-compose up -d --build

Docker

To start production variant of github-releases-bot in docker with dedicated Postgres instance, follow this simple steps:

  1. Prepare database as described above
  2. Run following command:
docker run -v <path-to config.yml>:/etc/gh-bot/config.yml s3kkt/github-releases-bot:latest -config="/etc/gh-bot/config.yml"

or use environment variables:

docker run --env-file <path to .env file> s3kkt/github-releases-bot:latest

Google Cloud Platform

ToDo

Known issues

  1. Latest release database table is not updating when rolling back GitHub release
  2. Bot does not work in group chats for now :(

# Packages

No description provided by the author