This is a Python bot that monitors your GitHub repositories for new commits and posts updates to Mastodon. The bot periodically checks for new commits in your repositories and, if a new commit is detected, it sends a post to your Mastodon account with a link to the commit on GitHub.
The bot uses the GitHub API to fetch the latest commit SHA for each repository and compares it with the last known commit SHA. If a new commit is found, it generates a post with the commit URL and sends it to your Mastodon account using the Mastodon API.
-
Make sure you have Python installed on your system. If not, download and install Python from the official website: https://www.python.org/downloads/
-
Clone this repository to your local machine:
git clone https://github.com/your-github-username/github-to-mastodon-bot.git
cd github-to-mastodon-bot
- Install the required libraries using pip:
pip install requests
pip install Mastodon.py
- Configure the bot:
Open github_to_mastodon_bot.py in a text editor.
Replace the placeholders with your actual GitHub username and access token, as well as your Mastodon instance URL and access token.
python github_to_mastodon_bot.py
The bot will now start monitoring your GitHub repositories and posting updates to Mastodon when new commits are detected.
To use this bot, you need a GitHub Personal Access Token to authenticate API requests. Follow these steps to get your access token:
-
Log in to your GitHub account.
-
Go to your GitHub settings by clicking on your profile picture in the top right corner and selecting "Settings."
-
In the left sidebar, click on "Developer settings."
-
From the "Developer settings" menu, click on "Personal access tokens."
-
Click the "Generate new token" button.
-
Give your token a name, select the desired scopes (usually "repo" is enough for this bot), and click "Generate token."
-
Copy the generated token and use it as your GITHUB_ACCESS_TOKEN in the bot's configuration.
To post updates to Mastodon, you need an access token for your Mastodon account. Here's how you can obtain it:
-
Log in to your Mastodon account on your instance.
-
Go to "Preferences" > "Development" > "Your applications" (or something similar depending on your instance).
-
Click on "New application" or "Create an application."
-
Fill in the required fields. For the redirect URI, you can use any valid URI (e.g., "https://example.com").
-
Click "Submit" or "Create application."
-
The access token will be generated. Copy the access token and use it as your MASTODON_ACCESS_TOKEN in the bot's configuration.
Log in to your Mastodon account on your instance.
Go to "Preferences" > "Development" > "Your applications" (or something similar depending on your instance).
Click on "New application" or "Create an application."
Fill in the required fields. For the redirect URI, you can use any valid URI (e.g., "https://example.com").
Click "Submit" or "Create application."
The access token will be generated. Copy the access token and use it as your MASTODON_ACCESS_TOKEN in the bot's configuration.