Coder Social home page Coder Social logo

manomanotech / homer Goto Github PK

View Code? Open in Web Editor NEW
29.0 7.0 6.0 1.69 MB

Homer is a Slack bot intended to help you to easily share and follow Gitlab merge requests.

License: MIT License

JavaScript 0.99% Shell 0.02% TypeScript 98.90% Dockerfile 0.09%
gitlab slack slack-bot slackbot

homer's Introduction

CI badge

Homer

Homer

Homer is a Slack bot intended to help you to easily share and follow Gitlab merge requests.

Why Homer?

At ManoMano, we were a bit tired of reading Gitlab emails to try keeping up to date with merge request updates.

Since we use Slack, we decided to create a bot that would help us to share our merge requests to other developers and to track their progress, so we could merge them more quickly:

Slack message

How does it work?

Homer communicates with both Slack and Gitlab to get merge request information and publish Slack messages.

Architecture Architecture

Usage

Commands

Here are the available commands:

Command Description
/homer changelog Display changelogs, for any Gitlab project, between 2 release tags.
/homer project add <project_name|project_id> Add a Gitlab project to a channel.
/homer project list List the Gitlab projects added to a channel.
/homer project remove Remove a Gitlab project from a channel.
/homer release Create a release for configured Gitlab project in a channel.
/homer review <search> Share a merge request on a channel.
Searches in title and description by default.
Accepts merge request URLs and merge request IDs prefixed with "!".
/homer review list List ongoing reviews shared in a channel.

Share a merge request using Homer

To share a merge request in a Slack channel using Homer, you have to follow the following steps:

1. Make Homer notified of changes happening in the Gitlab project

To keep up to date the Slack messages it creates, Homer needs to be notified when something occurs on the related merge requests.

To do so, you need to set up a webhook in the Gitlab project of your merge request:

  • Ask for Homer's GITLAB_SECRET to the person that manages Homer in your organisation.

  • Go to the Webhooks setting page of your Gitlab project.

    Webhooks menu

  • Enter the following URL: HOMER_BASE_URL/api/v1/homer/gitlab.

    HOMER_BASE_URL should also be provided by the person that manages Homer in your organisation.

    Webhook URL

  • Enter the value of GITLAB_SECRET in Secret token field.

    Webhook secret

  • Check the following checkboxes: Push events, Comments, Merge request events.

    Webhook secret

  • Click on the Add webhook button on the bottom of the page.

    Webhook secret

  • Make sure that the Gitlab user linked to your GITLAB_TOKEN has at least the Developer role in your project:

    • Go to the Projects members page:

      Members menu

    • Use the search bar to find the information of the user.

    • Check that the role in Max role is at least Developer.

2. Add the Gitlab project to a Slack channel

If it is the first time that you share a merge request of the Gitlab project in a Slack channel, you have to link them.

Inside the Slack channel, run one of the following commands:

  • /homer project add PROJECT_ID
  • /homer project add PROJECT_NAME

Warning

If you want to use Homer in a private channel, you need to invite it to the channel first.

3. Share the merge request

To share a Gitlab merge request to a Slack channel, use the /homer review <search> command.

You can provide a merge request ID prefixed with !, e.g.: /homer review !128.

If you want to get an overview of merge requests that are still being reviewed (meaning they are not merged yet), use /homer review list.

Install

Warning

Currently, Homer can only be installed by manually cloning the git repository.

1. Create the Slack app

  • Go to https://api.slack.com/apps/.

  • Click on Create New App.

    Create New App

  • Select From an app manifest.

    From app manifest

  • Select the right workspace and click on Next.

    Select workspace

  • Copy the content of manifest.json file and paste it in the Slack webapp modal.

    Manifest modal

  • Create the app and enjoy.

2. Add Slack emojis

Homer uses custom emojis when posting messages. To have them properly displayed, you will need to add all the emojis under emojis to your Slack organisation.

Customize menu

3. Prerequisites

Be sure to have all those installed:

4. Set the necessary environment variables

Create a .env file containing the following variables:

  • API_BASE_PATH

    This is the base path that will be used to build the API URL to call homer, for example https://homer.com<API_BASE_PATH>/command.

  • GITLAB_SECRET

    This is a user generated secret, so you can put any value.

    It will be used later to set up Gitlab webhooks to allow Homer to verify that Gitlab→Homer calls are authentic.

  • GITLAB_TOKEN

    If you don't already have one, you need to create a project access token on Gitlab by following the dedicated documentation.

    This token allows Homer to use the Gitlab API.

  • SLACK_SIGNING_SECRET

    • Go to the Slack apps page of your organisation.

    • Click on your app.

    • Find Signin Secret input in App credentials section.

      Signin secret

    This secret allows Homer to verify that Slack→Homer calls are authentic.

  • SLACK_BOT_USER_O_AUTH_ACCESS_TOKEN

    • Go to the Slack apps page of your organisation.

    • Click on your app.

    • Click on OAuth & Permissions in Features menu.

      OAuth menu

    • Copy the Bot User OAuth Token.

      OAuth token

  • EMAIL_DOMAINS

    Email domains of your organization (separated by comma), for instance my-domain.com,ext.my-domain.com. Used to find Slack users from Gitlab username. Note that this means your org has to use the same naming scheme for emails and gitlab username.

  • GITLAB_URL

    The gitlab URL of your organization

  • TICKET_MANAGEMENT_URL_PATTERN

    The ticket management URL pattern for your organization, this is used to generate a link to the ticket in the changelog. It must contain the {ticketId} matcher to be replaced by the ticket ID, for instance https://my-ticket-management.com/view/{ticketId}.

