GithubHelp home page GithubHelp logo

trigger.dev-github-stars-to-slack's Introduction

✨ 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

trigger.dev-github-stars-to-slack's People

Contributors

jessie-cakework avatar jessie-young avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.