Skip to content

Commit

Permalink
Adds support for falling back to GITHUB_TOKEN if available
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Oct 2, 2018
1 parent 1132886 commit aed6295
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

## Master

# 4.2.1

- Adds a fallback to `GITHUB_TOKEN` if it's in the ENV - orta
- There was some versioning faffing going on

# 4.1.0

- Adds the ability to send a PR from a Dangerfile easily.
Expand Down
2 changes: 1 addition & 1 deletion source/api/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function api(
}

const showToken = process.env["DANGER_VERBOSE_SHOW_TOKEN"]
const token = process.env["DANGER_GITHUB_API_TOKEN"]
const token = process.env["DANGER_GITHUB_API_TOKEN"] || process.env["GITHUB_TOKEN"]

if (init.headers) {
for (const prop in init.headers) {
Expand Down
2 changes: 1 addition & 1 deletion source/ci_source/ci_source_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export async function getPullRequestIDForBranch(metadata: RepoMetaData, env: Env
return 0
}

const token = env["DANGER_GITHUB_API_TOKEN"]
const token = env["DANGER_GITHUB_API_TOKEN"] || env["GITHUB_TOKEN"]
if (!token) {
return 0
}
Expand Down
2 changes: 1 addition & 1 deletion source/platforms/github/GitHubGit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const gitHubGitDSL = (github: GitHubDSL, json: GitJSONDSL, githubAPI?: Gi
githubAPI ||
new GitHubAPI(
{ repoSlug: github.pr.base.repo.full_name, pullRequestID: String(github.pr.number) },
process.env["DANGER_GITHUB_API_TOKEN"]
process.env["DANGER_GITHUB_API_TOKEN"] || process.env["GITHUB_TOKEN"]
)

if (!githubAPI) {
Expand Down
2 changes: 1 addition & 1 deletion source/platforms/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function getPlatformForEnv(env: Env, source: CISource, requireAuth = true
}

// GitHub
const ghToken = env["DANGER_GITHUB_API_TOKEN"]
const ghToken = env["DANGER_GITHUB_API_TOKEN"] || env["GITHUB_TOKEN"]
if (ghToken || !requireAuth) {
if (!ghToken) {
console.log("You don't have a DANGER_GITHUB_API_TOKEN set up, this is optional, but TBH, you want to do this")
Expand Down
2 changes: 1 addition & 1 deletion source/runner/dslGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const jsonDSLGenerator = async (platform: Platform): Promise<DangerDSLJSO
[platform.name === "BitBucketServer" ? "bitbucket_server" : "github"]: platformDSL,
settings: {
github: {
accessToken: process.env["DANGER_GITHUB_API_TOKEN"] || "NO_TOKEN",
accessToken: process.env["DANGER_GITHUB_API_TOKEN"] || process.env["GITHUB_TOKEN"] || "NO_TOKEN",
additionalHeaders: {},
baseURL: process.env["DANGER_GITHUB_API_BASE_URL"] || undefined,
},
Expand Down

0 comments on commit aed6295

Please sign in to comment.