UNPKG

@nodesecure/github

Version:

Download repository from github

127 lines (98 loc) 5.35 kB
# Github ![version](https://img.shields.io/badge/dynamic/json.svg?style=for-the-badge&url=https://raw.githubusercontent.com/NodeSecure/github/master/package.json&query=$.version&label=Version) [![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg?style=for-the-badge)](https://github.com/NodeSecure/github/graphs/commit-activity) [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/NodeSecure/github/badge?style=for-the-badge)](https://api.securityscorecards.dev/projects/github.com/NodeSecure/github) ![MIT](https://img.shields.io/github/license/NodeSecure/github.svg?style=for-the-badge) ![build](https://img.shields.io/github/actions/workflow/status/NodeSecure/github/node.js.yml?style=for-the-badge) Download and (optionaly) extract github repository archive. ## Requirements - [Node.js](https://nodejs.org/en/) v18 or higher ## Getting Started This package is available in the Node Package Repository and can be easily installed with [npm](https://docs.npmjs.com/getting-started/what-is-npm) or [yarn](https://yarnpkg.com). ```bash $ npm i @nodesecure/github # or $ yarn add @nodesecure/github ``` ## Usage example ```js 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); ``` ## API Both `download` and `downloadAndExtract` functions use the same set of options. ```ts 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; } ``` ### download(repository: string, options?: DownloadOptions): Promise< DownloadResult > Download the tar.gz archive of the GIT repository. ```ts interface DownloadResult { /** Archive or repository location on disk */ location: string; /** Github repository name */ repository: string; /** Github organization name */ organization: string; /** Github branch name */ branch: string; } ``` ### downloadAndExtract(repository: string, options?: DownloadExtractOptions): Promise< DownloadResult > Use download but extract the tar.gz archive. ```ts interface DownloadExtractOptions extends DownloadOptions { /** * Remove the tar.gz archive after a succesfull extraction * * @default true */ removeArchive?: boolean; } ``` ## Contributors ✨ <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --> [![All Contributors](https://img.shields.io/badge/all_contributors-4-orange.svg?style=flat-square)](#contributors-) <!-- ALL-CONTRIBUTORS-BADGE:END --> Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)): <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> <!-- prettier-ignore-start --> <!-- markdownlint-disable --> <table> <tbody> <tr> <td align="center" valign="top" width="14.28%"><a href="https://www.linkedin.com/in/thomas-gentilhomme/"><img src="https://avatars.githubusercontent.com/u/4438263?v=4?s=100" width="100px;" alt="Gentilhomme"/><br /><sub><b>Gentilhomme</b></sub></a><br /><a href="https://github.com/NodeSecure/github/commits?author=fraxken" title="Code">💻</a> <a href="https://github.com/NodeSecure/github/commits?author=fraxken" title="Documentation">📖</a> <a href="https://github.com/NodeSecure/github/pulls?q=is%3Apr+reviewed-by%3Afraxken" title="Reviewed Pull Requests">👀</a> <a href="#security-fraxken" title="Security">🛡️</a> <a href="https://github.com/NodeSecure/github/issues?q=author%3Afraxken" title="Bug reports">🐛</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/AlexandreMalaj"><img src="https://avatars.githubusercontent.com/u/32218832?v=4?s=100" width="100px;" alt="Alexandre Malaj"/><br /><sub><b>Alexandre Malaj</b></sub></a><br /><a href="https://github.com/NodeSecure/github/commits?author=AlexandreMalaj" title="Code">💻</a> <a href="https://github.com/NodeSecure/github/commits?author=AlexandreMalaj" title="Documentation">📖</a></td> <td align="center" valign="top" width="14.28%"><a href="https://www.linkedin.com/in/nicolas-hallaert/"><img src="https://avatars.githubusercontent.com/u/39910164?v=4?s=100" width="100px;" alt="Nicolas Hallaert"/><br /><sub><b>Nicolas Hallaert</b></sub></a><br /><a href="https://github.com/NodeSecure/github/commits?author=Rossb0b" title="Code">💻</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/fabnguess"><img src="https://avatars.githubusercontent.com/u/72697416?v=4?s=100" width="100px;" alt="Kouadio Fabrice Nguessan"/><br /><sub><b>Kouadio Fabrice Nguessan</b></sub></a><br /><a href="#maintenance-fabnguess" title="Maintenance">🚧</a></td> </tr> </tbody> </table> <!-- markdownlint-restore --> <!-- prettier-ignore-end --> <!-- ALL-CONTRIBUTORS-LIST:END --> ## License MIT