Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Commit

Permalink
Allow to pass github token with env var
Browse files Browse the repository at this point in the history
  • Loading branch information
fabien0102 committed May 5, 2021
1 parent c910a47 commit d047196
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ restful-react is **very well tested, production ready** and powers all of our pr
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->


- [Overview](#overview)
- [Getting Started](#getting-started)
- [Features](#features)
Expand Down Expand Up @@ -664,12 +663,11 @@ To generate components from remote specifications, you'll need to follow the fol
1. Open a terminal and run `restful-react import --github username:repo:branch:path/to/openapi.yaml --output MY_FETCHERS.tsx`, substituting things where necessary.
1. You will be prompted for a token.
1. Paste your token.
1. You will be asked if you'd like to save it for later. This is _entirely_ up to you and completely safe: it is saved in your `node_modules` folder and _not_ committed to version control or sent to us or anything: the source code of this whole thing is public so you're safe.
**Caveat:** _Since_ your token is stored in `node_modules`, your token will be removed on each `npm install` of `restful-react`.
1. You will be asked if you'd like to save it for later. This is _entirely_ up to you and completely safe: it is saved in your home directory.
1. You're done! 🎉
Note: For CI environment, you can also provide the github token with the environment variable called `GITHUB_TOKEN`
#### Transforming an Original Spec
In some cases, you might need to augment an existing OpenAPI specification on the fly, for code-generation purposes. Our CLI makes this quite straightforward:
Expand Down
6 changes: 3 additions & 3 deletions src/bin/restful-react-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ const importSpecs = async (options: AdvancedOptions) => {
} else if (options.github) {
const { github } = options;

let accessToken: string;
let accessToken = process.env.GITHUB_TOKEN;
const githubTokenPath = join(homedir(), ".restful-react");
if (existsSync(githubTokenPath)) {
if (!accessToken && existsSync(githubTokenPath)) {
accessToken = readFileSync(githubTokenPath, "utf-8");
} else {
} else if (!accessToken) {
const answers = await inquirer.prompt<{ githubToken: string; saveToken: boolean }>([
{
type: "input",
Expand Down

0 comments on commit d047196

Please sign in to comment.