-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6247beb
commit e46d0af
Showing
3 changed files
with
36 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
GH_ORG=cyprus-developer-community | ||
GH_GRAPHQL_URL=https://api.github.com/graphql | ||
|
||
# https://github.com/settings/tokens?type=beta | ||
# Create a fine-grained token with the following permissions: | ||
# Resource owner: cyprus-developer-community | ||
# Repository Access: Public Repositories (read only) | ||
# Organization permissions: Members (read only) | ||
GH_PAT= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ node_modules | |
/functions/\[\[path\]\].js | ||
/public/build | ||
.env | ||
.env.* | ||
keyfile.pem | ||
build | ||
.pnpm-debug.log | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,32 @@ | ||
import { Octokit } from '@octokit/core' | ||
import { createAppAuth } from '@octokit/auth-app' | ||
|
||
const appOctokit = new Octokit({ | ||
authStrategy: createAppAuth, | ||
auth: { | ||
appId: process.env.GH_APP_ID, | ||
privateKey: atob(process.env.GH_PRIVATE_KEY) | ||
} | ||
}) | ||
let token = '', | ||
octokit = {} | ||
|
||
const { token } = await appOctokit.auth({ | ||
type: 'installation', | ||
installationId: process.env.GH_APP_INSTALLATION_ID | ||
}) | ||
if (process.env.GH_PAT) { | ||
// with personal access token (local development) | ||
const patOctokit = new Octokit({ auth: process.env.GH_PAT }) | ||
|
||
export { token, appOctokit as octokit } | ||
token = process.env.GH_PAT | ||
octokit = patOctokit | ||
} else { | ||
// with GitHub App (production) | ||
const appOctokit = new Octokit({ | ||
authStrategy: createAppAuth, | ||
auth: { | ||
appId: process.env.GH_APP_ID, | ||
privateKey: atob(process.env.GH_PRIVATE_KEY) | ||
} | ||
}) | ||
|
||
const { token: appToken } = await appOctokit.auth({ | ||
type: 'installation', | ||
installationId: process.env.GH_APP_INSTALLATION_ID | ||
}) | ||
|
||
token = appToken | ||
octokit = appOctokit | ||
} | ||
|
||
export { token, octokit } |