ericallam / github-stars-staging-1

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

✨ Trigger.dev GitHub Stars to Slack

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

✍️ 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.

🚀 Deploy

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)

Deploy to Render

Note Make sure you use your "live" trigger.dev API Key when deploying to a server

💻 Run locally

First, in your terminal of choice, clone the repo and install dependencies:

git clone https://github.com/ericallam/github-stars-staging-1.git
cd github-stars-staging-1
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]

🧪 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

License:MIT License


Languages

Language:TypeScript 95.0%Language:Shell 5.0%