danger / peril-settings

🔎 The danger org's instance of Peril's settings
MIT License
7 stars 3 forks source link

WIP on "allow someone to declare a PR as merge on green" #6

Closed orta closed 6 years ago

orta commented 6 years ago
import { schedule, danger, markdown } from "danger"
import { Status } from "github-webhook-event-types"

import * as semverSort from "semver-sort"
import { stat } from "fs";

const isJest = typeof jest !== "undefined"

// Stores the parameter in a closure that can be invoked in tests.
const storeRFC = (reason: string, closure: () => void | Promise<any>) =>
  // We return a closure here so that the (promise is resolved|closure is invoked)
  // during test time and not when we call rfc().
  () => (closure instanceof Promise ? closure : Promise.resolve(closure()))

// Either schedules the promise for execution via Danger, or invokes closure.
const runRFC = (reason: string, closure: () => void | Promise<any>) => schedule(closure)

export const newTag = runRFC("Send a comment to PRs on new tags that they have been released", async () => {
  const api = danger.github.api
  const status = (danger.github as any) as Status
  const repo= status.repository

  // See https://github.com/maintainers/early-access-feedback/issues/114 for more context on getting a PR from a SHA
  const repoString = repo.full_name
  const searchResponse = await api.search.issues({q: `${status.commit.sha} type:pr is:open repo:${repoString}`})

  // https://developer.github.com/v3/search/#search-issues
  // Turns into an array like ["https://api.github.com/repos/cupy/cupy/pulls/1169"]
  const prsWithCommit = searchResponse.data.map((i :any) => i.id) as number[]
  for (const pr of prsWithCommit) {
    // Get all the comments for that issue
    const comments = await api.issues.getComments({ owner:repo.owner.login, repo: repo.name, number: pr })

  }

})

May make more sense to do a label instead

orta commented 6 years ago

Yeah, a better version of this is:

orta commented 6 years ago

8