Skip to content

Commit

Permalink
Merge pull request #194 from danger/preparation_for_peril
Browse files Browse the repository at this point in the history
[WIP] Changes made during Peril work
  • Loading branch information
orta committed Mar 30, 2017
2 parents d388b29 + 5eef02d commit 0e54770
Show file tree
Hide file tree
Showing 19 changed files with 523 additions and 369 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ dangerfile.js
env
.eslintrc.json
jsconfig.json
coverage
9 changes: 8 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
### master

// Add your own contribution below
// Add your own contribution below, ideally with a consumer's perspective in mind.

* Updated jest-* dependencies to 19.x - orta

Updating the jest-* dependencies seems to be exhibiting strange behavior in tests for windows if you update, and
use windows, can you please confirm that everything is 👍

* Added type shapings to `JSONPatchForFile` - orta

### 0.14.2

Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,31 +78,31 @@
"@types/debug": "0.0.29",
"@types/jest": "^19.2.1",
"@types/node-fetch": "^1.6.6",
"babel-cli": "^6.16.0",
"babel-cli": "6.16",
"babel-plugin-syntax-async-functions": "^6.13.0",
"babel-plugin-transform-flow-strip-types": "^6.8.0",
"babel-plugin-transform-regenerator": "^6.16.1",
"babel-preset-es2015": "^6.16.0",
"babel-preset-stage-3": "^6.17.0",
"babel-plugin-transform-flow-strip-types": "^6.22.0",
"babel-plugin-transform-regenerator": "^6.22.0",
"babel-preset-es2015": "^6.24.0",
"babel-preset-stage-3": "^6.22.0",
"husky": "^0.12.0",
"in-publish": "^2.0.0",
"jest": "^19.0.2",
"lint-staged": "^3.2.5",
"madge": "^1.4.4",
"shx": "^0.2.1",
"ts-jest": "^19.0.0",
"ts-jest": "^19.0.2",
"ts-node": "^3.0.0",
"tslint": "^4.4.0",
"tslint": "^4.5.1",
"typescript": "2.2.1"
},
"dependencies": {
"babel-polyfill": "^6.20.0",
"chalk": "^1.1.1",
"commander": "^2.9.0",
"debug": "^2.6.0",
"jest-config": "^18.0.0",
"jest-environment-node": "^18.1.0",
"jest-runtime": "^18.0.0",
"jest-config": "^19.0.2",
"jest-environment-node": "^19.0.2",
"jest-runtime": "^19.0.2",
"jsome": "^2.3.25",
"jsonpointer": "^4.0.1",
"lodash.find": "^4.6.0",
Expand Down
9 changes: 9 additions & 0 deletions source/ci_source/ci_source.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@

/** A json object that represents the outer ENV */
export type Env = any

/** Key details about a repo */
export interface RepoMetaData {
/** A path like "artsy/eigen" */
repoSlug: string,
/** The ID for the pull/merge request "11" */
pullRequestID: string
}

/** The shape of an object that represents an individual CI */
export interface CISource {
/** The project name, mainly for showing errors */
Expand Down
6 changes: 3 additions & 3 deletions source/ci_source/ci_source_helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Env, CISource } from "./ci_source"
import { Env, RepoMetaData } from "./ci_source"
import { GitHubAPI } from "../platforms/github/GitHubAPI"
import { GitHubPRDSL } from "../dsl/GitHubDSL"
import * as find from "lodash.find"
Expand Down Expand Up @@ -42,12 +42,12 @@ export function ensureEnvKeysAreInt(env: Env, keys: Array<string>): boolean {
* @returns {number} The pull request ID, if any. Otherwise 0 (Github starts from #1).
* If there are multiple pull requests open for a branch, returns the first.
*/
export async function getPullRequestIDForBranch(source: CISource, env: Env, branch: string): Promise<number> {
export async function getPullRequestIDForBranch(metadata: RepoMetaData, env: Env, branch: string): Promise<number> {
const token = env["DANGER_GITHUB_API_TOKEN"]
if (!token) {
return 0
}
const api = new GitHubAPI(source, token)
const api = new GitHubAPI(metadata, token)
const prs = await api.getPullRequests() as any[]
const prForBranch: GitHubPRDSL = find(prs, (pr: GitHubPRDSL) => pr.head.ref === branch)
if (prForBranch) {
Expand Down
7 changes: 6 additions & 1 deletion source/danger.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ export interface JSONDiffValue {
removed?: any[]
}

/** A map of string keys to JSONDiffValue */
export interface JSONDiff {
[name: string]: JSONDiffValue
}

// This is `danger.git`

/** The git specific metadata for a PR */
Expand Down Expand Up @@ -190,7 +195,7 @@ export interface GitDSL {
*
* @param {string} filename the path to the json file
*/
JSONDiffForFile(filename: string): Promise<any>,
JSONDiffForFile(filename: string): Promise<JSONDiff>,

/** The Git commit metadata */
readonly commits: Array<GitCommit>
Expand Down
7 changes: 6 additions & 1 deletion source/dsl/GitDSL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export interface JSONDiffValue {
removed?: any[]
}

/** A map of string keys to JSONDiffValue */
export interface JSONDiff {
[name: string]: JSONDiffValue
}

// This is `danger.git`

/** The git specific metadata for a PR */
Expand Down Expand Up @@ -85,7 +90,7 @@ export interface GitDSL {
*
* @param {string} filename the path to the json file
*/
JSONDiffForFile(filename: string): Promise<any>,
JSONDiffForFile(filename: string): Promise<JSONDiff>,

/** The Git commit metadata */
readonly commits: Array<GitCommit>
Expand Down
3 changes: 1 addition & 2 deletions source/platforms/_tests/GitHub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ export const requestWithFixturedJSON = async (path: string): Promise<() => Promi

describe("with fixtured data", () => {
it("returns the correct github data", async () => {
const mockSource = new FakeCI({})
const api = new GitHubAPI(mockSource)
const api = new GitHubAPI({ repoSlug: "unused/metadata", pullRequestID: "1" })
const github = new GitHub(api)
api.getPullRequestInfo = await requestWithFixturedJSON("github_pr.json")

Expand Down
5 changes: 5 additions & 0 deletions source/platforms/_tests/fixtures/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Here's an example CURL request to add a new fixture

```sh
curl -H "Authorization: XXX" curl -H "Accept: application/vnd.github.black-cat-preview+json" --request GET https://api.github.com/repos/artsy/emission/pulls/327/requested_reviewers > source/platforms/_tests/fixtures/requested_reviewers.json
```
21 changes: 21 additions & 0 deletions source/platforms/_tests/fixtures/requested_reviewers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[
{
"login": "ArtsyOpenSource",
"id": 12397828,
"avatar_url": "https://avatars1.githubusercontent.com/u/12397828?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/ArtsyOpenSource",
"html_url": "https://github.com/ArtsyOpenSource",
"followers_url": "https://api.github.com/users/ArtsyOpenSource/followers",
"following_url": "https://api.github.com/users/ArtsyOpenSource/following{/other_user}",
"gists_url": "https://api.github.com/users/ArtsyOpenSource/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ArtsyOpenSource/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ArtsyOpenSource/subscriptions",
"organizations_url": "https://api.github.com/users/ArtsyOpenSource/orgs",
"repos_url": "https://api.github.com/users/ArtsyOpenSource/repos",
"events_url": "https://api.github.com/users/ArtsyOpenSource/events{/privacy}",
"received_events_url": "https://api.github.com/users/ArtsyOpenSource/received_events",
"type": "User",
"site_admin": false
}
]
146 changes: 146 additions & 0 deletions source/platforms/_tests/fixtures/reviews.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
[
{
"id": 2332973,
"user": {
"login": "orta",
"id": 49038,
"avatar_url": "https://avatars1.githubusercontent.com/u/49038?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/orta",
"html_url": "https://github.com/orta",
"followers_url": "https://api.github.com/users/orta/followers",
"following_url": "https://api.github.com/users/orta/following{/other_user}",
"gists_url": "https://api.github.com/users/orta/gists{/gist_id}",
"starred_url": "https://api.github.com/users/orta/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/orta/subscriptions",
"organizations_url": "https://api.github.com/users/orta/orgs",
"repos_url": "https://api.github.com/users/orta/repos",
"events_url": "https://api.github.com/users/orta/events{/privacy}",
"received_events_url": "https://api.github.com/users/orta/received_events",
"type": "User",
"site_admin": false
},
"body": "Generally speaking, there's a _lot_ of similar shaped code here that seems to mainly only be different to the artist a tiny amount\n",
"state": "COMMENTED",
"html_url": "https://github.com/artsy/emission/pull/327#pullrequestreview-2332973",
"pull_request_url": "https://api.github.com/repos/artsy/emission/pulls/327",
"_links": {
"html": {
"href": "https://github.com/artsy/emission/pull/327#pullrequestreview-2332973"
},
"pull_request": {
"href": "https://api.github.com/repos/artsy/emission/pulls/327"
}
},
"submitted_at": "2016-09-30T14:14:11Z",
"commit_id": "76c122e47ee36170c86739bb6cc665b6114e308c"
},
{
"id": 2343835,
"user": {
"login": "orta",
"id": 49038,
"avatar_url": "https://avatars1.githubusercontent.com/u/49038?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/orta",
"html_url": "https://github.com/orta",
"followers_url": "https://api.github.com/users/orta/followers",
"following_url": "https://api.github.com/users/orta/following{/other_user}",
"gists_url": "https://api.github.com/users/orta/gists{/gist_id}",
"starred_url": "https://api.github.com/users/orta/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/orta/subscriptions",
"organizations_url": "https://api.github.com/users/orta/orgs",
"repos_url": "https://api.github.com/users/orta/repos",
"events_url": "https://api.github.com/users/orta/events{/privacy}",
"received_events_url": "https://api.github.com/users/orta/received_events",
"type": "User",
"site_admin": false
},
"body": "",
"state": "COMMENTED",
"html_url": "https://github.com/artsy/emission/pull/327#pullrequestreview-2343835",
"pull_request_url": "https://api.github.com/repos/artsy/emission/pulls/327",
"_links": {
"html": {
"href": "https://github.com/artsy/emission/pull/327#pullrequestreview-2343835"
},
"pull_request": {
"href": "https://api.github.com/repos/artsy/emission/pulls/327"
}
},
"submitted_at": "2016-09-30T15:08:12Z",
"commit_id": "466bdef69fdbcdceb3b35242370edc328605ae1e"
},
{
"id": 2344085,
"user": {
"login": "orta",
"id": 49038,
"avatar_url": "https://avatars1.githubusercontent.com/u/49038?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/orta",
"html_url": "https://github.com/orta",
"followers_url": "https://api.github.com/users/orta/followers",
"following_url": "https://api.github.com/users/orta/following{/other_user}",
"gists_url": "https://api.github.com/users/orta/gists{/gist_id}",
"starred_url": "https://api.github.com/users/orta/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/orta/subscriptions",
"organizations_url": "https://api.github.com/users/orta/orgs",
"repos_url": "https://api.github.com/users/orta/repos",
"events_url": "https://api.github.com/users/orta/events{/privacy}",
"received_events_url": "https://api.github.com/users/orta/received_events",
"type": "User",
"site_admin": false
},
"body": "",
"state": "COMMENTED",
"html_url": "https://github.com/artsy/emission/pull/327#pullrequestreview-2344085",
"pull_request_url": "https://api.github.com/repos/artsy/emission/pulls/327",
"_links": {
"html": {
"href": "https://github.com/artsy/emission/pull/327#pullrequestreview-2344085"
},
"pull_request": {
"href": "https://api.github.com/repos/artsy/emission/pulls/327"
}
},
"submitted_at": "2016-09-30T15:09:27Z",
"commit_id": "466bdef69fdbcdceb3b35242370edc328605ae1e"
},
{
"id": 2344137,
"user": {
"login": "orta",
"id": 49038,
"avatar_url": "https://avatars1.githubusercontent.com/u/49038?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/orta",
"html_url": "https://github.com/orta",
"followers_url": "https://api.github.com/users/orta/followers",
"following_url": "https://api.github.com/users/orta/following{/other_user}",
"gists_url": "https://api.github.com/users/orta/gists{/gist_id}",
"starred_url": "https://api.github.com/users/orta/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/orta/subscriptions",
"organizations_url": "https://api.github.com/users/orta/orgs",
"repos_url": "https://api.github.com/users/orta/repos",
"events_url": "https://api.github.com/users/orta/events{/privacy}",
"received_events_url": "https://api.github.com/users/orta/received_events",
"type": "User",
"site_admin": false
},
"body": "",
"state": "COMMENTED",
"html_url": "https://github.com/artsy/emission/pull/327#pullrequestreview-2344137",
"pull_request_url": "https://api.github.com/repos/artsy/emission/pulls/327",
"_links": {
"html": {
"href": "https://github.com/artsy/emission/pull/327#pullrequestreview-2344137"
},
"pull_request": {
"href": "https://api.github.com/repos/artsy/emission/pulls/327"
}
},
"submitted_at": "2016-09-30T15:09:47Z",
"commit_id": "466bdef69fdbcdceb3b35242370edc328605ae1e"
}
]

0 comments on commit 0e54770

Please sign in to comment.