GithubHelp home page GithubHelp logo

wicker / slack-push-notify Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 64 KB

Super simple test of making a Slack integration that notifies about git pushes.

License: GNU General Public License v3.0

slack-push-notify's Introduction

Slack-Push-Notify

Slack app that notifies about git pushes.

Design Notes

Using the Slack Apps docs.

Created the app called Push-Notify on my workspace. For now, this will just be private to my workspace.

Features:

  • Uses as incoming webhook

Future:

  • Richly format the message
  • Supports slash commands
  • Add OAuth support

Incoming Webhooks

The app will look for a post-commit git webhook in the related repo, which is this one, for now. Webhooks are regular HTTP requests with a JSON payload.

Flipped the right switches in the Slack API. These are great docs so far...

Added a webhook to my workspace and tried the example:

curl -X POST -H 'Content-type: application/json' --data '{"text":"Hello, World!"}' <hook url here>

Hello World webhook screenshot

Adding Git Hook to Repository

Referring to Git documentation

The server-side post-push hook is called post-receive:

This hook is invoked by linkgit:git-receive-pack[1] when it reacts to `git push` and updates reference(s) in its repository. It executes on the remote repository once after all the refs have been updated.

Reviewed the git/contrib/hooks/multimail post-receive hook example.

Just use Bash for this for now to make that curl call.

We're exposing that webhook URL so there's a potential for abuse, but this is a demo for today and I'll disable the webhook in a few hours.

Here's the new post-receive webhook, chmodded to 755:

#!/bin/bash

echo Notifying Slack through Push-Notify app.

curl -X POST -H 'Content-type: application/json' --data '{"text":"Push-Notify repo has been updated."}' <hook url here>

Now to test the hook...

Interesting! It works when run in the terminal, but not when the README is updated and pushed. Here's the result in Slack from the terminal command:

Post-Receive Webhook from Terminal to Slack

Double checked permissions, which are correct.

This push has the README and a new image, so the post-receive hook should fire.

Oh! Code's on Github, which won't let me run server-side code. That's okay, though, for now I'll move it to a post-commit hook by changing the name of the file.

Test results: IT WORKS.

slack-push-notify's People

Watchers

 avatar James Cloos 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.