@litebox-packages/release-notes-bot
v1.3.1
Published
Automated release notes generator using GitLab API and OpenAI
Maintainers
Readme
Release Notes Bot
Automated release notes generator supporting GitLab and GitHub APIs.
How It Works
The script analyzes changes between two Git commits and generates human-readable release notes using AI. Here's what happens when you run it:
Fetches Git Changes: Connects to the GitLab or GitHub API (based on
--platform) to retrieve commits, file changes, and diffs between the specified commit hashes (--beforeand--after).Detects Context: Identifies whether the changes represent a merge request or a single commit, extracting relevant branch and commit information.
Filters & Sanitizes: Removes asset files (images, fonts, etc.) and unnecessary metadata from the diff data to optimize token usage.
Estimates Costs: Calculates estimated token usage and API costs before making the LLM call, so you know what to expect.
Generates Release Notes: Sends the processed commit data to OpenAI's GPT-4o-mini model, which analyzes the changes and generates formatted release notes with:
- Summary of changes
- Categorized features, fixes, and improvements
- Emojis for visual clarity
- Markdown formatting
Displays Results: Shows the generated release notes in the console, along with actual token usage and costs.
Sends to Slack (optional): If Slack credentials are provided, automatically posts the release notes to the specified channel or user, formatted with Slack Block Kit for better readability.
Setup
- Install dependencies:
pnpm install- Build the project:
pnpm buildUsage
Using npx (Recommended - No installation needed)
GitLab Example:
npx -p @litebox-packages/release-notes-bot release-notes-bot --platform gitlab --before <commit-hash-1> --after <commit-hash-2> --projectId <gitlab-project-id> --token <gitlab-token> --openaiToken <openai-token> --slackToken <slack-token> --slackChannelId <slack-channel-id>GitHub Example:
npx -p @litebox-packages/release-notes-bot release-notes-bot --platform github --before <commit-hash-1> --after <commit-hash-2> --owner <owner> --repo <repo> --token <github-token> --openaiToken <openai-token> --slackToken <slack-token> --slackChannelId <slack-channel-id>Option 2: Direct npx (may require clearing cache)
npx @litebox-packages/release-notes-bot --platform gitlab --before <commit-hash-1> --after <commit-hash-2> --projectId <gitlab-project-id> --token <gitlab-token> --openaiToken <openai-token> --slackToken <slack-token> --slackChannelId <slack-channel-id>If Option 2 doesn't work, try clearing npx cache:
rm -rf ~/.npm/_npxDevelopment Mode (using ts-node)
GitLab:
pnpm dev --platform gitlab --before <commit-hash-1> --after <commit-hash-2> --projectId <gitlab-project-id> --token <gitlab-token> --openaiToken <openai-token> --slackToken <slack-token> --slackChannelId <slack-channel-id>GitHub:
pnpm dev --platform github --before <commit-hash-1> --after <commit-hash-2> --owner <owner> --repo <repo> --token <github-token> --openaiToken <openai-token> --slackToken <slack-token> --slackChannelId <slack-channel-id>Production Mode (after building)
GitLab:
pnpm start --platform gitlab --before <commit-hash-1> --after <commit-hash-2> --projectId <gitlab-project-id> --token <gitlab-token> --openaiToken <openai-token> --slackToken <slack-token> --slackChannelId <slack-channel-id>GitHub:
pnpm start --platform github --before <commit-hash-1> --after <commit-hash-2> --owner <owner> --repo <repo> --token <github-token> --openaiToken <openai-token> --slackToken <slack-token> --slackChannelId <slack-channel-id>Or directly with node:
node dist/cli.js --platform gitlab --before <commit-hash-1> --after <commit-hash-2> --projectId <gitlab-project-id> --token <gitlab-token> --openaiToken <openai-token> --slackToken <slack-token> --slackChannelId <slack-channel-id>Getting Required Tokens
GitLab Personal Access Token
To get your GitLab personal access token:
- Go to your GitLab instance (e.g.,
https://gitlab.comor your self-hosted instance) - Click on your profile picture/avatar in the top right corner
- Select Settings (or Preferences)
- In the left sidebar, click Access Tokens
- Give your token a name (e.g., "Release Notes Bot")
- Set an expiration date (optional)
- Select the
apiscope (required) - Click Create personal access token
- Copy the token immediately - you won't be able to see it again!
The token will start with glpat- for GitLab.com or your instance's prefix.
GitHub Personal Access Token
To get your GitHub personal access token:
- Go to https://github.com/settings/tokens
- Click Generate new token → Generate new token (classic)
- Give your token a name (e.g., "Release Notes Bot")
- Set an expiration date (optional)
- Select the
reposcope (required for private repositories)- For public repositories, you can use a token without any scopes, but
reposcope is recommended
- For public repositories, you can use a token without any scopes, but
- Click Generate token
- Copy the token immediately - you won't be able to see it again!
The token will be a long alphanumeric string (no specific prefix).
OpenAI API Key
- Go to https://platform.openai.com/api-keys
- Sign in or create an account
- Click Create new secret key
- Give it a name (e.g., "Release Notes Bot")
- Copy the key immediately - you won't be able to see it again!
The key will start with sk-.
Slack Bot Token (Optional)
- Go to https://api.slack.com/apps
- Create a new app or select an existing one
- Go to OAuth & Permissions in the left sidebar
- Under Bot Token Scopes, add
chat:writepermission - Install the app to your workspace
- Copy the Bot User OAuth Token (starts with
xoxb-)
To get the Channel ID:
- Right-click on the channel in Slack → View channel details → Copy the Channel ID (starts with
C) - For DMs, use the user's ID (starts with
U)
Arguments
Common Arguments (Required)
--platform: Platform to use - eithergitlaborgithub(default:gitlab)--before: The commit hash to compare from (older commit)--after: The commit hash to compare to (newer commit)--token: Your Git provider personal access token (GitLab or GitHub)--openaiToken: Your OpenAI API key (starts withsk-)
GitLab-Specific Arguments (Required when --platform gitlab)
--projectId: Your GitLab project ID (can be found in project settings)
GitHub-Specific Arguments (Required when --platform github)
--owner: Repository owner (username or organization name)--repo: Repository name
Optional Arguments
--slackToken: Your Slack bot token (starts withxoxb-). If provided,--slackChannelIdis also required.--slackChannelId: Slack channel ID or user DM ID where release notes will be sent. Required if--slackTokenis provided. Slack failures are non-fatal and will only log a warning.
Examples
GitLab Example
npx -p @litebox-packages/release-notes-bot release-notes-bot --platform gitlab --before abc123 --after def456 --projectId 12345 --token glpat-xxxxxxxxxxxxx --openaiToken sk-xxxxxxxxxxxxx --slackToken xoxb-xxxxxxxxxxxxx --slackChannelId C09TVLQ33HNGitHub Example
npx -p @litebox-packages/release-notes-bot release-notes-bot --platform github --before abc123 --after def456 --owner octocat --repo Hello-World --token ghp_xxxxxxxxxxxxx --openaiToken sk-xxxxxxxxxxxxx --slackToken xoxb-xxxxxxxxxxxxx --slackChannelId C09TVLQ33HNLocal Development (GitLab)
pnpm dev --platform gitlab --before abc123 --after def456 --projectId 12345 --token glpat-xxxxxxxxxxxxx --openaiToken sk-xxxxxxxxxxxxx --slackToken xoxb-xxxxxxxxxxxxx --slackChannelId C09TVLQ33HNLocal Development (GitHub)
pnpm dev --platform github --before abc123 --after def456 --owner octocat --repo Hello-World --token ghp_xxxxxxxxxxxxx --openaiToken sk-xxxxxxxxxxxxx --slackToken xoxb-xxxxxxxxxxxxx --slackChannelId C09TVLQ33HNCI/CD Integration
GitLab CI Integration
In your .gitlab-ci.yml, you can use it like this:
generate-release-notes:
script:
- npx -p @litebox-packages/release-notes-bot release-notes-bot --platform gitlab --before "$CI_COMMIT_BEFORE_SHA" --after "$CI_COMMIT_SHA" --projectId "$CI_PROJECT_ID" --token "$GITLAB_TOKEN" --openaiToken "$OPENAI_TOKEN" --slackToken "$SLACK_TOKEN" --slackChannelId "$SLACK_CHANNEL_ID"GitHub Actions Integration
In your .github/workflows/release-notes.yml, you can use it like this:
name: Generate Release Notes
on:
push:
branches:
- main
jobs:
generate-release-notes:
runs-on: ubuntu-latest
steps:
- name: Generate Release Notes
run: |
npx -p @litebox-packages/release-notes-bot release-notes-bot \
--platform github \
--before "${{ github.event.before }}" \
--after "${{ github.sha }}" \
--owner "${{ github.repository_owner }}" \
--repo "${{ github.event.repository.name }}" \
--token "${{ secrets.GITHUB_TOKEN }}" \
--openaiToken "${{ secrets.OPENAI_TOKEN }}" \
--slackToken "${{ secrets.SLACK_TOKEN }}" \
--slackChannelId "${{ secrets.SLACK_CHANNEL_ID }}"