Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to latest @octokit/rest #983

Merged
merged 4 commits into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/danger.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Autogenerated from scripts/danger-dts.ts
//

import * as GitHub from "@octokit/rest"
import { Octokit as GitHub } from "@octokit/rest"

type MarkdownString = string
// TODO: extract out from BitBucket specifically, or create our own type
Expand Down
2 changes: 1 addition & 1 deletion source/dsl/GitHubDSL.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Please don't have includes in here that aren't inside the DSL folder, or the d.ts/flow defs break

import { GitCommit } from "./Commit"
import * as GitHub from "@octokit/rest"
import { Octokit as GitHub } from "@octokit/rest"

// This is `danger.github` inside the JSON

Expand Down
2 changes: 1 addition & 1 deletion source/platforms/GitHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { GitHubAPI } from "./github/GitHubAPI"
import GitHubUtils from "./github/GitHubUtils"
import gitDSLForGitHub from "./github/GitHubGit"

import NodeGitHub from "@octokit/rest"
import { Octokit as NodeGitHub } from "@octokit/rest"
import { Platform } from "./platform"

import { GitHubIssueCommenter } from "./github/comms/issueCommenter"
Expand Down
2 changes: 1 addition & 1 deletion source/platforms/github/GitHubAPI.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import GitHubNodeAPI from "@octokit/rest"
import { Octokit as GitHubNodeAPI } from "@octokit/rest"
import { debug } from "../../debug"
import * as node_fetch from "node-fetch"
import parse from "parse-link-header"
Expand Down
9 changes: 7 additions & 2 deletions source/platforms/github/GitHubUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { filepathContentsMapToUpdateGitHubBranch, BranchCreationConfig } from "m

const d = debug("GitHub::Utils")

import * as GitHub from "@octokit/rest"
import { Octokit as GitHub } from "@octokit/rest"

// We need to curry in access to the GitHub PR metadata

Expand Down Expand Up @@ -66,8 +66,13 @@ export const fileContentsGenerator = (
owner: repoSlug.split("/")[0],
}
try {
// response of getContents() can be one of 4 things. We are interested in file responses only
// https://developer.github.com/v3/repos/contents/#get-contents
const response = await api.repos.getContents(opts)
if (response && response.data && response.data.type === "file") {
if (Array.isArray(response.data)) {
return ""
}
if (response && response.data && response.data.content) {
const buffer = new Buffer(response.data.content, response.data.encoding)
return buffer.toString()
} else {
Expand Down
2 changes: 1 addition & 1 deletion source/platforms/github/_tests/_github_git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { readFileSync } from "fs"
import { resolve, join as pathJoin } from "path"
import { gitHubGitDSL as gitJSONToGitDSL } from "../GitHubGit"

import NodeGitHub from "@octokit/rest"
import { Octokit as NodeGitHub } from "@octokit/rest"
import { GitHubDSL } from "../../../dsl/GitHubDSL"
import { GitDSL, GitJSONDSL } from "../../../dsl/GitDSL"

Expand Down
2 changes: 1 addition & 1 deletion source/platforms/github/_tests/fixturedGitHubDSL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { readFileSync } from "fs"
import { resolve, join as pathJoin } from "path"
import { gitHubGitDSL as gitJSONToGitDSL } from "../GitHubGit"

import NodeGitHub from "@octokit/rest"
import { Octokit as NodeGitHub } from "@octokit/rest"
import { GitHubDSL } from "../../../dsl/GitHubDSL"
import { GitDSL, GitJSONDSL } from "../../../dsl/GitDSL"
import { DangerDSLType } from "../../../dsl/DangerDSL"
Expand Down
8 changes: 7 additions & 1 deletion source/platforms/github/comms/checks/resultsToCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DangerResults, regularResults, inlineResults, resultsIntoInlineResults
import { GitHubPRDSL } from "../../../../dsl/GitHubDSL"
import { ExecutorOptions } from "../../../../runner/Executor"
import { template as githubResultsTemplate } from "../../../../runner/templates/githubIssueTemplate"
import GitHubNodeAPI from "@octokit/rest"
import { Octokit as GitHubNodeAPI } from "@octokit/rest"
import { debug } from "../../../../debug"

const d = debug("GitHub::ResultsToCheck")
Expand Down Expand Up @@ -68,7 +68,13 @@ export const resultsToCheck = async (

const getBlobUrlForPath = async (path: string) => {
try {
// response of getContents() can be one of 4 things. We are interested in file responses only
// https://developer.github.com/v3/repos/contents/#get-contents
const { data } = await api.repos.getContents({ repo: pr.head.repo.name, owner: pr.head.repo.owner.login, path })
if (Array.isArray(data)) {
console.error(`Path "${path}" is a folder - ignoring`)
return ""
}
d("Got content data for: ", path)
// https://developer.github.com/v3/checks/runs/#example-of-completed-conclusion
// e.g. "blob_href": "http://github.com/octocat/Hello-World/blob/837db83be4137ca555d9a5598d0a1ea2987ecfee/README.md",
Expand Down
10 changes: 5 additions & 5 deletions source/runner/jsonToDSL.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import OctoKit from "@octokit/rest"
import { Octokit } from "@octokit/rest"

import { DangerDSLJSONType, DangerDSLType } from "../dsl/DangerDSL"
import { gitHubGitDSL as githubJSONToGitDSL } from "../platforms/github/GitHubGit"
Expand Down Expand Up @@ -31,7 +31,7 @@ export const jsonToDSL = async (dsl: DangerDSLJSONType, source: CISource): Promi

const api = apiForDSL(dsl)
const platformExists = [dsl.github, dsl.bitbucket_server, dsl.gitlab, dsl.bitbucket_cloud].some(p => !!p)
const github = dsl.github && githubJSONToGitHubDSL(dsl.github, api as OctoKit)
const github = dsl.github && githubJSONToGitHubDSL(dsl.github, api as Octokit)
const bitbucket_server =
dsl.bitbucket_server && bitbucketServerJSONToBitBucketServerDSL(dsl.bitbucket_server, api as BitBucketServerAPI)
const bitbucket_cloud = dsl.bitbucket_cloud
Expand Down Expand Up @@ -67,7 +67,7 @@ export const jsonToDSL = async (dsl: DangerDSLJSONType, source: CISource): Promi
}
}

const apiForDSL = (dsl: DangerDSLJSONType): OctoKit | BitBucketServerAPI | GitLabAPI | BitBucketCloudAPI => {
const apiForDSL = (dsl: DangerDSLJSONType): Octokit | BitBucketServerAPI | GitLabAPI | BitBucketCloudAPI => {
if (process.env["DANGER_BITBUCKETSERVER_HOST"]) {
return new BitBucketServerAPI(dsl.bitbucket_server!.metadata, bitbucketServerRepoCredentialsFromEnv(process.env))
}
Expand All @@ -82,7 +82,7 @@ const apiForDSL = (dsl: DangerDSLJSONType): OctoKit | BitBucketServerAPI | GitLa
return new GitLabAPI(gitlab.metadata, getGitLabAPICredentialsFromEnv(process.env))
}

const options: OctoKit.Options & { debug: boolean } = {
const options: Octokit.Options & { debug: boolean } = {
debug: !!process.env.LOG_FETCH_REQUESTS,
baseUrl: dsl.settings.github.baseURL,
}
Expand All @@ -102,6 +102,6 @@ const apiForDSL = (dsl: DangerDSLJSONType): OctoKit | BitBucketServerAPI | GitLa
options.auth = `token ${dsl.settings.github.accessToken}`
}

const api = new OctoKit(options)
const api = new Octokit(options)
return api
}
Loading