feat: adds option to force update new branch in contents routes (#35592)

Allows users to specify a "force" option in API /contents routes when
modifying files in a new branch. When "force" is true, and the branch
already exists, a force push will occur provided the branch does not
have a branch protection rule that disables force pushing.

This is useful as a way to manage a branch remotely through only the
API. For example in an automated release tool you can pull commits,
analyze, and update a release PR branch all remotely without needing to
clone or perform any local git operations.

Resolve #35538

---------

Co-authored-by: Rob Gonnella <rob.gonnella@papayapay.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Rob Gonnella
2025-10-07 00:23:14 -04:00
committed by GitHub
parent ad2ff67343
commit c9e7fde8b3
11 changed files with 160 additions and 47 deletions

View File

@@ -21995,7 +21995,7 @@
"$ref": "#/definitions/Identity"
},
"branch": {
"description": "branch (optional) to base this file from. if not given, the default branch is used",
"description": "branch (optional) is the base branch for the changes. If not supplied, the default branch is used",
"type": "string",
"x-go-name": "BranchName"
},
@@ -22013,13 +22013,18 @@
},
"x-go-name": "Files"
},
"force_push": {
"description": "force_push (optional) will do a force-push if the new branch already exists",
"type": "boolean",
"x-go-name": "ForcePush"
},
"message": {
"description": "message (optional) for the commit of this file. if not supplied, a default message will be used",
"description": "message (optional) is the commit message of the changes. If not supplied, a default message will be used",
"type": "string",
"x-go-name": "Message"
},
"new_branch": {
"description": "new_branch (optional) will make a new branch from `branch` before creating the file",
"description": "new_branch (optional) will make a new branch from base branch for the changes. If not supplied, the changes will be committed to the base branch",
"type": "string",
"x-go-name": "NewBranchName"
},
@@ -22834,7 +22839,7 @@
"$ref": "#/definitions/Identity"
},
"branch": {
"description": "branch (optional) to base this file from. if not given, the default branch is used",
"description": "branch (optional) is the base branch for the changes. If not supplied, the default branch is used",
"type": "string",
"x-go-name": "BranchName"
},
@@ -22849,13 +22854,18 @@
"dates": {
"$ref": "#/definitions/CommitDateOptions"
},
"force_push": {
"description": "force_push (optional) will do a force-push if the new branch already exists",
"type": "boolean",
"x-go-name": "ForcePush"
},
"message": {
"description": "message (optional) for the commit of this file. if not supplied, a default message will be used",
"description": "message (optional) is the commit message of the changes. If not supplied, a default message will be used",
"type": "string",
"x-go-name": "Message"
},
"new_branch": {
"description": "new_branch (optional) will make a new branch from `branch` before creating the file",
"description": "new_branch (optional) will make a new branch from base branch for the changes. If not supplied, the changes will be committed to the base branch",
"type": "string",
"x-go-name": "NewBranchName"
},
@@ -23847,7 +23857,7 @@
"$ref": "#/definitions/Identity"
},
"branch": {
"description": "branch (optional) to base this file from. if not given, the default branch is used",
"description": "branch (optional) is the base branch for the changes. If not supplied, the default branch is used",
"type": "string",
"x-go-name": "BranchName"
},
@@ -23857,13 +23867,18 @@
"dates": {
"$ref": "#/definitions/CommitDateOptions"
},
"force_push": {
"description": "force_push (optional) will do a force-push if the new branch already exists",
"type": "boolean",
"x-go-name": "ForcePush"
},
"message": {
"description": "message (optional) for the commit of this file. if not supplied, a default message will be used",
"description": "message (optional) is the commit message of the changes. If not supplied, a default message will be used",
"type": "string",
"x-go-name": "Message"
},
"new_branch": {
"description": "new_branch (optional) will make a new branch from `branch` before creating the file",
"description": "new_branch (optional) will make a new branch from base branch for the changes. If not supplied, the changes will be committed to the base branch",
"type": "string",
"x-go-name": "NewBranchName"
},
@@ -28639,7 +28654,7 @@
"$ref": "#/definitions/Identity"
},
"branch": {
"description": "branch (optional) to base this file from. if not given, the default branch is used",
"description": "branch (optional) is the base branch for the changes. If not supplied, the default branch is used",
"type": "string",
"x-go-name": "BranchName"
},
@@ -28654,18 +28669,23 @@
"dates": {
"$ref": "#/definitions/CommitDateOptions"
},
"force_push": {
"description": "force_push (optional) will do a force-push if the new branch already exists",
"type": "boolean",
"x-go-name": "ForcePush"
},
"from_path": {
"description": "from_path (optional) is the path of the original file which will be moved/renamed to the path in the URL",
"type": "string",
"x-go-name": "FromPath"
},
"message": {
"description": "message (optional) for the commit of this file. if not supplied, a default message will be used",
"description": "message (optional) is the commit message of the changes. If not supplied, a default message will be used",
"type": "string",
"x-go-name": "Message"
},
"new_branch": {
"description": "new_branch (optional) will make a new branch from `branch` before creating the file",
"description": "new_branch (optional) will make a new branch from base branch for the changes. If not supplied, the changes will be committed to the base branch",
"type": "string",
"x-go-name": "NewBranchName"
},