Slack: Subscribe to file modifications on a branch

Created on 8 Mar 2018  路  5Comments  路  Source: integrations/slack

I would love to see a feautre where it is possible to subscribe to specific CHANGES to a file, when pushed to a branch.

We have a CHANGELOG.md file in the root of our repository, and would love to automatically push notifications to slack when that file changes (with a diff for example, but just the fact that it happened would be awesome as well.)

subscription feature wontfix

Most helpful comment

I'm looking for this exact feature! I keep getting this result in Google when searching for tricks to notify myself when a certain file was changed.

All 5 comments

Is this still relevant? If so, just comment with any updates and we'll leave it open. Otherwise, if there is no further activity, it will be closed.

I'm looking for this exact feature! I keep getting this result in Google when searching for tricks to notify myself when a certain file was changed.

+1 on this request

+1 on this request

Reposting from #1062:

If you need notifications about a changed file, you can use NotiFunction App and create notification with this code:

// If this file is changed - it will trigger the notification
const FILE_TO_WATCH = 'README.md'

// This is where notification will go to
// could be a channel or a person's email.
const CHANNEL = '#test'

// Reacts to "push" event
// https://docs.github.com/developers/webhooks-and-events/webhook-events-and-payloads#push
exports.handler = async (input) => {
    let changedFiles = []

    // Iterate over commits in a push and collect modified files
    input.commits.forEach(c => {
        changedFiles = changedFiles.concat(c.modified)
    })

    // If our file is modified - send a notification
    // otherwise do nothing
    if (changedFiles.includes(FILE_TO_WATCH)) {
        return buildMessage(input)
    }
}

// Function that generates a Slack message
function buildMessage(input) {
    return {
        to: CHANNEL,
        text: `${FILE_TO_WATCH} was changed by ${input.sender.login}: ${input.compare}`
    }
}

Then connect it to the "push" event from github to send notifications like this:

notification-example

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dbuskariol picture dbuskariol  路  4Comments

derwasp picture derwasp  路  4Comments

sean-ahn picture sean-ahn  路  5Comments

bkeepers picture bkeepers  路  5Comments

EyeCandyEyewear picture EyeCandyEyewear  路  5Comments