Testing
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";
// Change "triggerdotdev/github-stars-to-slack" to the repo you want to track e.g. "yourorg/yourrepo"
const repo =
process.env.GITHUB_REPOSITORY ?? "triggerdotdev/github-stars-to-slack";
new Trigger({
// Give your Trigger a stable ID
id: "github-stars-to-slack",
name: "GitHub Stars to Slack",
// This will register a webhook with the repo
// and trigger whenever the repo gets a new star
on: github.events.newStarEvent({
repo,
}),
// The run function will get called once per "new star" event
// See https://docs.trigger.dev/integrations/apis/github/events/new-star
run: async (event) => {
// Posts a new message to the "github-stars" slack channel.
// See https://docs.trigger.dev/integrations/apis/slack/actions/post-message
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();
You can easily create a new project interactively based on this template by running:
npx create-trigger@latest github-stars-to-slack
# or
yarn create trigger github-stars-to-slack
# or
pnpm create trigger@latest github-stars-to-slack
Follow the instructions in the CLI to get up and running locally in <30s.
- 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.
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: