import {
setState,
getState,
} from "https://deno.land/x/windmill@v1.85.0/mod.ts";
import { Octokit } from "npm:@octokit/rest@19.0.5";
const MAX_ITEMS = 500;
/**
* @returns A list of starrers in descending order of when they starred.
* The maximum number of returned items is 500.
*/
type Github = {
token: string;
};
export async function main(auth: Github, owner: string, repo: string) {
const octokit = new Octokit({
auth: auth.token,
});
const lastUpdate = (await getState()) || 0;
const starCount = (await octokit.repos.get({ owner, repo })).data
.stargazers_count;
let lastPage =
+(starCount / 100).toFixed(0) + (starCount % 100 === 0 ? 0 : 1);
const newStarrers: Starrer[] = [];
await setState(Date.now());
let runLoop = true;
do {
const response = await octokit.activity.listStargazersForRepo({
owner,
repo,
per_page: 100,
page: lastPage--,
headers: {
accept: "application/vnd.github.star+json",
},
});
for (let i = response.data.length - 1; i >= 0; i--) {
const entry = response.data[i];
if (!entry || !entry.user) continue;
const starredAt = new Date(entry.starred_at).getTime();
if (starredAt < lastUpdate) {
runLoop = false;
break;
}
const { id, login, type, url, email, name } = entry.user;
newStarrers.push({ id, starredAt, login, type, url, email, name });
if (newStarrers.length >= MAX_ITEMS) {
await setState(newStarrers.at(-1)?.starredAt);
runLoop = false;
break;
}
}
} while (runLoop);
console.log(newStarrers.length);
return newStarrers;
}
interface Starrer {
id: number;
login: string;
type: string;
url: string;
starredAt: number;
email?: string | null;
name?: string | null;
}
Submitted by admin 468 days ago
import { setState, getState } from "https://deno.land/x/windmill@v1.85.0/mod.ts";
import { Octokit } from "npm:@octokit/rest@19.0.5";
const MAX_ITEMS = 500
/**
* @returns A list of starrers in descending order of when they starred.
* The maximum number of returned items is 500.
*/
type Github = {
token: string;
};
export async function main(
auth: Github,
owner: string,
repo: string
) {
const octokit = new Octokit({
auth: auth.token
});
const lastUpdate = await getState() || 0
const starCount = (await octokit.repos.get({ owner, repo })).data.stargazers_count
let lastPage = +(starCount / 100).toFixed(0) + (starCount % 100 === 0 ? 0 : 1)
const newStarrers: Starrer[] = []
await setState(Date.now())
let runLoop = true
do {
const response = await octokit.activity.listStargazersForRepo({
owner,
repo,
per_page: 100,
page: lastPage--,
headers: {
accept: 'application/vnd.github.star+json'
}
})
for(let i = response.data.length - 1; i >= 0; i--) {
const entry = response.data[i]
if(!entry || !entry.user) continue;
const starredAt = new Date(entry.starred_at).getTime()
if(starredAt < lastUpdate) {
runLoop = false
break
}
const { id, login, type, url, email, name } = entry.user
newStarrers.push({ id, starredAt, login, type, url, email, name })
if(newStarrers.length >= MAX_ITEMS) {
await setState(newStarrers.at(-1)?.starredAt)
runLoop = false
break
}
}
} while(runLoop)
console.log(newStarrers.length)
return newStarrers
}
interface Starrer {
id: number,
login: string,
type: string,
url: string,
starredAt: number,
email?: string | null,
name?: string | null
}
Submitted by admin 471 days ago
import { Resource, setState, getState } from "https://deno.land/x/windmill@v1.85.0/mod.ts";
import { Octokit } from "npm:@octokit/rest@19.0.5";
const MAX_ITEMS = 500
/**
* @returns A list of starrers in descending order of when they starred.
* The maximum number of returned items is 500.
*/
export async function main(
auth: Resource<"github">,
owner: string,
repo: string
) {
const octokit = new Octokit({
auth: auth.token
});
const lastUpdate = await getState() || 0
const starCount = (await octokit.repos.get({ owner, repo })).data.stargazers_count
let lastPage = +(starCount / 100).toFixed(0) + (starCount % 100 === 0 ? 0 : 1)
const newStarrers: Starrer[] = []
await setState(Date.now())
let runLoop = true
do {
const response = await octokit.activity.listStargazersForRepo({
owner,
repo,
per_page: 100,
page: lastPage--,
headers: {
accept: 'application/vnd.github.star+json'
}
})
for(let i = response.data.length - 1; i >= 0; i--) {
const entry = response.data[i]
if(!entry || !entry.user) continue;
const starredAt = new Date(entry.starred_at).getTime()
if(starredAt < lastUpdate) {
runLoop = false
break
}
const { id, login, type, url, email, name } = entry.user
newStarrers.push({ id, starredAt, login, type, url, email, name })
if(newStarrers.length >= MAX_ITEMS) {
await setState(newStarrers.at(-1)?.starredAt)
runLoop = false
break
}
}
} while(runLoop)
console.log(newStarrers.length)
return newStarrers
}
interface Starrer {
id: number,
login: string,
type: string,
url: string,
starredAt: number,
email?: string | null,
name?: string | null
}
Submitted by adam186 599 days ago
import { Resource, setState, getState } from "https://deno.land/x/windmill@v1.70.1/mod.ts";
import { Octokit } from "npm:@octokit/rest@19.0.5";
const MAX_ITEMS = 500
/**
* @returns A list of starrers in descending order of when they starred.
* The maximum number of returned items is 500.
*/
export async function main(
auth: Resource<"github">,
owner: string,
repo: string
) {
const octokit = new Octokit({
auth: auth.token
});
const lastUpdate = await getState() || 0
const starCount = (await octokit.repos.get({ owner, repo })).data.stargazers_count
let lastPage = +(starCount / 100).toFixed(0) + (starCount % 100 === 0 ? 0 : 1)
const newStarrers: Starrer[] = []
await setState(Date.now())
let runLoop = true
do {
const response = await octokit.activity.listStargazersForRepo({
owner,
repo,
per_page: 100,
page: lastPage--,
headers: {
accept: 'application/vnd.github.star+json'
}
})
for(let i = response.data.length - 1; i >= 0; i--) {
const entry = response.data[i]
if(!entry || !entry.user) continue;
const starredAt = new Date(entry.starred_at).getTime()
if(starredAt < lastUpdate) {
runLoop = false
break
}
const { id, login, type, url, email, name } = entry.user
newStarrers.push({ id, starredAt, login, type, url, email, name })
if(newStarrers.length >= MAX_ITEMS) {
await setState(newStarrers.at(-1)?.starredAt)
runLoop = false
break
}
}
} while(runLoop)
console.log(newStarrers.length)
return newStarrers
}
interface Starrer {
id: number,
login: string,
type: string,
url: string,
starredAt: number,
email?: string | null,
name?: string | null
}
Submitted by adam186 634 days ago
import { Resource, setState, getState } from "https://deno.land/x/windmill@v1.55.0/mod.ts";
import { Octokit } from "npm:@octokit/rest@19.0.5";
const MAX_ITEMS = 500
/**
* @returns A list of starrers in descending order of when they starred.
* The maximum number of returned items is 500.
*/
export async function main(
auth: Resource<"github">,
owner: string,
repo: string
) {
const octokit = new Octokit({
auth: auth.token
});
const lastUpdate = await getState() || 0
const starCount = (await octokit.repos.get({ owner, repo })).data.stargazers_count
let lastPage = +(starCount / 100).toFixed(0) + (starCount % 100 === 0 ? 0 : 1)
const newStarrers: Starrer[] = []
await setState(Date.now())
let runLoop = true
do {
const response = await octokit.activity.listStargazersForRepo({
owner,
repo,
per_page: 100,
page: lastPage--,
headers: {
accept: 'application/vnd.github.star+json'
}
})
for(let i = response.data.length - 1; i >= 0; i--) {
const entry = response.data[i]
if(!entry || !entry.user) continue;
const starredAt = new Date(entry.starred_at).getTime()
if(starredAt < lastUpdate) {
runLoop = false
break
}
const { id, login, type, url, email, name } = entry.user
newStarrers.push({ id, starredAt, login, type, url, email, name })
if(newStarrers.length >= MAX_ITEMS) {
await setState(newStarrers.at(-1)?.starredAt)
runLoop = false
break
}
}
} while(runLoop)
console.log(newStarrers.length)
return newStarrers
}
interface Starrer {
id: number,
login: string,
type: string,
url: string,
starredAt: number,
email?: string | null,
name?: string | null
}
Submitted by adam186 708 days ago
import { Resource, setState, getState } from "https://deno.land/x/windmill@v1.55.0/mod.ts";
import { Octokit } from "npm:@octokit/rest@19.0.5";
export async function main(
auth: Resource<"github">,
owner: string,
repo: string
) {
const octokit = new Octokit({
auth: auth.token
});
const lastUpdate = await getState() || 0
const starCount = (await octokit.repos.get({ owner, repo })).data.stargazers_count
let lastPage = +(starCount / 100).toFixed(0) + (starCount % 100 === 0 ? 0 : 1)
const newStarrers: Starrer[] = []
await setState(Date.now())
let runLoop = true
do {
const response = await octokit.activity.listStargazersForRepo({
owner,
repo,
per_page: 100,
page: lastPage--,
headers: {
accept: 'application/vnd.github.star+json'
}
})
for(let i = response.data.length - 1; i >= 0; i--) {
const entry = response.data[i]
if(!entry || !entry.user) continue;
const starredAt = new Date(entry.starred_at).getTime()
if(starredAt < lastUpdate) {
runLoop = false
break;
}
const { id, login, type, url, email, name } = entry.user
newStarrers.push({ id, starredAt, login, type, url, email, name })
}
} while(runLoop)
return newStarrers
}
interface Starrer {
id: number,
login: string,
type: string,
url: string,
starredAt: number,
email?: string | null,
name?: string | null
}
Submitted by adam186 708 days ago