Skip to content
This repository has been archived by the owner on Apr 8, 2020. It is now read-only.

[WIP] Add rule for closing new pull requests to starter repos #64

Merged
merged 3 commits into from
Dec 20, 2018
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
9 changes: 9 additions & 0 deletions peril.settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
"repos": {
"gatsbyjs/gatsby" : {
"pull_request": ["gatsbyjs/peril-gatsbyjs@rules/validate-yaml.ts"]
},
"gatsbyjs/gatsby-starter-default" : {
"pull_request.opened": ["gatsbyjs/peril-gatsbyjs@rules/pull-request-on-starter.ts"]
},
"gatsbyjs/gatsby-starter-hello-world" : {
"pull_request.opened": ["gatsbyjs/peril-gatsbyjs@rules/pull-request-on-starter.ts"]
},
"gatsbyjs/gatsby-starter-blog" : {
"pull_request.opened": ["gatsbyjs/peril-gatsbyjs@rules/pull-request-on-starter.ts"]
}
},
"tasks": {
Expand Down
39 changes: 39 additions & 0 deletions rules/pull-request-on-starter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { danger, markdown } from "danger"

// TODO: Improve comment
export const comment = (username: string) => `
Hey, @${username}

Thank you for your pull request!

We've moved all our starters over to https://github.com/gatsbyjs/gatsby. Please reopen this there.

Thanks again!
`

export const closePullRequestAndComment = async () => {
const gh = danger.github
const api = gh.api

// Details about the repo.
const owner = gh.thisPR.owner
const repo = gh.thisPR.repo
const number = gh.thisPR.number

// Details about the collaborator.
const username = gh.pr.user.login

// Leave a comment redirecting the collaborator to the monorepo
markdown(comment(username))
// Close this pull request
await api.pullRequests.update({
owner,
repo,
number,
state: "closed",
})
}

export default async () => {
await closePullRequestAndComment()
}
47 changes: 47 additions & 0 deletions tests/pull-request-on-starter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
jest.mock("danger", () => jest.fn())
import * as danger from "danger"

const dm = danger as any

import {
closePullRequestAndComment,
comment,
} from "../rules/pull-request-on-starter"

beforeEach(() => {
dm.danger = {
github: {
thisPR: {
owner: "gatsbyjs",
repo: "peril-gatsbyjs",
number: 1,
},
pr: {
user: {
login: "someUser",
},
},
api: {
pullRequests: {
update: jest.fn(),
},
},
},
}
dm.markdown = jest.fn()
})

describe("an opened pull request", () => {
it("was closed with a comment", async () => {
await closePullRequestAndComment()

expect(dm.danger.github.api.pullRequests.update).toBeCalledWith({
owner: "gatsbyjs",
repo: "peril-gatsbyjs",
number: 1,
state: "closed",
})

expect(dm.markdown).toBeCalledWith(comment("someUser"))
})
})