Skip to content

Commit

Permalink
Merged by Peril
Browse files Browse the repository at this point in the history
Mega grabbag PR
  • Loading branch information
peril-staging[bot] committed Aug 26, 2018
2 parents eba4391 + 2d05ee0 commit ecd41ac
Show file tree
Hide file tree
Showing 34 changed files with 1,060 additions and 1,557 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
"PAPERTRAIL",
"PRDSL",
"PRJSONDSL",
"Schedulable",
"Sidenote",
"dockerhub",
"doggos",
"mockingoose",
"prioritise"
]
}
39 changes: 39 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
## 2018 - August 25

- The edit an installation mutation allows setting a `installationSlackUpdateWebhookURL` on your installation, which
Peril will use to send messages to your installation

- Generic rules for all the org now default to the settings JSON repo, reducing dupes in the settings json - orta

```diff
{
"$schema": "https://raw.githubusercontent.com/danger/peril/master/peril-settings-json.schema",
"rules": {
"create (ref_type == tag)": [
+ "org/new_tag.ts",
- "danger/peril-settings@org/new_tag.ts",
+ "org/updateDangerSystems.ts",
- "danger/peril-settings@org/updateDangerSystems.ts"
],
+ "pull_request.closed": "org/aeryn.ts",
- "pull_request.closed": "danger/peril-settings@org/aeryn.ts",
+ "pull_request": ["org/debug.ts", "org/changelog.ts"],
- "pull_request": ["danger/peril-settings@org/debug.ts", "danger/peril-settings@org/changelog.ts"],
+ "issue_comment": "org/markAsMergeOnGreen.ts",
- "issue_comment": "danger/peril-settings@org/markAsMergeOnGreen.ts",
+ "issues.opened": "org/checkTemplate.ts",
- "issues.opened": "danger/peril-settings@org/checkTemplate.ts",
+ "status.success": "org/mergeOnGreen.ts"
- "status.success": "danger/peril-settings@org/mergeOnGreen.ts"
},
"tasks": {
+ "trigger-scheduler": "testing/trigger-scheduler.ts",
- "trigger-scheduler": "danger/peril-settings@testing/trigger-scheduler.ts",
+ "logger": "testing/logger.ts"
- "logger": "danger/peril-settings@testing/logger.ts"
}
}
```

I'll update thee docs later, once I'm certain all the edge cases are handled.

## 2018 - August 5

- Adds support for relative file imports inside a Dangerfile - orta
Expand Down
17 changes: 17 additions & 0 deletions docs/debugging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### How do debug agenda

Edit `now.staging.json` to include `DEBUG`

```diff
{
"env": {
+ "DEBUG": "agenda:*"
}
}
```

You can throw up a UI to the db using:

