Coder Social home page Coder Social logo

slack-bitbucket-bot's Introduction

slack-bitbucket-bot

A python 3 bot for posting updates about unanswered comments on bitbucket in a slack channel.

Docker instructions

Slack and Bitbucket setup

If you haven't already you will need to Create a new Slack app with appropriate permissions. Additionally you will need to create a Bitbucket App password with the appropriate permissions.

Environment variables

See .env.example. Otherwise your .env should look like so:

SLACK_OAUTH=someoauthkeyorsomethingidunno
SLACK_CHANNEL=engineeering
BITBUCKET_USER=SomeUser
BITBUCKET_PASS=SomeAppPassword
BITBUCKET_WORKSPACES=BitbucketWorkspace1,BitbucketWorkspace2
POST_TIME=12:00

POST_TIME is in UTC

Build and Run

docker build -t slack-bb-bot .
docker run --env-file .env slack-bb-bot

Non-docker instructions

Python dependencies

Install the following dependencies via pip:

pip install requests
pip install slack_sdk
pip install schedule

config.json

config.json describes the local configuration for the bot. It has three required fields:

  1. workspaces - This is an array of strings. Each string corresponds to a BitBucket workspace to monitor.
  2. channel - This is a single string. It corresponds to the slack channel the bot will post digests in.
  3. time - This is a single string. It correponds to a single time of day that the bot will run.

For example, if we wanted to get information about workspace BitbucketWorskpace1 at noon every day and post it in the engineering channel, config.json would look like this:

{
	"bitbucket_workspaces": [
		"BitbucketWorkspace1"
	],
	"slack_channel": "engineering",
	"post_time": "12:00"
}

config.json should be placed in the same directory as main.py

Setting up the Slack integration

Currently the bot only works for one (1) slack workspace at a time. I don't feel like setting up a full OAuth flow so if you want more, just run multiple instances of the bot.

First go to the Slack Apps Page and click Create New App

Then go to OAuth and Permissions on the new app's dashboard and enable the chat:write and chat:write.public permissions.

Finally go to Install App and install the app to your workspace. The provided OAuth token should be exported as the environment variable SLACK_OAUTH. Add the following line to .env in the same directory as main.py:

export SLACK_OAUTH=someoauthkeyorsomethingidunno

The bot is now ready to send messages to Slack.

Setting up the Bitbucket integration

You will need a Bitbucket username and a corresponding app password with the correct permissions. Navigate to the app password page on your profile and create a new app password.

Enable read permissions for Projects, Repositories, Pull Requests, Account, Workspace Membership, and Issues. Give the app password a name and write it down.

Add both your bitbucket username and app password to the BITBUCKET_USER and BITBUCKET_PASS environment variables respectively, or add the following lines to the .env file:

export BITBUCKET_USER=SomeUser
export BITBUCKET_PASS=SomeAppPassword

Running the bot

You can either run main.py directly with the correct environment variables defined or, if using .env, you can execute the included run.sh script to pull the environment variables in and run the bot with the correct command-line arguments.

slack-bitbucket-bot's People

Contributors

ethanwillis avatar

Watchers

Clark Van Oyen avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.