Skip to content

Instantly share code, notes, and snippets.

@dmail
Created August 20, 2019 09:11

Revisions

  1. dmail created this gist Aug 20, 2019.
    28 changes: 28 additions & 0 deletions listPullRequestForBranch.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    // https://developer.github.com/v3/pulls/#list-pull-requests
    const fetch = require("node-fetch")

    const listPullRequestForBranch = async ({ token, repoOwner, repoName, head }) => {
    try {
    const href = `https://api.github.com/repos/${repoOwner}/${repoName}/pulls?head=${encodeURIComponent(
    head,
    )}`
    const response = await fetch(href, {
    headers: {
    authorization: `token ${token}`,
    },
    method: "GET",
    })
    const status = response.status
    const responseBodyAsJSON = await response.json()

    if (status !== 200) {
    console.log({
    status,
    responseBodyAsJSON,
    })
    }
    return responseBodyAsJSON
    } catch (e) {
    throw e
    }
    }