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

2 points by rossmccrann 84 days ago | 839 uses

One script reply has been approved by the moderators
This version of script #27 was approved by the moderators as the one that fits the best the script ask: 'Notify of new Github repo stars'. It is safe to use in your flows in production.
0 points
by rossmccrann 84 days ago
edit by rossmccrann 59 days ago
import * as wmill from "https://deno.land/x/[email protected]/index.ts";
import { Octokit } from "https://cdn.skypack.dev/octokit?dts";
import { WebClient } from "https://deno.land/x/[email protected]/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;
}
edit/run in windmill raw embed