You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit c9b31b0
Browse filesBrowse the repository at this point in the historyBrowse files
fix: support binary file content via base64 encoding in create_or_update_file and push_files
JSON tool arguments must be valid UTF-8, so binary file content (e.g.
images) could not be written through create_or_update_file or
push_files: the content string was passed through verbatim, corrupting
non-UTF-8 bytes.
Add an optional encoding parameter (utf-8, the default, or base64)
to both tools. For base64 content, create_or_update_file decodes it
once before handing the raw bytes to the Contents API. push_files
uploads decoded content as a git blob and references it by SHA in the
tree, because the Trees API rejects TreeEntry content that is not
valid UTF-8. Invalid base64 and unsupported encoding values return
clear tool errors.
Closes#3312
Copy file name to clipboardExpand all lines: pkg/github/__toolsnaps__/create_or_update_file.snap
+10-1Lines changed: 10 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,16 @@
17
17
"type": "string"
18
18
},
19
19
"content": {
20
-
"description": "Content of the file, exactly as it should appear once written. Do not base64-encode it; this server does that before calling the REST API.",
20
+
"description": "Content of the file, exactly as it should appear once written. Do not base64-encode it; this server does that before calling the REST API. If the content is binary (for example an image), pass it base64-encoded together with encoding \"base64\".",
21
+
"type": "string"
22
+
},
23
+
"encoding": {
24
+
"default": "utf-8",
25
+
"description": "Encoding of the content parameter. \"utf-8\" (default) writes the content as-is. \"base64\" decodes the content once and writes the resulting raw bytes; use it for binary files such as images, whose bytes cannot be represented in a JSON string.",
Copy file name to clipboardExpand all lines: pkg/github/__toolsnaps__/push_files.snap
+11-2Lines changed: 11 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -12,12 +12,21 @@
12
12
"type": "string"
13
13
},
14
14
"files": {
15
-
"description": "Array of file objects to push, each object with path (string) and content (string)",
15
+
"description": "Array of file objects to push, each with path (string), content (string), and optional encoding (\"utf-8\" or \"base64\"; defaults to \"utf-8\")",
16
16
"items": {
17
17
"additionalProperties": false,
18
18
"properties": {
19
19
"content": {
20
-
"description": "file content",
20
+
"description": "file content; when encoding is \"base64\", this is the base64-encoded content of the file",
21
+
"type": "string"
22
+
},
23
+
"encoding": {
24
+
"default": "utf-8",
25
+
"description": "Encoding of the file content. \"utf-8\" (default) writes the content as-is. \"base64\" decodes the content once and writes the resulting raw bytes; use it for binary files such as images, whose bytes cannot be represented in a JSON string.",
Copy file name to clipboardExpand all lines: pkg/github/repositories.go
+75-15Lines changed: 75 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -437,7 +437,13 @@ SHA MUST be provided for existing file updates.
437
437
},
438
438
"content": {
439
439
Type: "string",
440
-
Description: "Content of the file, exactly as it should appear once written. Do not base64-encode it; this server does that before calling the REST API.",
440
+
Description: "Content of the file, exactly as it should appear once written. Do not base64-encode it; this server does that before calling the REST API. If the content is binary (for example an image), pass it base64-encoded together with encoding \"base64\".",
441
+
},
442
+
"encoding": {
443
+
Type: "string",
444
+
Description: "Encoding of the content parameter. \"utf-8\" (default) writes the content as-is. \"base64\" decodes the content once and writes the resulting raw bytes; use it for binary files such as images, whose bytes cannot be represented in a JSON string.",
445
+
Enum: []any{"utf-8", "base64"},
446
+
Default: json.RawMessage(`"utf-8"`),
441
447
},
442
448
"message": {
443
449
Type: "string",
@@ -492,7 +498,22 @@ SHA MUST be provided for existing file updates.
492
498
}
493
499
494
500
// json.Marshal encodes byte arrays with base64, which is required for the API.
Description: "Array of file objects to push, each object with path (string) and content (string)",
1660
+
Description: "Array of file objects to push, each with path (string), content (string), and optional encoding (\"utf-8\" or \"base64\"; defaults to \"utf-8\")",
Description: "file content; when encoding is \"base64\", this is the base64-encoded content of the file",
1672
+
},
1673
+
"encoding": {
1674
+
Type: "string",
1675
+
Description: "Encoding of the file content. \"utf-8\" (default) writes the content as-is. \"base64\" decodes the content once and writes the resulting raw bytes; use it for binary files such as images, whose bytes cannot be represented in a JSON string.",
0 commit comments