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 852 days ago
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: 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 875 days ago
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,
});
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 876 days ago