Download and (optionaly) extract github repository archive.
- Node.js v18 or higher
This package is available in the Node Package Repository and can be easily installed with npm or yarn.
$ npm i @nodesecure/github
# or
$ yarn add @nodesecure/github
import * as github from "@nodesecure/github";
const utils = await github.download("NodeSecure.utils");
console.log(utils.location);
const scanner = await github.downloadAndExtract("NodeSecure.scanner");
console.log(scanner.location);
const contributors = await github.getContributorsLastActivities(
"NodeSecure",
"scanner"
);
console.log(contributors);
export interface DownloadOptions {
/**
* The destination (location) to extract the tar.gz
*
* @default process.cwd()
*/
dest?: string;
/**
* The default github branch name (master, main ...)
*
* @default main
*/
branch?: string;
/**
* Authentication token for private repositories
*
* @default process.env.GITHUB_TOKEN
*/
token?: string;
}
export type ExtractOptions = DownloadOptions & {
/**
* Remove the tar.gz archive after a succesfull extraction
*
* @default true
*/
removeArchive?: boolean;
};
export interface DownloadResult {
/** Archive or repository location on disk */
location: string;
/** Github repository name */
repository: string;
/** Github organization name */
organization: string;
}
export interface GetContributorsLastActivities {
token?: string;
}
export interface GetContributorsLastActivitiesResult {
[key: string]: {
repository: string;
actualRepo: boolean;
lastActivity: string;
}[];
}
export function download(
repo: string,
options?: DownloadOptions
): Promise<DownloadResult>;
export function downloadAndExtract(
repo: string,
options?: ExtractOptions
): Promise<DownloadResult>;
export function getContributorsLastActivities(
owner: string,
repository: string,
options?: GetContributorsLastActivities
): Promise<GetContributorsLastActivitiesResult | null>;
export function setToken(githubToken: string): void;
To work with private repositories you can either setup a GITHUB_TOKEN
system variable or use setToken
method:
import * as github from "@nodesecure/github";
github.setToken("...");
Thanks goes to these wonderful people (emoji key):
Gentilhomme 💻 📖 👀 🛡️ 🐛 |
Alexandre Malaj 💻 📖 |
Nicolas Hallaert 💻 |
Kouadio Fabrice Nguessan 🚧 |
MIT