Download and (optionaly) extract gitlab 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/gitlab
# or
$ yarn add @nodesecure/gitlab
import * as gitlab from "@nodesecure/gitlab";
// Note: repository can be either namespace path or repository ID
const is = await gitlab.download("NodeSecure.utils");
console.log(is.location);
export interface DownloadOptions {
/**
* The destination (location) to extract the tar.gz
*
* @default process.cwd()
*/
dest?: string;
/**
* The default gitlab branch name (master, main ...).
* By default it fetch the "default" gitlab branch.
*
* @default null
*/
branch?: string | null;
/**
* Authentication token for private repositories
*
* @default process.env.GITLAB_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;
/** Gitlab repository name */
repository: string;
/** Gitlab organization name */
organization: string;
/** Gitlab branch name */
branch: string;
}
export function download(repo: string, options?: DownloadOptions): Promise<DownloadResult>;
export function downloadAndExtract(repo: string, options?: ExtractOptions): Promise<DownloadResult>;
export function setToken(gitlabToken: string): void;
export function setUrl(gitlabUrl: string | URL): void;
To work with private repositories you can either setup a GITLAB_TOKEN
system variable or use setToken
method:
import * as gitlab from "@nodesecure/gitlab";
gitlab.setToken("...");
To work with a custom gitlab instance you can either setup a GITLAB_URL
system variable or use setUrl
method:
import * as gitlab from "@nodesecure/gitlab";
gitlab.setUrl("...");
Thanks goes to these wonderful people (emoji key):
Gentilhomme 💻 📖 👀 🛡️ 🐛 |
Haze 💻 |
Alexandre Malaj 💻 📖 |
Kouadio Fabrice Nguessan 🚧 |
MIT