```sh
echo "http://localhost:3001"; npx agendash --db=[get this from .env] --collection=agendaJobs --port=3001
```
78 changes: 39 additions & 39 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,55 @@
"setup": "yarn run setup:plugins && yarn run setup:env",
"setup:env": "node out/scripts/setup-env.js",
"setup:plugins": "node out/scripts/setup-plugins.js",
"deploy:staging": "nf run scripts/deploy_staging.sh",
"logs:staging": "/usr/local/bin/now logs --team peril staging-api.peril.systems",
"docker:build:site": "docker build .",
"docker:build:runner": "docker build -f Dockerfile.runner -t runner .",
"runner": "node out/runner/index.js",
"precommit": "lint-staged; yarn build;",
"precommit": "lint-staged; yarn type-check;",
"postcommit": "yarn danger local --dangerfile dangerfile.lite.ts",
"prepush": "jest"
},
"repository": {
"type": "git",
"url": "https://github.com/danger/peril.git"
},
"engines": {
"node": "9"
},
"author": "Orta",
"license": "MIT",
"availablePerilRuntimeDependencies": {
"@slack/client": "3.15.0",
"danger": "^3",
"danger-plugin-spellcheck": "1.2.3",
"danger-plugin-yarn": "1.2.1",
"@slack/client": "^4.5.0",
"danger": "^4",
"danger-plugin-spellcheck": "^1.2.3",
"danger-plugin-yarn": "^1.2.1",
"jira-client": "6.4.1",
"lodash": "4.17.4",
"semver-sort": "0.0.4"
},
"dependencies": {
"@types/agenda": "^2.0.1",
"@slack/client": "^4.5.0",
"@types/agenda": "^2.0.2",
"@types/body-parser": "^1.17.0",
"@types/cookie-parser": "^1.4.1",
"@types/debug": "^0.0.30",
"@types/dotenv": "^4.0.3",
"@types/ejs": "^2.5.1",
"@types/express": "^4.11.1",
"@types/express": "^4.16.0",
"@types/get-stdin": "^5.0.1",
"@types/glob": "^5.0.35",
"@types/jest": "^23.3.1",
"@types/json5": "^0.0.29",
"@types/jsonwebtoken": "^7.2.6",
"@types/json5": "^0.0.30",
"@types/jsonwebtoken": "^7.2.8",
"@types/lodash": "^4.14.116",
"@types/mongodb": "^3.0.15",
"@types/mongoose": "^5.0.10",
"@types/node": "^9.6.6",
"@types/mongodb": "^3.1.4",
"@types/mongoose": "^5.2.7",
"@types/node": "^9.1.2",
"@types/node-cleanup": "^2.1.0",
"@types/node-fetch": "^1.6.9",
"@types/node-fetch": "^2.1.2",
"@types/node-schedule": "^1.2.2",
"@types/winston": "^2.3.9",
"@types/winston": "^2.4.4",
"agenda": "^2.0.0",
"apollo-engine": "^1.1.1",
"apollo-server-express": "^1.3.6",
"async-exit-hook": "^2.0.1",
"babel-cli": "7.0.0-alpha.19",
Expand All @@ -71,41 +75,40 @@
"babel-polyfill": "^6.26.0",
"babel-preset-es2015": "7.0.0-alpha.19",
"babel-preset-stage-3": "7.0.0-alpha.19",
"body-parser": "^1.18.2",
"body-parser": "^1.18.3",
"chalk": "^2.4.1",
"cookie": "^0.3.1",
"cookie-parser": "^1.4.3",
"cors": "^2.8.4",
"danger": "^3.8.6",
"danger-plugin-yarn": "^1.3.0",
"dotenv": "^5.0.1",
"ejs": "^2.5.9",
"express": "^4.16.3",
"express-x-hub": "^1.0.4",
"get-stdin": "^6.0.0",
"github-webhook-event-types": "^1.1.0",
"glob": "^7.1.2",
"graphql": "^0.13.2",
"graphql-playground-middleware-express": "^1.6.1",
"graphql-playground-middleware-express": "^1.7.3",
"graphql-relay-tools": "^0.1.1",
"graphql-resolvers": "^0.2.2",
"graphql-tools": "^3.0.1",
"graphql-tools-types": "^1.1.18",
"graphql-yoga": "^1.8.5",
"graphql-tools": "^3.1.1",
"graphql-tools-types": "^1.1.26",
"graphql-yoga": "^1.16.1",
"hyper-aws4": "^1.1.3",
"jest": "^23.4.2",
"jest": "^23.5.0",
"json2ts": "orta/json2ts#ts-less",
"json5": "^1.0.1",
"jsonwebtoken": "^8.2.1",
"json5": "^2.0.1",
"jsonwebtoken": "^8.3.0",
"lodash": "^4.17.10",
"mongoose": "^5.0.16",
"node-fetch": "2.1.2",
"node-mocks-http": "^1.5.8",
"mongoose": "^5.2.9",
"node-fetch": "2.2.0",
"node-mocks-http": "^1.7.0",
"node-schedule": "^1.3.0",
"override-require": "^1.1.1",
"primus": "^7.2.1",
"ts-jest": "^23.1.2",
"ts-node": "^7.0.0",
"primus": "^7.2.2",
"ts-jest": "^23.1.4",
"ts-node": "^7.0.1",
"tslint": "^5.11.0",
"typescript": "^3.0.1",
"typings": "^2.1.1",
Expand All @@ -114,18 +117,15 @@
"ws": "^5.2.0"
},
"devDependencies": {
"@heroku/foreman": "^2.0.2",
"@types/cookie": "^0.3.1",
"@types/require-from-string": "^1.2.0",
"husky": "^0.14.0",
"lint-staged": "^7.2.0",
"lint-staged": "^7.2.2",
"mockingoose": "^2.10.1",
"now-travis": "^1.2.0",
"prettier": "^1.14.0",
"tslint-config-prettier": "^1.14.0",
"typescript-json-schema": "^0.31.0"
},
"engines": {
"node": "9"
"prettier": "^1.14.2",
"tslint-config-prettier": "^1.15.0",
"typescript-json-schema": "^0.32.0"
},
"jest": {
"transform": {
Expand Down
3 changes: 2 additions & 1 deletion source/ambient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ declare module "json2ts"
declare module "async-exit-hook"
declare module "graphql-resolvers"

// TODO: Make types for these two
// TODO: Make types for these two?
declare module "graphql-tools-types"
declare module "winston"

// https://github.com/excitement-engineer/graphql-relay-tools
declare module "graphql-relay-tools" {
Expand Down
4 changes: 4 additions & 0 deletions source/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ export const sendMessageToConnectionsWithAccessToInstallation = (iID: number, me
})
}

/**
* This is a lazy loaded version of the above, the callback func will only get called
* if there is a connected websocket.
*/
export const sendAsyncMessageToConnectionsWithAccessToInstallation = (
iID: number,
callback: (spark: any) => Promise<any>
Expand Down
2 changes: 1 addition & 1 deletion source/api/graphql/_tests/_graphql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { schema } from "../index"
jest.mock("../../../db/getDB")
import { MockDB } from "../../../db/__mocks__/getDB"
import { getDB } from "../../../db/getDB"
import generateInstallation from "../../../testing/installationFactory"
import { generateInstallation } from "../../../testing/installationFactory"
const mockDB = getDB() as MockDB

beforeEach(() => mockDB.clear())
Expand Down
6 changes: 4 additions & 2 deletions source/api/graphql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ const schemaSDL = gql`
recordWebhooksUntilTime: String
# The time when a user requested recording webhooks
startedRecordingWebhooksTime: String
# A URL for Slack which Peril can send notifications about an installation to
installationSlackUpdateWebhookURL: String
}
# Someone logged in to the API, all user data is stored inside the JWT
Expand Down Expand Up @@ -131,8 +133,8 @@ const schemaSDL = gql`
type Mutation {
# Building this out incrementally, but basically this provides
# the ability to set the URL that Peril should grab data from
editInstallation(iID: Int!, perilSettingsJSONURL: String!): Installation
# the ability to set changes
editInstallation(iID: Int!, perilSettingsJSONURL: String, installationSlackUpdateWebhookURL: String): Installation
# Sets the installation to record webhooks for the next 5m
makeInstallationRecord(iID: Int!): Installation
# Send webhook
Expand Down
33 changes: 26 additions & 7 deletions source/api/graphql/mutations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getDB } from "../../../db/getDB"
import { MongoDB } from "../../../db/mongo"

import { GitHubInstallation } from "../../../db"
import { sendLogsToSlackForInstallation } from "../../../infrastructure/installationSlackMessaging"
import logger from "../../../logger"
import {
getRecordedWebhook,
Expand Down Expand Up @@ -191,25 +192,43 @@ export const mutations = {
// TODO: Store the time in some kind of per-installation analytics document

// Wait 2 seconds for the container to finish
setTimeout(() => {
setTimeout(async () => {
let dangerfileLog: MSGDangerfileLog | undefined

// Get Hyper logs
// Send another message
sendAsyncMessageToConnectionsWithAccessToInstallation(installation.iID, async spark => {
// TODO: Cache the hyper call, because the logs will disappear after the first
// connected client gets access to them.
const getLogs = async () => {
let logs = null
try {
logs = await getHyperLogs(opts.hyperCallID)
} catch (error) {
logger.error(`Requesting the hyper logs for ${installation.iID} with callID ${opts.hyperCallID} - ${error}`)
return
}
const logMessage: MSGDangerfileLog = {
event: opts.name,
action: "log",
filenames: opts.dangerfiles,
log: logs,
log: logs as string,
}
return logMessage
}

// If you have a connected slack webhook, then always grab the logs
// and store the value somewhere where the websocket to admin connections
// can also read.
if (installation.installationSlackUpdateWebhookURL) {
dangerfileLog = await getLogs()
sendLogsToSlackForInstallation("Received logs from Peril", dangerfileLog!, installation)
}

// Callback inside is lazy loaded and only called if there are people
// in the dashboard
sendAsyncMessageToConnectionsWithAccessToInstallation(installation.iID, async spark => {
// If the slack trigger above didn't grab the logs, then re-grab them.
if (!dangerfileLog) {
dangerfileLog = await getLogs()
}
spark.write(logMessage)
spark.write(dangerfileLog)
})
}, 2000)

Expand Down
24 changes: 23 additions & 1 deletion source/danger/_tests/_danger_run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe("for PRs", () => {
])
})

it("returns many runs when there are mutliple potential matches", () => {
it("returns many runs when there are multiple potential matches", () => {
const rules = {
issue: "dangerfile.js",
pull_request: "dangerfile.js",
Expand Down Expand Up @@ -114,6 +114,28 @@ describe("for PRs", () => {
])
})

it("prefixes the repo when that's passed in", () => {
const rules = {
"issue.created, issue.closed": "dangerfile.js",
pull_request: "dangerfile.js",
}

expect(
dangerRunForRules("pull_request", "created", rules, {}, "danger/olives").map(m => m.referenceString)
).toEqual(["danger/[email protected]"])
})

it("doesn't prefix the repo when that's passed in and has a repo reference", () => {
const rules = {
"issue.created, issue.closed": "dangerfile.js",
pull_request: "danger/[email protected]",
}

expect(
dangerRunForRules("pull_request", "created", rules, {}, "danger/olives").map(m => m.referenceString)
).toEqual(["danger/[email protected]"])
})

it("returns null when no multi inline rules match", () => {
const rules = {
"issue.created, pull_request.closed": "dangerfile.js",
Expand Down
9 changes: 8 additions & 1 deletion source/danger/danger_run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export const dangerRunForRules = (
event: string,
action: string | null,
rule: RunnerRuleset | undefined | null,
webhook: any
webhook: any,
prefixRepo?: string
): DangerRun[] => {
// tslint:disable-line
// Can't do anything with nothing
Expand Down Expand Up @@ -103,6 +104,12 @@ export const dangerRunForRules = (
possibilities = possibilities.concat(arr)
})

// Basically, if we provide a prefix repo, the blank repos
// should use that repo
if (prefixRepo) {
possibilities = possibilities.map(p => (p.includes("@") ? p : `${prefixRepo}@${p}`))
}

return possibilities.map(path => ({
action,
dslType: dslTypeForEvent(event),
Expand Down
Loading

0 comments on commit ecd41ac

Please sign in to comment.