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

[BUG]: Deleting in a Git Tree Fails When Passing Null or "Null" #120

Open
1 task done
MarkEnverus opened this issue Sep 17, 2024 · 3 comments
Open
1 task done

[BUG]: Deleting in a Git Tree Fails When Passing Null or "Null" #120

MarkEnverus opened this issue Sep 17, 2024 · 3 comments
Labels
Status: Up for grabs Issues that are ready to be worked on by anyone Type: Bug Something isn't working as documented

Comments

@MarkEnverus
Copy link

What happened?

https://docs.github.com/en/rest/git/trees?apiVersion=2022-11-28
When passing a null - the value is not serialized inside TreesPostRequestBody_tree and an error is thrown that Content or Sha must be passed. If you pass a "null" it throws an error => sha null is not a valid blob
We need to be able to pass just a null to delete a blob in a Pull Request (Tree)

`sha string or null
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.`

Versions

octokit v.0.0.14
.net 8

Code of Conduct

  • I agree to follow this project's Code of Conduct
@MarkEnverus MarkEnverus added Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented labels Sep 17, 2024
Copy link

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@kfcampbell kfcampbell moved this from 🆕 Triage to 🔥 Backlog in 🧰 Octokit Active Sep 27, 2024
@kfcampbell kfcampbell added Status: Up for grabs Issues that are ready to be worked on by anyone and removed Status: Triage This is being looked at and prioritized labels Sep 27, 2024
@kfcampbell
Copy link
Member

Interesting...our YAML OpenAPI schema definition looks like this:

  "/repos/{owner}/{repo}/git/trees":
    post:
      summary: Create a tree
      description: |-
        The tree creation API accepts nested entries. If you specify both a tree and a nested path modifying that tree, this endpoint will overwrite the contents of the tree with the new path contents, and create a new tree structure.

        If you use this endpoint to add, delete, or modify the file contents in a tree, you will need to commit the tree and then update a branch to point to the commit. For more information see "[Create a commit](https://docs.github.com/rest/git/commits#create-a-commit)" and "[Update a reference](https://docs.github.com/rest/git/refs#update-a-reference)."

        Returns an error if you try to delete a file that does not exist.
      tags:
      - git
      operationId: git/create-tree
      externalDocs:
        description: API method documentation
        url: https://docs.github.com/rest/git/trees#create-a-tree
      parameters:
      - "$ref": "#/components/parameters/owner"
      - "$ref": "#/components/parameters/repo"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                tree:
                  type: array
                  description: Objects (of `path`, `mode`, `type`, and `sha`) specifying
                    a tree structure.
                  items:
                    type: object
                    properties:
                      path:
                        type: string
                        description: The file referenced in the tree.
                      mode:
                        type: string
                        description: The file mode; one of `100644` for file (blob),
                          `100755` for executable (blob), `040000` for subdirectory
                          (tree), `160000` for submodule (commit), or `120000` for
                          a blob that specifies the path of a symlink.
                        enum:
                        - '100644'
                        - '100755'
                        - '040000'
                        - '160000'
                        - '120000'
                      type:
                        type: string
                        description: Either `blob`, `tree`, or `commit`.
                        enum:
                        - blob
                        - tree
                        - commit
                      sha:
                        type: string
                        description: "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.  \n  \n**Note:** Use either `tree.sha`
                          or `content` to specify the contents of the entry. Using
                          both `tree.sha` and `content` will return an error."
                        nullable: true
                      content:
                        type: string
                        description: "The content you want this file to have. GitHub
                          will write this blob out and use that SHA for this entry.
                          Use either this, or `tree.sha`.  \n  \n**Note:** Use either
                          `tree.sha` or `content` to specify the contents of the entry.
                          Using both `tree.sha` and `content` will return an error."
                base_tree:
                  type: string
                  description: |-
                    The SHA1 of an existing Git tree object which will be used as the base for the new tree. If provided, a new Git tree object will be created from entries in the Git tree object pointed to by `base_tree` and entries defined in the `tree` parameter. Entries defined in the `tree` parameter will overwrite items from `base_tree` with the same `path`. If you're creating new changes on a branch, then normally you'd set `base_tree` to the SHA1 of the Git tree object of the current latest commit on the branch you're working on.
                    If not provided, GitHub will create a new Git tree object from only the entries defined in the `tree` parameter. If you create a new commit pointing to such a tree, then all files which were a part of the parent commit's tree and were not defined in the `tree` parameter will be listed as deleted by the new commit.
              required:
              - tree
            examples:
              default:
                value:
                  base_tree: 9fb037999f264ba9a7fc6274d15fa3ae2ab98312
                  tree:
                  - path: file.rb
                    mode: '100644'
                    type: blob
                    sha: 44b4fc6d56897b048c772eb4087f854f46256132
      responses:
        '201':
          description: Response
          content:
            application/json:
              schema:
                "$ref": "#/components/schemas/git-tree"
              examples:
                default:
                  "$ref": "#/components/examples/git-tree"
          headers:
            Location:
              example: https://api.github.com/repos/octocat/Hello-World/trees/cd8274d15fa3ae2ab983129fb037999f264ba9a7
              schema:
                type: string
        '422':
          "$ref": "#/components/responses/validation_failed"
        '404':
          "$ref": "#/components/responses/not_found"
        '403':
          "$ref": "#/components/responses/forbidden"
        '409':
          "$ref": "#/components/responses/conflict"
      x-github:
        githubCloudOnly: false
        enabledForGitHubApps: true
        category: git
        subcategory: trees

Note nullable: true, which should allow for passing null. Perhaps this is a Kiota issue?

@MarkEnverus
Copy link
Author

is there a work around?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Up for grabs Issues that are ready to be worked on by anyone Type: Bug Something isn't working as documented
Projects
Status: 🔥 Backlog
Development

No branches or pull requests

2 participants