Skip to content

jessie-young/trigger.dev-github-stars-to-slack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

✨ Trigger.dev GitHub Stars to Slack

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();

🔧 Install

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.

✍️ Customize

  1. Make sure and update the repo parameter to point to a GitHub repository you manage by setting the GITHUB_REPOSITORY environment variable.
  2. Feel free to customize postMessage call with more data from the newStar Event and change the channel name.

🧪 Test it

After successfully running this template locally, head over to your Trigger.dev Dashboard and you should see your newly created workflow:

workflow list

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:

workflow overview

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):

workflow connected

If you head over to your repo, you should see the newly registered webhook:

webhook registered

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:

workflow run started

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:

slack auth

Once you authenticate your Slack workspace, the run will pickup where it left off and post the message:

post message

Head over to slack to see your newly created message:

slack message

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published