1

Get Repo Star Count

by
Published Jun 29, 2022
Script github Verified

The script

Submitted by hugo989 Bun
Verified 6 days ago
1
import { Octokit } from "octokit";
2

3
/**
4
 * @param owner The account owner of the repository. The name is not case sensitive.
5
 *
6
 * @param repo The name of the repository. The name is not case sensitive.
7
 */
8
type Github = {
9
  token: string;
10
};
11
export async function main(gh_auth: Github, owner: string, repo: string) {
12
  const octokit = new Octokit({ auth: gh_auth.token });
13

14
  const repository = await octokit.request("GET /repos/{owner}/{repo}", {
15
    owner,
16
    repo,
17
    headers: {
18
      "X-GitHub-Api-Version": "2022-11-28",
19
      Accept: "application/vnd.github+json",
20
    },
21
  });
22

23
  return repository?.data?.stargazers_count;
24
}
25

Other submissions
  • Submitted by rossmccrann Deno
    Created 1160 days ago
    1
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts";
    2
    import { Octokit } from "https://cdn.skypack.dev/@octokit/rest";
    3
    
    
    4
    /*
    5
    @param: {wmill.Resource<"github">} gh_auth - Resource containing Github Auth API Key
    6
    example:
    7
    {
    8
        auth: github_api_key
    9
    }
    10
    */
    11
    
    
    12
    export async function main(
    13
        gh_auth: wmill.Resource<"github">,
    14
        owner: string,
    15
        repo: string,
    16
    ) {
    17
        const octokit = new Octokit({ auth: gh_auth.token });
    18
        const response = await octokit.rest.repos.get({
    19
            owner,
    20
            repo,
    21
        });
    22
    
    
    23
        var repo_list = {};
    24
    
    
    25
        const arr = response.data;
    26
        repo_list[arr.name] = arr.stargazers_count;
    27
    
    
    28
        return repo_list;
    29
    }
    30
    
    
  • Submitted by adam186 Deno
    Created 398 days ago
    1
    import { Octokit } from "https://esm.sh/octokit?dts";
    2
    
    
    3
    /**
    4
     * @param owner The account owner of the repository. The name is not case sensitive.
    5
     *
    6
     * @param repo The name of the repository. The name is not case sensitive.
    7
     */
    8
    type Github = {
    9
      token: string;
    10
    };
    11
    export async function main(gh_auth: Github, owner: string, repo: string) {
    12
      const octokit = new Octokit({ auth: gh_auth.token });
    13
    
    
    14
      const repository = await octokit.request("GET /repos/{owner}/{repo}", {
    15
        owner,
    16
        repo,
    17
        headers: {
    18
          "X-GitHub-Api-Version": "2022-11-28",
    19
          Accept: "application/vnd.github+json",
    20
        },
    21
      });
    22
    
    
    23
      return repository?.data?.stargazers_count;
    24
    }
    25