Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Tree no longer accepts null value in sha field #636

Closed
asthinasthi opened this issue Dec 9, 2019 · 3 comments
Closed

Create Tree no longer accepts null value in sha field #636

asthinasthi opened this issue Dec 9, 2019 · 3 comments
Labels

Comments

@asthinasthi
Copy link

asthinasthi commented Dec 9, 2019

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

  1. Create a sample repo
  2. 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)
  3. 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;
        }
    }
@asthinasthi
Copy link
Author

Suggested changes #642

@bitwiseman bitwiseman added the bug label Dec 13, 2019
@asthinasthi
Copy link
Author

Method is deprecated. So closing this.

@bitwiseman
Copy link
Member

Fixed in #642.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants