Edits history of script submission #23197 for ' Create Pull Request (github)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Create Pull Request
     * Open a pull request merging head into base. For a cross-repository PR, set head to 'username:branch'.
     */
    export async function main(
      auth: RT.Github,
      owner: string,
      repo: string,
      title: string,
      head: string,
      base: string,
      body: string | undefined,
      draft: boolean = false,
      maintainer_can_modify: boolean | undefined
    ) {
      const response = await fetch(
        `https://api.github.com/repos/${owner}/${repo}/pulls`,
        {
          method: "POST",
          headers: {
            Authorization: `Bearer ${auth.token}`,
            "Content-Type": "application/json",
            Accept: "application/vnd.github+json",
            "X-GitHub-Api-Version": "2022-11-28",
          },
          body: JSON.stringify({
            title,
            head,
            base,
            body,
            draft,
            maintainer_can_modify,
          }),
        }
      )
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 2 hours ago