klothoplatform / slack-notifier Goto Github PK
View Code? Open in Web Editor NEWSlack notification bot
License: MIT License
Slack notification bot
License: MIT License
We currently have logic to get the botId with various methods and callbacks, but it's available already as an argument to the requests. Use that instead.
Really just some simple helpers and mocks, so that we can start writing good tests as we develop new features.
Copy/pasting the Slack convo for context and some ideas:
Gordon
@Yuval Shavit
maybe some kind of CD for ^ for when multiple people are commenting at the same time
Yuval Shavit
CD?
Gordon
sorry, CoolDown - a timer that disallows similar actions until it has elapsed
Yuval Shavit
ah, gotcha. Yeah, the problem is that in a lot of cases you don’t want that. If I post a question and then you post an answer very quickly, and then I say “ah cool, makes sense” — then I think you probably do want to see that ack.
Definitely not opposed to it (and I even called out this kind of notification-spam in my short doc on comment notifications), but I think it needs some thought as to what the desired behavior is.
Gordon
I guess it depends on the scenario - I use the slack comments to be like "hey, look at the PR again". If there's a lot of back-and-forth, I'm most likely already looking at it
Yuval Shavit
Yep, I agree completely — the trick is when is it “a lot”, as opposed to “ask a quick question, get a quick response.”
I’m definitely not saying we can’t draw the line — just that I haven’t yet put much thought into where that line is.
Gordon
Yeah, I think it's 1x back-and-forth = 👍 , > a couple (2?) then start to throttle messages
Gordon
some kind of heuristic like that
Yuval Shavit
Some of the nicer heuristics might require new klotho functionality, and specifically the ability to set a delay on subsub notifications. That would let us take the notifications and put them on a queue to be processed in 30 seconds (or whatever), and in the meanwhile we’ll have a better sense of the history
Gordon
oh, maybe instead of "last commenter" it could do something more like batching (after the first message, to keep it responsive for the quick case)
Yuval Shavit
yeah, that batching is exactly the kind of thing I mean 🙂
Gordon
so after the first one, wait until no comments for X minutes then a
gordon-klotho commented Y times on the PR
Yuval Shavit
yup, 💯
Gordon
well, doesn't have to be a queue per se just some data store that we can add & remove from
Yuval Shavit
I actually think that would not only be a great feature for the bot, but also a great way to incorporate a new capability into the app!
Gordon
like a DB :)
Yuval Shavit
how would you implement the “[wait] X minutes then [action]“?
Gordon
polling
Yuval Shavit
yuck 😛
Gordon
why yuck?
Yuval Shavit
well firstly it’ll be a good deal more expensive — it means we need to use fargate instead of lambda. Secondly, it forces an infra decision (fargate instead of lambda). And thirdly, event-driven is just nicer imo.
Gordon
Well, you can add polling to lambda, just not through Klotho (yet)
Gordon
Event-driven is okay, but how do you "reset" the timer when you get a new message? There's not really a clean way to do that in event-driven
Yuval Shavit
as in have one fire off every 1 minute or so to collect all the actions you need? yeah, you could do that.
Gordon
event-driven could actually have worse perf depending on how rapidly the commenting happens (say 1 comment per 30s vs polling every 5 minutes)
Yuval Shavit
I was thinking that you’d put the info into the DB right away, and then a message to the queue to basically say “check back on this in 30 seconds.”
So ultimately, it’s still polling, just with a different mechanism.
Yuval Shavit
so I retract my yuck. point is, it would require some functionality that klotho doesn’t yet have 🙂
Gordon
would be a good impetus for implementing such
Yuval Shavit
agreed!
Basically:
--- PR #21: Adds NestJS + Sequelize sample app (+17426/-0) by DavidSeptimus-Klotho
+++ PR KlothoPlatform/sample-apps#21: Adds NestJS + Sequelize sample app (+17426/-0) by DavidSeptimus-Klotho
That does make it feel like a lot of link, though:
PR KlothoPlatform/sample-apps#21: Adds NestJS + Sequelize sample app (+17426/-0) by DavidSeptimus-Klotho
Maybe this?
KlothoPlatform/sample-apps PR#21: Adds NestJS + Sequelize sample app (+17426/-0) by DavidSeptimus-Klotho
https://typescript-eslint.io/docs/
When I did this, I got a bunch of errors and warnings. Clean them up as part of this.
As little as is required to get a bot that:
Today, we just post the GH-flavored markdown into Slack's mrkdwn. It works for some of the basic stuff, but also often breaks.
This library could help: https://github.com/jsarafajr/slackify-markdown (and by "help" I mean "basically do it all for us").
This would probably also fix #44.
GitHub's webhooks are experiencing degraded performance right now, meaning that we're not getting notifications.
It'd be cool if the bot recognized that, and posted to the channel to give everyone a head's up.
Let's say you had a repo at Acme/foo-repo
, with a PR 123. If you rename Acme
to WidgetMakers
, then the bot loses track of the PR, and won't update its thread. It will just ignore all updates to that PR.
This is because we identify each PR by its URL, which includes the org name (afaik, there isn't any global PR identifier). When the org name changes, we can't find the original thread that the bot made, and without that it can't update or reply to it.
I believe this would apply to repo name changes too, though I haven't tested that.
If someone posts a PR for a public repo, Slack is able to pick up the page preview without any bot's help. It then attaches it to the message — and because the bot owns that message, we humans can't even remove it.
Hopefully there's a way to tell slack not to do that.
The most important are probably:
#123
-> link to issue/PR in same repoorg/reponame#123
-> link to issue/PR in that repoorg/reponame@sha
-> link to commit in that repoAlso add a comment in the thread
Today, we hard-code the channel id, and post updates from all repos to it.
It'd be nice to configure this on a per-channel basis. Something like:
/klothobot listen to CloudCompilers/klotho
and
/klothobot stop listening to CloudCompilers/klotho
and
/klothobot list repos
If event.pull_request.draft
is true
, then ignore it.
This seems to be a client issue.
Repro (maybe?)
Seems to be that the client caches the top-level message.
We may be able to fix this just by having the bot first update the top-level message, and then post the "PR was merged" message to the thread. This may satisfy the 2.ii.a condition, and thus work around the issue.
Need to find a way to correlate GH user -> Slack user (via email?).
Support when reviewers are added when the PR is posted as well as reviewers added after posting.
await this["handle_${event.action}"](channel, event)
(with safety checks if it's not found)onPrThread
take as an arg a new SlackIO
, which automatically adds the thread_id. I keep getting bitten by forgetting it in that context!There are two ways to view a diff:
The first one works if even you do the amend, but just shows the diff without context (ie without the PR it’s part of). The second shows it within the PR, but breaks if the left-side isn’t part of the PR’s current history — that is, if you squash/amended away a previous PR.
Ideally, the bot would be smart enough to use the PR-compare when it can, and the non-PR when it can't.
context: slack thread
If my commit message has something like this:
- fizz buzz
Then GH renders it as a list:
- fizz buzz
... but Slack renders it as just the literal -
text.
For example, klothoplatform/sample-apps#31 has the following title:
add `npm run <klotho | pulumi>` scripts
This got rendered as:
PR <https://github.com/klothoplatform/sample-apps/pull/31%7C#31: add npm run <klotho | pulumi> scripts> (+777/-0) by yuval-klotho
%7C
is |
, weirdly enough.
Anyway, we should properly escape these things. Would be good to write a general markdown-to-slack conversion (including escaping any slack-specific sequences). Related to #12.
All calls should be idempotent.
If the PR already has a thread_ts stored, we should just return success.
We should similarly check to see if the description message has been posted, and only post it if it hasn't been (or maybe if there hasn't been any reply in the thread?)
We currently hard-code the emoji, which is bad on two counts:
We should:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.