If you want Homer to connect to an external PostgreSQL database, you can set the following variables:

  • POSTGRES_DATABASE_NAME: database name (like homer).
  • POSTGRES_HOST: host of the database.
  • POSTGRES_PASSWORD: password used when connecting to the database.
  • POSTGRES_PORT: port where the database listens.
  • POSTGRES_USER: username used when connecting to the database.

5. Install and run

# Clone the repo
git clone https://github.com/ManoManoTech/homer.git

# Go to directory that was just created
cd homer

# Install yarn dependencies
yarn install

# Start the database Docker container
docker compose up -d

# Build Homer
yarn build

# Start Homer
yarn start

To check that Homer is working properly, you can go to http://localhost:3000/api/monitoring/healthcheck and check that a donut is displayed.

6. Make your local instance of Homer reachable from outside

  • On another terminal, open an HTTP bridge using ngrok: npx ngrok http localhost:3000.

  • Copy the Forwarding URL (ex: https://d59a-176-179-182-210.ngrok.io).

  • Go to the Slack apps page of your organisation.

  • Click on your app.

  • Click on Interactivity & Shortcuts in Features menu.

    Interactivity menu

  • In Request URL, replace https://HOMER_BASE_URL by the URL you copied above.

    Interactivity URL

  • Click on Save Change button.

    Interactivity save button

  • Click on Slash Commands in Features menu.

    Slash menu

  • Click on edit button.

    Slash edit button

  • In Request URL, replace https://HOMER_BASE_URL by the URL you copied above.

    Slash URL

  • Click on Save button.

    Slash save button

You should now be able to use Homer commands on Slack 🎉

Contributing

See CONTRIBUTING.md.

homer's People

Contributors

josselinbuils avatar greg0ire avatar cicoub13 avatar fleboulch avatar eliebleton-manomano avatar m0nkeysan avatar pfongkye avatar

Stargazers

Maxime Stevenot avatar Bastien Cer avatar  avatar jpinfinity avatar Maxime Grébauval avatar Pierrick V avatar  avatar Audric.S avatar Charles Brossollet avatar Lluís avatar Alba Artal avatar Aurélien Lajoie avatar Arnaud Forgues avatar  avatar Marcos de la Calle avatar Jocelyn N'TAKPE avatar Salva Roig avatar Hike avatar apailleau avatar Miguel avatar Marc Brillault avatar Alex Lombry avatar Jose Boretto avatar Cesar Santos avatar  avatar Arnaud Querrec avatar Farsen ABDALLAH COMBO avatar Kévin Mathieu avatar  avatar

Watchers

 avatar jpinfinity avatar  avatar Jules Duvivier avatar  avatar  avatar Jose Maria Elías avatar

homer's Issues

Open source the release and changelog feature

What

In the current Manomano internal project, homer offers the option of publishing and displaying a project's change log using the following commands :

  • /homer changelog Generate changelogs for any Gitlab project using release tags.
  • /homer release Create a Gitlab release.
  • /homer release cancel Cancel a Gitlab release.
  • /homer release end End a Gitlab release.

These functionalities should be reviewed and modified to make them available in the open-source project.

How

In order to add a releasable project, an internal configuration file must be modified. This behaviour needs to be reviewed to simplify the process and avoid the need to redeploy homer each time.

Firstly, we should externalise this configuration, and write documentation about it.
Then we could add a command like /homer release enable to register a new releaseable project.

The current configuration is as follows:

{
    notificationChannelIds: [
      IT_DEPLOY_CHANNEL_ID,
      FT_SELLER_CHANNEL_ID,
    ],
    projectId: 1,
    releaseChannelId: FT_SELLER_CHANNEL_ID,
    releaseManager: defaultReleaseManager,
    releaseTagManager: semanticReleaseTagManager,
  },

projectId : Gitlab project ID
notificationChannelIds : ID of the Slack channels that receive notifications about the release
releaseChannelId : ID of the slack channel where the release of the project is enabled
releaseManager : change depending on the type of the project (library, micro-service, frontend ..)
releaseTagManager : defines the tag naming (semantic, stable date ...)

The modal could be like this :

image

Generate calendar

Not sure how feasible this is, but it might be nice to be able to generate a calendar (an ICS file) of the releases.

GITLAB_URL not loaded properly

When using the docker image internally at my company, the GITLAB_URL does not seem to load properly.

Steps to reproduce on internal Gitlab:

  • Pull image from GitHub and build another one in internal Gitlab.
  • Run the image on Gitlab pipeline with all env variables set.

An error in log mentioning Environment variable GITLAB_URL not found

Reviewer Roulette

I've stumbled upon this project today and was wondering: wouldn't it be possible to implement mechanism for drawing reviewers? In larger teams it would be great if every member was involved at similar level, so this should draw reviewers considering review history and current activity. But MVP would be just ability to run command that would draw expected amount of reviewers.

List of users available for review should be configurable per project, as I don't see any reliable way based on available data (Slack channel's participant, Gitlab project's members would most probably be much wider than people interested in the MR), maybe CODEOWNERS would be closest.

What do you think?

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.