Edits history of script submission #27 for ' Notify of new Github repo stars (github)'

  • deno
    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;
    }

    Submitted by rossmccrann 1372 days ago

  • deno
    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: 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} `;
        }
    
        const web = new WebClient(await wmill.getVariable("g/all/slack_token"));
        if (channel == '') {
            channel = null;
        }
        if (username == '') {
            username = null;
        }
        if ((channel == null && username == null) || channel != null && username != null) {
            throw "one and only one of channel or user need to be set";
        }
        if (username != null) {
            channel = `@${username}`
        }
    
        await web.chat.postMessage({
            channel: channel,
            text: notification,
            username: username
        });
    
        return `Message sent on slack: ${notification}`;
    }

    Submitted by rossmccrann 1395 days ago

  • deno
    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,
        });
    
        var 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];
    
        var 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} `;
        }
    
        const web = new WebClient(await wmill.getVariable("g/all/slack_token"));
        if (channel == '') {
            channel = null;
        }
        if (username == '') {
            username = null;
        }
        if ((channel == null && username == null) || channel != null && username != null) {
            throw "one and only one of channel or user need to be set";
        }
        if (username != null) {
            channel = `@${username}`
        }
    
        await web.chat.postMessage({
            channel: channel,
            text: notification,
            username: username
        });
    
        return `Message sent on slack: ${notification}`;
    }

    Submitted by rossmccrann 1396 days ago