This repo contains a GitHub newStarEvent Trigger that will run whenever the specified repository gets a new ⭐️:
import { Trigger } from "@trigger.dev/sdk";
import * as github from "@trigger.dev/github";
import * as slack from "@trigger.dev/slack";
const repo =
process.env.GITHUB_REPOSITORY ?? "triggerdotdev/github-stars-to-slack";
new Trigger({
id: "github-stars-to-slack",
name: "GitHub Stars to Slack",
on: github.events.newStarEvent({
repo,
}),
run: async (event) => {
await slack.postMessage("⭐️", {
channelName: "github-stars",
text: `New GitHub star from \n<${event.sender.html_url}|${event.sender.login}>. You now have ${event.repository.stargazers_count} stars!`,
});
},
}).listen();
- Make sure and update the
repo
parameter to point to a GitHub repository you manage by setting theGITHUB_REPOSITORY
environment variable. - Feel free to customize postMessage call with more data from the newStar Event and change the channel name.
We've made it really easy to deploy this repo to Render.com, if you don't already have a Node.js server to host your triggers.
Render.com is a super-fast way to deploy webapps and servers (think of it like a modern Heroku)
Note Make sure you use your "live" trigger.dev API Key when deploying to a server
First, in your terminal of choice, clone the repo and install dependencies:
git clone https://github.com/Pranav2612000/trigger.dev-test.git
cd trigger.dev-test
npm install
Then create a .env
file at the root of the repository (it's already gitignored) with your development Trigger.dev API Key and GITHUB_REPOSITORY:
TRIGGER_API_KEY=<your api key>
GITHUB_REPOSITORY=<your github repository> # e.g. triggerdotdev/trigger.dev
And finally you are ready to run the process:
npm run dev
You should see a message like the following:
[trigger.dev] ✨ Connected and listening for events [github-stars-to-slack]
After successfully running this template locally, head over to your Trigger.dev Dashboard and you should see your newly created workflow:
Click on the workflow in the list and you should come to the Workflow overview page, with a message detailing that you need to authenticate to GitHub to register the webhook for the newStarEvent:
After connecting to your GitHub account, you'll be redirected back to your Workflow Overview page and the message should be gone (you sometimes need to refresh a few times because we register the webhook in the background):
If you head over to your repo, you should see the newly registered webhook:
The easiest way to fire off the newStarEvent
is to go ahead and star the repo (in this case it's this repo). Head back to the Workflow Overview page and you should see a run is in progress:
Navigate to the Run Details page (by clicking on the run in the list) and you'll notice the "post message to github-stars" step has paused, waiting for your Slack authentication:
Once you authenticate your Slack workspace, the run will pickup where it left off and post the message:
Head over to slack to see your newly created message: