How to use the danger/distribution/platforms/github/GitHubUtils.createOrUpdatePR function in danger

To help you get started, we’ve selected a few danger examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github danger / peril / api / source / danger / peril_platform.ts View on Github external
export const getPerilPlatformForDSL = (type: RunType, github: GitHubType | null, githubEvent: any): Platform => {
  if (type === RunType.pr && github) {
    return github
  } else {
    const repoSlug = reposlugFromEvent(githubEvent) || "danger/peril"
    const ref = refFromEvent(githubEvent)

    // This bit of faffing ensures that as the gh utils expands we get
    // compiler errors in peril
    const utils: GitHubUtilsDSL | null = github && {
      fileContents: fileContentsGenerator(github.api.getExternalAPI(), repoSlug, ref),
      createUpdatedIssueWithID: createUpdatedIssueWithIDGenerator(github.api.getExternalAPI()),
      createOrAddLabel: createOrAddLabel(undefined, github.api.getExternalAPI()),
      createOrUpdatePR: createOrUpdatePR(undefined, github.api.getExternalAPI()),
      // Not sure what this looks like for non-PR events
      fileLinks: (paths, _, __, ___) => paths.join(", "),
    }

    const nullFunc: any = () => ""

    const platform: Platform = {
      name: "Peril",
      getFileContents: github ? github.getFileContents.bind(github) : nullFunc,
      // Checks Support should *not* be available if we're not in a GH PR
      platformResultsPreMapper: undefined,

      // deprecated, and not used to my knowledge
      handlePostingResults: () =>
        github ? github.handlePostingResults && github.handlePostingResults.bind(github) : nullFunc,
github danger / peril / api / source / danger / append_peril.ts View on Github external
if (response && response.data && response.data.type === "file") {
        const buffer = Buffer.from(response.data.content, response.data.encoding)
        return buffer.toString()
      } else {
        return ""
      }
    } catch {
      return ""
    }
  },

  createUpdatedIssueWithID: createUpdatedIssueWithIDGenerator(api),
  // TODO: Is this right?
  //       Do I need to move the PR object into here if needed?
  createOrAddLabel: createOrAddLabel(undefined as any, api),
  createOrUpdatePR: createOrUpdatePR(undefined as any, api),
})