Skip to content

NodeSecure/github

Repository files navigation

Github

version Maintenance OpenSSF Scorecard 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
Gentilhomme

💻 📖 👀 🛡️ 🐛
Alexandre Malaj
Alexandre Malaj

💻 📖
Nicolas Hallaert
Nicolas Hallaert

💻
Kouadio Fabrice Nguessan
Kouadio Fabrice Nguessan

🚧

License

MIT