Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@artginzburg/github-user-downloads

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@artginzburg/github-user-downloads - npm Package Compare versions

Comparing version 0.4.1 to 0.5.0

cli.js

28

index.js
const { Octokit } = require('@octokit/rest');
const sumDownloads = (accum, asset) => accum + asset.download_count;
module.exports = async function getUserDownloads(username, auth = process.env.GITHUB_TOKEN) {
const octokit = new Octokit({ auth });
const { rest } = new Octokit({ auth });

@@ -11,8 +13,8 @@ const userDownloads = {

const { data: repos } = await octokit.rest.repos.listForUser({
const { data: repos } = await rest.repos.listForUser({
username,
});
for (const repo of repos) {
const { data: releases } = await octokit.rest.repos.listReleases({
const mapRepo = async (repo) => {
const { data: releases } = await rest.repos.listReleases({
owner: repo.owner.login,

@@ -23,3 +25,3 @@ repo: repo.name,

if (!releases.length) {
continue;
return;
}

@@ -29,4 +31,4 @@

for (const release of releases) {
const { data: assets } = await octokit.rest.repos.listReleaseAssets({
const mapRelease = async (release) => {
const { data: assets } = await rest.repos.listReleaseAssets({
owner: repo.owner.login,

@@ -37,10 +39,14 @@ repo: repo.name,

repoDownloadCount += assets.reduce((accum, asset) => accum + asset.download_count, 0);
}
repoDownloadCount += assets.reduce(sumDownloads, 0);
};
await Promise.all(releases.map(mapRelease));
userDownloads.total += repoDownloadCount;
userDownloads.data.push({ name: repo.name, download_count: repoDownloadCount });
}
};
await Promise.all(repos.map(mapRepo));
return userDownloads;
}
};
{
"name": "@artginzburg/github-user-downloads",
"version": "0.4.1",
"version": "0.5.0",
"description": "Get total downloads of all repos by username",

@@ -14,6 +14,10 @@ "license": "ISC",

"scripts": {
"start": "node test"
"test": "node test",
"start": "node cli",
"lint": "eslint . --fix"
},
"bin": "./cli.js",
"files": [
"index.js"
"index.js",
"cli.js"
],

@@ -24,4 +28,7 @@ "dependencies": {

"devDependencies": {
"dotenv": "^10.0.0"
"dotenv": "^10.0.0",
"eslint": "^8.10.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.25.4"
}
}

@@ -9,8 +9,2 @@ # Purpose

## Limitations
This is for testing and personal purposes only (for now)
> I'm planning to build sort of an ecosystem around it later
# Preparation

@@ -23,2 +17,18 @@

# Usage
## As a CLI
```ps1
GITHUB_TOKEN=ghp_321yourPersonalAccessToken npx @artginzburg/github-user-downloads username
```
> if username is ommited, uses $USER environment variable instead.
## As an ES module
I'm personally using it via a GitHub Action with `cron` to fetch my stats daily. Also, GitHub Actions provide you a GITHUB_TOKEN, with no need to create it manually.
<br/>
# Testing

@@ -28,3 +38,3 @@

2. Install dependencies (`npm i`)
3. Set `GITHUB_TOKEN` and `USER` environmental variables (use `.env` file if you want)
4. Run `npm start`
3. Set `GITHUB_TOKEN` and `USER` (if your local username is not the one you want to check) environmental variables (use `.env` file if you want)
4. Run `npm test`, or `npm start username`
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc