-
-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from danger/tests_ok
Add some test structure for the github class + flow typed definition
- Loading branch information
Showing
14 changed files
with
397 additions
and
49 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
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,15 +0,0 @@ | ||
// @flow | ||
|
||
// import danger from "danger" | ||
import { danger, fail } from "./source/danger" | ||
|
||
// warn on changes in Package.json and not in shrinkwrap | ||
const hasChangelog = danger.git.modified_files.includes("changelog.md") | ||
if (!hasChangelog) { | ||
fail("No Changelog changes!") | ||
} | ||
|
||
// warn on changelog | ||
// console.log(danger) | ||
// console.log(danger.git) | ||
// console.log(danger.git.created_files) | ||
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
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,55 @@ | ||
var fs = require("fs") | ||
var fileOutput = "" | ||
|
||
fs.readdir("source/dsl", (err, files) => { | ||
if (err) { return console.log("Could not read DSL folder") } | ||
for (var file of files) { | ||
// Sometimes they have more stuff, in those cases | ||
// offer a way to crop the file. | ||
const content = fs.readFileSync(`source/dsl/${file}`).toString() | ||
if (content.includes("/* END FLOWTYPE")) { | ||
fileOutput += content.split("/* END FLOWTYPE")[0] | ||
} else { | ||
fileOutput += content | ||
} | ||
} | ||
|
||
// The definition of all the exposed vars is inside | ||
// the Dangerfile.js file. | ||
const allDangerfile = fs.readFileSync("source/runner/Dangerfile.js").toString() | ||
const moduleContext = allDangerfile.split("BEGIN FLOWTYPE EXPORT */")[1].split("/* END FLOWTYPE")[0] | ||
|
||
// we need to add either `declare function` or `declare var` to the interface | ||
const context = moduleContext.split("\n").map((line) => { | ||
if ((line.length === 0) || (line.includes("*"))) { return line } | ||
if (line.includes("(")) { return " declare function " + line.trim() } | ||
if (line.includes(":")) { return " declare var " + line.trim() } | ||
}).join("\n") | ||
|
||
fileOutput += ` | ||
declare module "danger" { | ||
declare module.exports: { | ||
${context} | ||
}; | ||
} | ||
` | ||
// Remove all JS-y bits | ||
fileOutput = fileOutput.split("\n").filter((line) => { | ||
return !line.startsWith("import type") && | ||
!line.startsWith('"use strict"') && | ||
!line.startsWith("// @flow") && | ||
!line.includes("* @type ") | ||
}).join("\n") | ||
|
||
// We don't export in the definitions files | ||
fileOutput = fileOutput.replace(/export interface/gi, "interface") | ||
|
||
// Remove any 2 line breaks | ||
fileOutput = fileOutput.replace(/\n\s*\n/g, "\n") | ||
|
||
// This is so you can get it for this repo 👍 | ||
fs.writeFileSync("flow-typed/npm/danger_v0.x.x.js", fileOutput) | ||
|
||
console.log("Awesome - shipped to flow-typed/npm/danger_v0.x.x.js") | ||
console.log("This should get sent to the main repo.") | ||
}) |
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
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
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,14 +1,37 @@ | ||
// @flow | ||
"use strict" | ||
|
||
import type { GitDSL } from "../dsl/Git" | ||
import type { GitDSL } from "../dsl/GitDSL" | ||
import type { GitHubDSL } from "../dsl/GitHubDSL" | ||
|
||
export default class DangerDSL { | ||
/** | ||
* The Danger DSL provides the metadata for introspection | ||
* in order to create your own rules. | ||
*/ | ||
export interface DangerDSLType { | ||
/** | ||
* Details specific to the git changes within the code changes. | ||
* Currently, this is just the raw file paths that have been | ||
* added, removed or modified. | ||
*/ | ||
git: GitDSL; | ||
/** | ||
* The GitHub metadata. | ||
* Currently, this is just the raw PR information. | ||
*/ | ||
github: GitHubDSL; | ||
} | ||
|
||
/* END FLOWTYPE EXPORT */ | ||
|
||
export class DangerDSL { | ||
git: GitDSL | ||
pr: any | ||
github: GitHubDSL | ||
|
||
constructor(pr: any, git: GitDSL) { | ||
this.git = git | ||
this.pr = pr | ||
this.github = { | ||
pr | ||
} | ||
} | ||
} |
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,21 @@ | ||
// @flow | ||
"use strict" | ||
|
||
export interface GitDSL { | ||
/** | ||
* Filepaths with changes relative to the git root | ||
* @type {string[]} | ||
*/ | ||
modified_files: string[], | ||
/** | ||
* Newly created filepaths relative to the git root | ||
* @type {string[]} | ||
*/ | ||
created_files: string[], | ||
/** | ||
* Removed filepaths relative to the git root | ||
* @type {string[]} | ||
*/ | ||
deleted_files: string[] | ||
} | ||
|
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,180 @@ | ||
// @flow | ||
"use strict" | ||
|
||
export interface GitHubDSL { | ||
/** | ||
* The PR metadata for a code review session | ||
* @type {GitHubPRDSL} | ||
*/ | ||
pr: GitHubPRDSL | ||
} | ||
|
||
/** | ||
* A GitHub user account | ||
*/ | ||
export interface GitHubUser { | ||
/** | ||
* Generic UUID | ||
* @type {number} | ||
*/ | ||
id: number, | ||
/** | ||
* The handle for the user/org | ||
* @type {string} | ||
*/ | ||
login: string, | ||
/** | ||
* Whether the user is an org, or a user | ||
* @type {string} | ||
*/ | ||
type: "User" | "Organization" | ||
} | ||
|
||
/** | ||
* A GitHub Repo | ||
*/ | ||
export interface GitHubRepo { | ||
/** | ||
* Generic UUID | ||
* @type {number} | ||
*/ | ||
id: number, | ||
|
||
/** | ||
* The name of the repo, e.g. "Danger-JS" | ||
* @type {string} | ||
*/ | ||
name: string, | ||
|
||
/** | ||
* The full name of the owner + repo, e.g. "Danger/Danger-JS" | ||
* @type {string} | ||
*/ | ||
full_name: string, | ||
|
||
/** | ||
* The owner of the repo | ||
* @type {GitHubUser} | ||
*/ | ||
owner: GitHubUser, | ||
|
||
/** | ||
* Is the repo publicly accessible? | ||
* @type {bool} | ||
*/ | ||
private: bool, | ||
|
||
/** | ||
* The textual description of the repo | ||
* @type {string} | ||
*/ | ||
description: string, | ||
|
||
/** | ||
* Is the repo a fork? | ||
* @type {bool} | ||
*/ | ||
fork: false | ||
} | ||
|
||
export interface GitHubMergeRef { | ||
/** | ||
* The human display name for the merge reference, e.g. "artsy:master" | ||
* @type {string} | ||
*/ | ||
label: string, | ||
|
||
/** | ||
* The reference point for the merge, e.g. "master" | ||
* @type {string} | ||
*/ | ||
ref: string, | ||
|
||
/** | ||
* The reference point for the merge, e.g. "704dc55988c6996f69b6873c2424be7d1de67bbe" | ||
* @type {string} | ||
*/ | ||
sha: string, | ||
|
||
/** | ||
* The user that owns the merge reference e.g. "artsy" | ||
* @type {string} | ||
*/ | ||
user: GitHubUser | ||
} | ||
|
||
export interface GitHubPRDSL { | ||
/** | ||
* The UUID for the PR | ||
* @type {number} | ||
*/ | ||
number: number, | ||
|
||
/** | ||
* The state for the PR | ||
* @type {string} | ||
*/ | ||
state: "closed" | "open" | "locked" | "merged", | ||
|
||
/** | ||
* Has the PR been locked to contributors only? | ||
* @type {boolean} | ||
*/ | ||
locked: boolean, | ||
|
||
/** | ||
* The title of the PR | ||
* @type {string} | ||
*/ | ||
title: string, | ||
|
||
/** | ||
* The markdown body message of the PR | ||
* @type {string} | ||
*/ | ||
body: string, | ||
|
||
/** | ||
* ISO6801 Date string for when PR was created | ||
* @type {string} | ||
*/ | ||
created_at: string, | ||
|
||
/** | ||
* ISO6801 Date string for when PR was updated | ||
* @type {string} | ||
*/ | ||
updated_at: string, | ||
|
||
/** | ||
* optional ISO6801 Date string for when PR was closed | ||
* @type {string} | ||
*/ | ||
closed_at: ?string, | ||
|
||
/** | ||
* Optional ISO6801 Date string for when PR was merged. | ||
* Danger probably shouldn't be running in this state. | ||
* @type {string} | ||
*/ | ||
merged_at: ?string, | ||
|
||
/** | ||
* Merge reference for the _other_ repo. | ||
* @type {GitHubMergeRef} | ||
*/ | ||
head: GitHubMergeRef, | ||
|
||
/** | ||
* Merge reference for _this_ repo. | ||
* @type {GitHubMergeRef} | ||
*/ | ||
base: GitHubMergeRef, | ||
|
||
/** | ||
* The User who submitted the PR | ||
* @type {GitHubUser} | ||
*/ | ||
user: GitHubUser | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.