danger / peril-settings

🔎 The danger org's instance of Peril's settings

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

orta opened this issue · comments

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

Yeah, a better version of this is:

  • A new issue can declare "merge on green", this adds (or creates) the label for that PR
  • A status check gets the PR for the commit, checks if all statuses are green then looks for the label, if the PR is totally green it merges