Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
get download info of a github release by just providing the name of a github repository
#ghdl
ghdl
(github download) is a node module and command line program that searches github repositories using the github api for a given repository name and returns download info of all tags of the given repo name if it is a real github repo with valid release(s) that have some file(s) to download because otherwise the api returns empty assets
for the repo.
You don't need to know the name of the user or the owner; just provide the name of a repository. For the most cases that ghdl
finds only one match, it returns an object
with download info of all tags of the given repo (see details below); however, in cases where there is more than one repo with the same name and with real releases (tags), it returns an array
of objects that each object contain download info of each repo.
###install
use the command line interface
Please run npm install -g ghdl
. If you encounter with a problem or getting EACCES
error, read fixing-npm-permissions.
use programmatically
run npm install ghdl
###api token
In order to make authenticated requests to github api, we need some sort of authorization method. Since we are not dealing with sensitive data and basically all data is public data that everyone can send an http
request to the api and get it on their browser or on other platforms; however, ghdl
uses personal access token which according to github docs works the same as OAuth tokens and can easily be generated on GitHub.
You can use a new access token by setting the environment variable GITHUB_TOKEN
.
###command line usage
get download count of only the latest tag (default)
ghdl <repository name>
example: ghdl kubernetes
get download count of all tags
ghdl <repository name> -a
example: ghdl kubernetes -a
show the help menu
ghdl -h
show the module version
ghdl -v
###sample output
download info of only the latest tag
download info of all tags
###api
ghdl(repo_name, callback)
repo_name
{String} -- repository name to get its download infocallback
{Function} -- gets two arguments (err, repo)
err
is an Error object (you get the error message by err.message)repo
is
object
if the given name matches only one real repo with valid tagsarray
of objects if the name matches more than one repo with real tagsnull
if no matches foundeach result object has these properties:
{
url: '',
tags: [{
tagname: '',
published_at: '',
files: [{
filename: '',
updated_at: '',
download: 0
}]
}]
}
The latest tag
is the first element of result object's tags array; that is, repo.tags[0]
.
###api usage
Based on the search result, ghdl
returns:
null
-- if no matches found.object
-- if only one repo foundarray
of objects -- if more than one repo with valid tags foundget download info of all tags
const ghdl = require('ghdl');
var repo_name = 'githubRepoName';
ghdl(repo_name, (err, result) => {
if (err) {
console.error(err.message);
}
if (result && !Array.isArray(result)) {
// only one repo found, return an object
console.log(result.url);
console.log(result.tags);
} else if (result && Array.isArray(result)) {
// more than one repo found, return an array of objects
result.forEach((repo) => {
console.log(repo.url);
console.log(repo.tags);
});
} else {
console.log(`no github release found for ${repo_name}.`);
}
});
get download info of only the latest tag
const ghdl = require('ghdl');
var repo_name = 'githubRepoName';
ghdl(repo_name, (err, result) => {
if (err) {
console.error(err.message);
}
if (result && !Array.isArray(result)) {
// the latest tag is the first element of result.tags
var latest_tag = result.tags[0];
console.log(result.url);
console.log(latest_tag.tagname);
console.log(latest_tag.published_at);
console.log(latest_tag.files);
} else if (result && Array.isArray(result)) {
result.forEach((repo) => {
var latest_tag = repo.tags[0];
console.log(repo.url);
console.log(latest_tag.tagname);
console.log(latest_tag.published_at);
console.log(latest_tag.files);
});
} else {
console.log(`no github release found for ${repo_name}.`);
}
});
Enjoy using ghdl
.
FAQs
deprecated
We found that ghdl demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.