Edits history of script submission #23234 for ' Sync Fork Branch with Upstream (github)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Sync Fork Branch with Upstream
     * Merge the upstream repository's changes into a branch of a fork (fast-forward or merge commit).
     */
    export async function main(
      auth: RT.Github,
      owner: string,
      repo: string,
      branch: string
    ) {
      const response = await fetch(
        `https://api.github.com/repos/${owner}/${repo}/merge-upstream`,
        {
          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({ branch }),
        }
      )
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 2 hours ago