Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@google-automations/git-file-utils

googleapis1mApache-2.03.0.0TypeScript support: included

Utilities for github file operation

Git data API

readme

git-file-utils

This is a small library for handling git files. Currently it only provides RepositoryFileCache which is a read-through cache for a single branch. Because this library uses GIt Data API, it can fetch files up to 100 MB of size.

Install

npm i @google-automations/git-file-utils

Fetch a file

import {Octokit} from '@octokit/rest';
import {
  FileNotFoundError,
  RepositoryFileCache
} from '@google-automations/git-file-utils';

const octokit = new Octokit();
const cache = new RepositoryFileCache(
  octokit,
  {
    owner: "googleapis",
    repo: "repo-automation-bots",
  });
try {
  const contents = await cache.getFileContents("README.md", "main");
  console.log(`content: ${contents.parsedContent}`);
} catch (e) {
  if (e instanceof FileNotFoundError) {
    console.log(`file not found`);
  } else {
    // rethrow
    throw e;
  }
}

changelog

Changelog

3.0.0 (2025-02-26)

⚠ BREAKING CHANGES

  • deps: update octokit/rest to v20 (#5680)

Bug Fixes

2.0.0 (2023-09-18)

⚠ BREAKING CHANGES

  • require node 18 (#5225)

Features

1.2.6 (2023-01-23)

Bug Fixes

1.2.5 (2023-01-05)

Bug Fixes

  • handle empty repository as if it has no files (#4863) (9c1d60e)

1.2.4 (2022-12-22)

Bug Fixes

  • pin typescript to 4.8.4 for four more bots (#4806) (3f4d0b0)

1.2.3 (2022-11-15)

Bug Fixes

  • deps: [git-file-utils] update dependency @octokit/types to v8 (#4672) (a372a6d)

1.2.2 (2022-10-31)

Bug Fixes

  • deps: [git-file-utils] update dependency @octokit/rest to v19.0.5 (#4575) (92a5fc8)

1.2.1 (2022-10-03)

Bug Fixes

  • git-file-utils: throws BranchNotFoundError for missing branch (#4522) (ecb7652)

1.2.0 (2022-08-31)

Features

1.1.0 (2022-08-18)

Features

  • add findFilesByFilename and findFilesByExtension (#4165) (706449c)

1.0.0 (2022-08-10)

Features