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

Add support for deleting files from tree #1678

Merged
merged 7 commits into from
Jun 29, 2023

Conversation

davseitsev
Copy link
Contributor

@davseitsev davseitsev commented Jun 20, 2023

Fixes #1484
Github API allows deleting files from tree by passing null value in sha field. Existing implementation skips all null fields during serialization due to @JsonInclude(Include.NON_NULL) annotation. This PR adds separate object for delete operation with sha field which is always serialized.

@davseitsev
Copy link
Contributor Author

@bitwiseman could you please take a look?

@codecov
Copy link

codecov bot commented Jun 28, 2023

Codecov Report

Patch coverage: 80.00% and project coverage change: -0.01 ⚠️

Comparison is base (8e73065) 80.00% compared to head (1f585c2) 80.00%.

❗ Current head 1f585c2 differs from pull request most recent head ac2f123. Consider uploading reports for the commit ac2f123 to get more accurate results

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1678      +/-   ##
============================================
- Coverage     80.00%   80.00%   -0.01%     
- Complexity     2223     2224       +1     
============================================
  Files           213      213              
  Lines          6727     6732       +5     
  Branches        365      365              
============================================
+ Hits           5382     5386       +4     
  Misses         1131     1131              
- Partials        214      215       +1     
Impacted Files Coverage Δ
...rc/main/java/org/kohsuke/github/GHTreeBuilder.java 76.31% <80.00%> (+0.55%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Comment on lines 183 to 184
public GHTreeBuilder delete(String path, boolean executable) {
TreeEntry entry = new DeleteTreeEntry(path, executable ? "100755" : "100644", "blob");
Copy link
Member

@bitwiseman bitwiseman Jun 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is executable required for deletion? Does it need to match the tree object that is being deleted?
If not (if delete works regardless of this value), we should remove the executable parameter here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also wonder what happens if the type doesn't match the item at that path.
https://docs.github.com/en/rest/git/trees?apiVersion=2022-11-28#create-a-tree under properties of tree, shows type can be blob, tree, or commit.

This isn't necessarily a blocker, but it would be good to know if there are scenarios that the current delete() method doesn't handle.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is executable required for deletion? Does it need to match the tree object that is being deleted? If not (if delete works regardless of this value), we should remove the executable parameter here.

Yes, it's required for deletion as well and it should be not null.
Reference doc says nothing about what value for mode should be used for deletion but my test shows it works with any valid non-null value. So we can use some hadcoded value. I will change this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also wonder what happens if the type doesn't match the item at that path.

I tested type=commit while deleting a blob and it works fine.

@@ -37,6 +37,15 @@ private TreeEntry(String path, String mode, String type) {
}
}

private static class DeleteTreeEntry extends TreeEntry {
@JsonInclude
private String sha;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is always going to be null right? I'm surprised there wasn't a warning about sha never being assigned/used...
At minimum add a comment explaining what is going on here.

Copy link
Member

@bitwiseman bitwiseman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few questions, but otherwise looks great.

@davseitsev
Copy link
Contributor Author

I've added comments and hardcoded mode value for delete method.
@bitwiseman let me know if I need to fix something else or squash commits in the branch.

@bitwiseman bitwiseman self-requested a review June 29, 2023 16:58
@bitwiseman bitwiseman merged commit c494891 into hub4j:main Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot delete blob from tree
2 participants