1
0
mirror of synced 2025-12-20 02:19:14 -05:00
Files
docs/script/helpers/github.js
Rachael Sewell cb37f22ef0 automate github apps docs (#35530)
Co-authored-by: Sarah Edwards <skedwards88@github.com>
2023-06-16 19:23:05 +00:00

30 lines
801 B
JavaScript

#!/usr/bin/env node
import dotenv from 'dotenv'
import { Octokit } from '@octokit/rest'
if (!process.env.GITHUB_TOKEN) {
dotenv.config()
}
// check for required PAT
if (!process.env.GITHUB_TOKEN) {
throw new Error(
'Error! You must have a GITHUB_TOKEN set in an .env file to use the GitHub REST API.'
)
}
// this module needs to work in development, production, and GitHub Actions
//
// GITHUB_TOKEN comes from one of the following sources:
// 1. set in the .env file (development)
// 2. set as a Heroku config var (staging and production)
// 3. an installation token granted via GitHub Actions
const apiToken = process.env.GITHUB_TOKEN
// See https://github.com/octokit/rest.js/issues/1207
export default function github() {
return new Octokit({
auth: `token ${apiToken}`,
})
}