slack icon indicating copy to clipboard operation
slack copied to clipboard

Subscribe to File Modification

Open dw2kim opened this issue 5 years ago • 5 comments

I am reopening the below issue.

It was closed by inactivity but there are still many people desiring this feature including myself.

https://github.com/integrations/slack/issues/437#issue-303451005

dw2kim avatar Aug 26 '20 02:08 dw2kim

Thanks for opening this issue! If you would like to help implement an improvement, read more about contributing and consider submitting a pull request.

welcome[bot] avatar Aug 26 '20 02:08 welcome[bot]

@dw2kim and others, 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

alice-engi avatar Oct 01 '20 16:10 alice-engi

@alice-engi Awesome. Thank you

dw2kim avatar Oct 05 '20 15:10 dw2kim

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.

stale[bot] avatar Jan 09 '22 02:01 stale[bot]

The NotiFunction App is no longer working so yes, I guess this is still relevant

Kvn91 avatar Aug 30 '22 12:08 Kvn91

+1

rohennes avatar Nov 07 '22 15:11 rohennes