A Discord bot for using webhooks with GitLab (and extendable for other custom webhooks not yet built into Discord). Unlike it's parent fork this project allows you to integrate multiple gitlabs, multiple access-tokens (not related to the webhook's access-tokens) with specific source restriction, hyperlink, confidentiality and event filtering. To top it all off it now supports multiple webhooks instead of 1 for each bot instance.
- Push Events
- Issue Events
- Comment Events
- Commits
- Merge Requests
- Issues
- Code Snippets
- Merge Request Events
- Wiki Page Events
- Tag Events (Not yet)
- Pipeline Events (Not yet)
- Build Events (Not yet)
- Clone this repo
- Install NodeJS
- Navigate to the cloned repo
- Initialize the NodeJS app with npm install
- All of the dependencies listed in package.json should automatically be installed to node_modules/
- Install pm2 using
npm install pm2@latest -g
- Update pm2
# make a parent directory for containing the repo, if desired
mkdir my_bots
# navigate to your desired directory
cd my_bots
# either clone via HTTPS
git clone https://github.com/FlyingWraptor/discord-gitlab.git
# ... or clone via SSH
git clone [email protected]:FlyingWraptor/discord-gitlab.git
# navigate to the cloned repo
cd discord-gitlab
# install the app via NodeJS, using package.json
npm install
# install pm2
npm install pm2@latest -g
# update pm2
pm2 update
The package.json file includes the following dependencies:
- discordJS for integrating with Discord
- erlpack for much faster websockets
- pm2 for monitoring and maintaining uptime
- Create your Discord Bot at https://discordapp.com/developers/applications/me Keep this tab open so you can easily access Client ID and Client Secret
- Make your Discord app a Bot User by clicking the "Create Bot User" button in your app page settings.
- Calculated the desired permissions for your bot at https://discordapi.com/permissions.html (or use the default 536964096)
- Authorize your Discord Bot for your server using
https://discordapp.com/oauth2/authorize?client_id={YOUR_CLIENT_ID}&scope=bot&permissions={YOUR_CALCULATED_PERMISSIONS}
NOTE: if you get "Unexpected Error" then you probably forgot to turn your Discord App into a Bot User in Step 2. - In your local bot repo, copy the dev/require/config-example.json to dev/require/config.json and fill in the data according to the instructions
- In your local GitLab server, set up a new webhook using your chosen URL (server.address:server.port), and the webhook's token specified in your config file.
- Run the bot using
pm2 start server.js --name dg-bot
or simplynode server.js
if you don't want to use pm2 - Test the webhook by clicking the 'Test' button in GitLab's integrations page
Notify the master-user about new releases, to enable add the key 'application.updates': 'true'
Debug mode can be configured in the config file under the application key (application.debug)
Instead of keeping your secret bot-token in a file, you can choose to set up an environment variable and export it for use with the bot script.
echo $DG_BOT_TOKEN
export DG_BOT_TOKEN=MySecretDiscordBotToken
echo $DG_BOT_TOKEN
In your GitLab instance (either on the web or on your own server), go to Settings > Integrations
and find (or create) your webhook. Use the drop-down menu next to your webhook's details to test different event types.
Note that some events will require additional setup on your GitLab instance, such as a .gitlab-ci.yml
script for your Pipeline and Job events, and an initial wiki page for your wiki events.
Calling the bot is as easy as simply mentioning him with your command, this can be done in a channel readable by the bot, or simply in a private message.
@botname gl_bind <url> <access_token>
This command may only be send in a private-message to the bot, the user is required to post it's user gitlab-url aswell as an access-token for the specified user on the gitlab platform with 'read_user' access for verification purposes only, after the bind has been completed the user may (and is advised to) delete the token.
@botname gl_unbind <url>
This command will remove the gitlab user from your discord account meaning you will not be quoted anymore if you are mentioned in tasks.
@botname disconnect
Tell the bot to stay logged out for TIME milliseconds (default is 5 seconds, max is 1 hour). The bot should automatically log itself back in after TIME is up. Only the configured master user is allowed to use this command. No commands will be processed during the timeout, but the server will still attempt to listen for incoming HTTP requests (which the bot will process when it logs back in).
@botname embed TYPE
Sends an embedded message via webhook, using data read from the specified sample file. Also replies to the user to acknowledge receiving the command.
TYPE must be one of the properties of the SAMPLE object:
build
Reads fromsample/build.json
, which is the body of a GitLab Build Hookissue
Reads fromsample/issue.json
, which is the body of a GitLab Issue Hookmerge
Reads fromsample/merge.json
, which is the body of a GitLab Merge Request Hookcommit_comment
Reads fromsample/note-commit.json
, which is the body of a GitLab Note Hook for Commitsissue_comment
Reads fromsample/note-comment.json
, which is the body of a GitLab Note Hook for Issuesmerge_comment
Reads fromsample/note-merge.json
, which is the body of a GitLab Note Hook for Merge Requestssnippet
Reads fromsample/note-snippet.json
, which is the body of a GitLab Note Hook for Code Snippetspipeline
Reads fromsample/pipeline.json
, which is the body of a GitLab Pipeline Hookpush
Reads fromsample/push.json
, which is the body of a GitLab Push Hooktag
Reads fromsample/tag.json
, which is the body of a GitLab Tag Hookwiki
Reads fromsample/wiki.json
, which is the body of a GitLab Wiki Page Hook
@botname test
Sends an embedded message via webhook, using some placeholder RichEmbed data with Markdown formatting. Also replies to the user to acknowledge receiving the command.