Skip to content

Instantly share code, notes, and snippets.

@jitran
Created April 5, 2024 02:29
Show Gist options
  • Save jitran/953f4957c1a61145bc0598684d2ae530 to your computer and use it in GitHub Desktop.
Save jitran/953f4957c1a61145bc0598684d2ae530 to your computer and use it in GitHub Desktop.
User statistics
import { Octokit } from "octokit";
import dotenv from "dotenv";
dotenv.config();
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
});
const username = process.argv[2]
const response = await octokit.rest.repos.listForUser({ username: username });
const followers = await octokit.rest.users.listFollowersForUser({ username: username });
let set = new Set();
response.data.map(repo => {
if (repo.language) {
set.add(repo.language);
}
});
console.log("User public statistics: %s", username);
console.log("Repositories: %d", response.data.length)
console.log("Languages used: %s", Array.from(set).join(", "));
console.log("Followers: %d", followers.data.length);
@jitran
Copy link
Author

jitran commented Apr 5, 2024

Exercise:

Create an application that takes a GitHub username as input and uses the GitHub API to display statistics about the user, such as the number of repositories they have, the languages they use, their followers, etc

Install node packages:

npm install dotenv octokit

Create .env file with a PAT that has public_repo and read:user access:

GITHUB_TOKEN="ghp_XYZ"

Run:

node user.mjs octocat

References:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment