-
Notifications
You must be signed in to change notification settings - Fork 769
Description
Describe the bug
https://developer.github.com/v3/git/trees/#create-a-tree allows content field or sha field. You could not use both but you could send sha with null value if you populated the content field
https://developer.github.com/enterprise/2.16/v3/git/trees/
The SHA1 checksum ID of the object in the tree. Also called tree.sha.
Note: Use either tree.sha or content to specify the contents of the entry. Using both tree.sha and content will return an error.
With 2.17+ API's
https://developer.github.com/enterprise/2.17/v3/git/trees/
The SHA1 checksum ID of the object in the tree. Also called tree.sha. If the value is null then the file will be deleted.
Note: Use either tree.sha or content to specify the contents of the entry. Using both tree.sha and content will return an error.
In the library a sha field is always sent with null value even if we choose to just send the content field because of serialization of the TreeEntry fields.
https://github.com/github-api/github-api/blob/d1507f26668950508e0bf242c34cdb599003991a/src/main/java/org/kohsuke/github/GHTreeBuilder.java#L24
To Reproduce
- Create a sample repo
- Use https://github.com/github-api/github-api/blob/d1507f26668950508e0bf242c34cdb599003991a/src/main/java/org/kohsuke/github/GHTreeBuilder.java#L111 to add an entry (no sha required)
- Invoke https://github.com/github-api/github-api/blob/d1507f26668950508e0bf242c34cdb599003991a/src/main/java/org/kohsuke/github/GHTreeBuilder.java#L164
The curl equivalent is:
curl -X POST \
https://github.com/api/v3/repos/org/repo/git/trees \
-H 'Authorization: token <>' \
-H 'Content-Type: application/json' \
-d '{
"base_tree": "base_sha",
"tree": [
{
"path": "somePath",
"mode": "100644",
"type": "blob",
"sha": null,
"content": "someText"
}
]
}'
Expected behavior
Tree must be created but instead we see:
{
"message": "Must supply tree.sha or tree.content",
"documentation_url": "https://developer.github.com/enterprise/2.18/v3/git/trees/#create-a-tree"
}
Desktop (please complete the following information):
Latest version
Additional context
Adding a @JsonInclude(Include.NON_NULL) in https://github.com/github-api/github-api/blob/d1507f26668950508e0bf242c34cdb599003991a/src/main/java/org/kohsuke/github/GHTreeBuilder.java#L20 will fix the issue according to me
@JsonInclude(Include.NON_NULL)
private static final class TreeEntry {
private final String path;
private final String mode;
private final String type;
private String sha;
private String content;
private TreeEntry(String path, String mode, String type) {
this.path = path;
this.mode = mode;
this.type = type;
}
}