Skip to content

Commit

Permalink
Pulls in github PR metadata based on a CI source
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Oct 15, 2016
1 parent fdfe12a commit 22917fc
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
],
"plugins": [
"transform-flow-strip-types",
"syntax-async-functions",
"transform-regenerator"
]
]
}
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
// Place your settings in this file to overwrite default and user settings.
{
"javascript.validate.enable": false,
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/.DS_Store": true,
"distribution/": true,
},
"search.exclude": {
"**/node_modules": true,
"distribution/": true,
},
}
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
},
"homepage": "https://github.com/danger/danger-js#readme",
"devDependencies": {
"@types/commander": "^2.3.30",
"@types/node-fetch": "^0.0.4",
"babel-cli": "^6.16.0",
"babel-eslint": "^7.0.0",
"babel-plugin-transform-flow-strip-types": "^6.8.0",
Expand All @@ -49,11 +51,11 @@
"eslint-plugin-promise": "^2.0.1",
"eslint-plugin-standard": "^2.0.0",
"flow-bin": "^0.32.0",
"jest-cli": "^16.0.0",
"@types/commander": "^2.3.30",
"@types/node-fetch": "^0.0.4"
"jest-cli": "^16.0.0"
},
"dependencies": {
"babel-plugin-syntax-async-functions": "^6.13.0",
"babel-plugin-transform-regenerator": "^6.16.1",
"commander": "^2.9.0",
"node-fetch": "^1.6.3"
}
Expand Down
17 changes: 17 additions & 0 deletions source/ci_source/fake.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// @flow
"use strict"

import type { Env } from "./ci_source"

export default class FakeCI {
env: Env
constructor(env: Env) { this.env = env }

get isCI() : boolean { return true }
get isPR() : boolean { return true }

get pullRequestID(): string { return "350" }
get repoSlug(): string { return "artsy/emission" }
get repoURL(): string { return "maybe not needed?" }
get supportedPlatforms() : string[] { return ["github"] }
}
11 changes: 10 additions & 1 deletion source/commands/danger-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@ var program = require("commander")
import { getCISourceForEnv } from "../ci_source/ci_source_selector"
import { GitHub } from "../platforms/github"

// import type { Platform } from "../platforms/platform"
// import type { CISource } from "../ci_source/ci_source"
import FakeCI from "../ci_source/fake"

program
.option("-h, --head [commitish]", "TODO: Set the head commitish")
.option("-b, --base [commitish]", "TODO: Set the base commitish")
.option("-f, --fail-on-errors", "TODO: Fail on errors")
.parse(process.argv)

// function setupPlatformWithSource(platform:Platform, source: CISource): void {

// }

let source = getCISourceForEnv(process.env)
let github = new GitHub("token")
let fake = new FakeCI(process.env)
let github = new GitHub("insert here", fake)
github.getInfo()

if (source) {
Expand Down
38 changes: 24 additions & 14 deletions source/platforms/github.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,46 @@
// @flow
"use strict"

import type { CISource } from "../ci_source/ci_source"

// import type { Metadata, Comment, Platform } from "./platform"
import fetch from "node-fetch"
import "babel-polyfill"

export type APIToken = string;
export type GraphQLQuery = string;
export type GraphQLResponse = any;

export class GitHub {
token: APIToken
constructor(token: APIToken) { this.token = token }
ciSource: CISource

constructor(token: APIToken, ciSource: CISource) {
this.token = token
this.ciSource = ciSource
}

async getInfo() : void {
console.log("starting")
let deets = await this.getUserInfo()
console.log(deets)
let deets = await this.getPullRequestInfo()
let pr = await deets.json()
console.log(pr)
}

async getUserInfo(): Promise<any> {
return fetch("https://api.github.com/user", {
method: "GET",
body: "",
headers: { "Authorization": this.token }
})
getUserInfo(): Promise<Response> {
return this.get("user")
}

getPullRequestInfo(): Promise<Response> {
const repo = this.ciSource.repoSlug
const prID = this.ciSource.pullRequestID
return this.get(`repos/${repo}/pulls/${prID}`)
}

async runQuery(query: GraphQLQuery): Promise<GraphQLResponse> {
return fetch("https://api.github.com/user", {
get(path: string, body: any = {}): Promise<Response> {
return fetch(`https://api.github.com/${path}`, {
method: "GET",
body: "",
headers: { "Authorization": "aacf0f931f363a0670f6e8b70ac82c1cdead94c0" }
body: body,
headers: { "Authorization": `token ${this.token}` }
})
}
}
6 changes: 5 additions & 1 deletion source/platforms/platform.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// @flow

import type { CISource } from "../ci_source/ci_source"

/** A type that represents the downloaded metadata about a code review session */
export type Metadata = any;

Expand All @@ -9,7 +11,9 @@ export type Comment = {
body: string
}

// export interface Platform {
export interface Platform {
ciSource: CISource
}
// envVars: () => string[];
// optionalEnvVars: () => string[];

Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ babel-plugin-jest-hoist@^16.0.0:
version "16.0.0"
resolved "https://registry.yarnpkg.com/babel-plugin-jest-hoist/-/babel-plugin-jest-hoist-16.0.0.tgz#b58ca3f770982a7e7c25b5614b2e57e9dafc6e76"

babel-plugin-syntax-async-functions@^6.8.0:
babel-plugin-syntax-async-functions, babel-plugin-syntax-async-functions@^6.8.0:
version "6.13.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-async-functions/-/babel-plugin-syntax-async-functions-6.13.0.tgz#cad9cad1191b5ad634bf30ae0872391e0647be95"

Expand Down Expand Up @@ -635,7 +635,7 @@ babel-plugin-transform-object-rest-spread@^6.16.0:
babel-plugin-syntax-object-rest-spread "^6.8.0"
babel-runtime "^6.0.0"

babel-plugin-transform-regenerator@^6.16.0:
babel-plugin-transform-regenerator, babel-plugin-transform-regenerator@^6.16.0:
version "6.16.1"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-regenerator/-/babel-plugin-transform-regenerator-6.16.1.tgz#a75de6b048a14154aae14b0122756c5bed392f59"
dependencies:
Expand Down

0 comments on commit 22917fc

Please sign in to comment.