# github-ensure-file

> Ensures a file exists across repos of a user or an org in GitHub.

Latest version **1.0.1** (published 2022-01-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install github-ensure-file
pnpm add github-ensure-file
yarn add github-ensure-file
bun add github-ensure-file
```

Provides the command `github-ensure-file`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2022-01-07 |
| First published | 2022-01-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 7.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Simone Busoli |
| Maintainers | simoneb |

## Links

- npm: https://www.npmjs.com/package/github-ensure-file
- npm.io page: https://npm.io/package/github-ensure-file

## Dependencies (2)

- [dotenv](https://npm.io/package/dotenv.md) ^10.0.0
- [@octokit/rest](https://npm.io/package/@octokit/rest.md) ^18.12.0

## Recent versions

- 1.0.1 (latest) — 2022-01-07
- 1.0.0 — 2022-01-07

## README

# github-ensure-file

Ensures a file exists across repos of a user or an org in GitHub.

## Setup

```sh
npm i github-ensure-file
```

Provide the `GITHUB_TOKEN` environment variable containing a token with enough permissions to write files to the repositories you'll be working on. You can also use a local `.env` file to provide that variable.

You can generate a personal access token [here](https://github.com/settings/tokens/new).

## Usage

```sh
github-ensure-file <github-user-or-org> <file-path>
```

- `github-user-or-org`: name of the GitHub user or organization
- `file-path`: path to a local file

## How it works

1. It iterates through all the the repositories of the organization
2. It uses `<file-path>` to check if a file exists in the repository **at the same path as the local file**
3. Processing
   - If the file does not exist in the repo -> it prompts to create it
   - If the file exists in the repo but its contents are different from the local file -> it prompts to update it
   - If the file exists and has the same content as the local file -> it continues to the next repo

## Example

If I wanted to ensure that the file located in this repo at `.github/workflows/ci.yml` existed in other repos in my user account (`@simoneb`) **at the same path** I would do:

```sh
github-ensure-file simoneb .github/workflows/ci.yml
```

Which would give me an output similar to:

```sh
File does not exist in simoneb/some-repo, create (y/N)?
File exists in simoneb/another-repo but is different, update (y/N)?
```

---
_Source: https://npm.io/package/github-ensure-file · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
