@nodesecure/github
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

Github

version Maintenance MIT Known Vulnerabilities build

Download and (optionaly) extract github repository archive.

Requirements

Getting Started

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

Usage example

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);

API

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;

Private repositories

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("...");

Contributors

All Contributors

Thanks goes to these wonderful people (emoji key):


Gentilhomme

💻 📖 👀 🛡️ 🐛

Alexandre Malaj

💻 📖

Nicolas Hallaert

💻

License

MIT

Package Sidebar

Install

npm i @nodesecure/github

Weekly Downloads

10

Version

1.2.0

License

MIT

Unpacked Size

13.5 kB

Total Files

5

Last publish

Collaborators

  • pierred
  • antoine-coulon
  • kawacrepe
  • fraxken
  • tonygo