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.2.0 to 0.3.0

endpoint.js

27

app.js

@@ -1,26 +0,7 @@

const getUserDownloads = require('./index.js');
const express = require('express');
const { endpoint } = require('./endpoint');
const app = express();
const { PORT = 3000 } = process.env;
const shieldsSchema = {
schemaVersion: 1,
label: 'downloads',
color: 'teal',
namedLogo: 'github',
style: 'social',
cacheSeconds: 24 * 60 * 60, // 24h
};
app.get('/:user', async (req, res) => {
const userDownloads = await getUserDownloads(req.params.user);
res.end(
JSON.stringify({
...shieldsSchema,
message: String(userDownloads.total),
}),
);
endpoint.listen(PORT, () => {
console.log(`Endpoint listening on http://localhost:${PORT}`);
});
module.exports.endpoint = app;
const { Octokit } = require('@octokit/rest');
async function getUserDownloads(username, personalAccessToken) {
const octokit = new Octokit({ auth: personalAccessToken });
async function getUserDownloads(username, auth) {
const octokit = new Octokit({ auth });
const { data: repos } = await octokit.rest.repos.listForUser({
username,
});
const userDownloads = {

@@ -15,2 +11,6 @@ total: 0,

const { data: repos } = await octokit.rest.repos.listForUser({
username,
});
for (const repo of repos) {

@@ -35,13 +35,7 @@ const { data: releases } = await octokit.rest.repos.listReleases({

const releaseDownloadCount = assets.reduce(
(releaseDownloadsAccumulator, currentAsset) =>
releaseDownloadsAccumulator + currentAsset.download_count,
0,
);
repoDownloadCount += releaseDownloadCount;
repoDownloadCount += assets.reduce((accum, asset) => accum + asset.download_count, 0);
}
userDownloads.total += repoDownloadCount;
userDownloads.data.push([{ name: repo.name, download_count: repoDownloadCount }]);
userDownloads.data.push({ name: repo.name, download_count: repoDownloadCount });
}

@@ -48,0 +42,0 @@

{
"name": "@artginzburg/github-user-downloads",
"version": "0.2.0",
"version": "0.3.0",
"description": "Get total downloads of all repos by username",

@@ -13,5 +13,6 @@ "license": "ISC",

},
"main": "app.js",
"main": "endpoint.js",
"scripts": {
"start": "node test"
"start": "node test",
"test": "node app"
},

@@ -18,0 +19,0 @@ "dependencies": {

@@ -1,5 +0,13 @@

const getUserDownloads = require('./index.js');
const getUserDownloads = require('./index');
require('dotenv').config();
getUserDownloads(({ USER = 'artginzburg', PERSONAL_ACCESS_TOKEN } = process.env)).then(console.log);
const { USER = 'artginzburg', PERSONAL_ACCESS_TOKEN } = process.env;
const timeLabel = 'github-user-downloads';
console.time(timeLabel);
getUserDownloads(USER, PERSONAL_ACCESS_TOKEN).then((data) => {
console.log(data);
console.timeEnd(timeLabel);
});
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