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

  • deno
    One script reply has been approved by the moderators
    Ap­pro­ved
    import {
      setState,
      getState,
    } from "https://deno.land/x/[email protected]/mod.ts";
    import { Octokit } from "npm:@octokit/[email protected]";
    
    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 hugo697 366 days ago

  • deno
    import {
      setState,
      getState,
    } from "https://deno.land/x/[email protected]/mod.ts";
    import { Octokit } from "npm:@octokit/[email protected]";
    
    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 999 days ago

  • deno
    import { setState, getState } from "https://deno.land/x/[email protected]/mod.ts";
    import { Octokit } from "npm:@octokit/[email protected]";
    
    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 1002 days ago

  • deno
    import { Resource, setState, getState } from "https://deno.land/x/[email protected]/mod.ts";
    import { Octokit } from "npm:@octokit/[email protected]";
    
    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 1130 days ago

  • deno
    import { Resource, setState, getState } from "https://deno.land/x/[email protected]/mod.ts";
    import { Octokit } from "npm:@octokit/[email protected]";
    
    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 1165 days ago

  • deno
    import { Resource, setState, getState } from "https://deno.land/x/[email protected]/mod.ts";
    import { Octokit } from "npm:@octokit/[email protected]";
    
    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 1239 days ago

  • deno
    import { Resource, setState, getState } from "https://deno.land/x/[email protected]/mod.ts";
    import { Octokit } from "npm:@octokit/[email protected]";
    
    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 1240 days ago