Search... Ctrl + K

Notify of new Github repo stars (github) - trigger module
One script reply has been approved by the moderators Verified

Created by rossmccrann 151 days ago Used 906 times 2 Points

  • 0
    The title shouldn't include "in Slack" because the output would be handled by a script and is not part of the trigger.
    by jaller94 122 days ago
Points: 0
deno
One script reply has been approved by the moderators
Ap­pro­ved
import * as wmill from "https://deno.land/x/windmill@v1.14.3/index.ts";
import { Octokit } from "https://cdn.skypack.dev/octokit?dts";
import { WebClient } from "https://deno.land/x/slack_web_api@1.0.3/mod.ts";

export async function main(
    gh_auth: wmill.Resource<"github">,
    owner: string,
    repo: string,
    channel: string,
    username: string
) {
    const octokit = new Octokit(gh_auth);
    const response = await octokit.rest.repos.get({
        owner,
        repo,
    });

    let repo_list = {};
    repo_list[response.data.name] = response.data.stargazers_count;
    const before = await wmill.getInternalState();
    const key = Object.keys(repo_list)[0];

    await wmill.setInternalState({ [key]: repo_list[key] });
    const after = await wmill.getInternalState();
    const before_val: number = Object.values(before)[0];
    const after_val: number = Object.values(after)[0];

    let notification_list = [];
    let notification: string =
        `No new Github stars on the following repo: \n ${key} : ${before_val} Stars`;
    if (after_val > before_val) {
        const difference: number = after_val - before_val;
        notification =
            `You have received ${difference} new Github stars on the following repo:\n${key} `;
        notification_list.push(notification);
    }

    return notification_list;
}

Submitted by rossmccrann 151 days ago

Edited 127 days ago

No comments yet