0

Updates an existing branch

by
Published Oct 17, 2025

Update an existing branch in your ReadMe project. >📘 > This route is only available to projects that are using [ReadMe Refactored](https://docs.readme.com/main/docs/welcome-to-readme-refactored).

Script readme Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Updates an existing branch
4
 * Update an existing branch in your ReadMe project.
5

6
>📘
7
> This route is only available to projects that are using [ReadMe Refactored](https://docs.readme.com/main/docs/welcome-to-readme-refactored).
8
 */
9
export async function main(auth: RT.Readme, branch: string, body: Body) {
10
	const url = new URL(`https://api.readme.com/v2/branches/${branch}`)
11

12
	const response = await fetch(url, {
13
		method: 'PATCH',
14
		headers: {
15
			'Content-Type': 'application/json',
16
			Authorization: 'Bearer ' + auth.apiKey
17
		},
18
		body: JSON.stringify(body)
19
	})
20
	if (!response.ok) {
21
		const text = await response.text()
22
		throw new Error(`${response.status} ${text}`)
23
	}
24
	return await response.json()
25
}
26

27
/* eslint-disable */
28
/**
29
 * This file was automatically generated by json-schema-to-typescript.
30
 * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
31
 * and run json-schema-to-typescript to regenerate this file.
32
 */
33

34
/**
35
 * Dependent upon the type of resource you are updating this is the representation for a branch or version.
36
 */
37
export type Body =
38
	| {
39
			/**
40
			 * A non-semver display name for the version.
41
			 */
42
			display_name?: string
43
			/**
44
			 * The semver name for the version.
45
			 */
46
			name?: string
47
			privacy?: {
48
				/**
49
				 * Whether the version is public, hidden, or the stable version that's visible by default.
50
				 */
51
				view?: 'default' | 'hidden' | 'public'
52
			}
53
			release_stage?: 'beta' | 'release'
54
			state?: 'current' | 'deprecated'
55
	  }
56
	| {
57
			/**
58
			 * The target rename of the branch and its version prefix.
59
			 */
60
			name: string
61
	  }
62