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 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.
If you are looking for a convenient front-end to get download info af a github release on your terminal and don't want to deal with the api, you can use ghdl-cli.
ghdl
web interface: https://ghdl.herokuapp.com
###install
npm install ghdl
###api
ghdl(repo_name, opts, callback)
repo_name
{String} -- repository name to get its download infoopts
{Object} -- gh-got options
opts.token
, which is the GitHub access token and can be set globally with GITHUB_TOKEN
environment variablecallback
{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 foundIn order to make authenticated requests to github api, the GitHub access token can be used that works the same as OAuth tokens and can easily be generated on GitHub. It can be set globally with GITHUB_TOKEN
environment variable.
each 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');
const opts = {
token: 'foo',
headers: {
'user-agent': 'https://github.com/manidlou/ghdl'
}
};
var repo_name = 'githubRepoName';
ghdl(repo_name, opts, (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');
// use the default user-agent (https://github.com/manidlou/ghdl)
// just provide the github token
ghdl('githubRepoName', {token: 'foo'}, (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.