-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix gradle file fetcher when included build is in submodule #7078
base: main
Are you sure you want to change the base?
Fix gradle file fetcher when included build is in submodule #7078
Conversation
👋 Thanks for putting this up.
Can you link to the code containing this ignore or explain this more? Do you mean upstream native Gradle java code already has this, or that Dependabot already has a similar ignore in a different section of our codebase? |
dependabot-core/gradle/lib/dependabot/gradle/file_fetcher.rb Lines 83 to 85 in d8840c0
|
Thanks! I am not familiar enough with Gradle to even know the difference between Gradle subprojects vs submodules so I'm not able to evaluate this properly w/o some further digging. So gonna "phone-a-friend(ly-contributor)"... 😄 @soulus13 @yeikel I don't recall if you both are primarily Maven users or also familiar with Gradle... your thoughts on this? |
Yeah, gradle seems to have many ways to define dependencies. There is also something similar in Dependabot for gradle dependency script plugins: dependabot-core/gradle/lib/dependabot/gradle/file_fetcher.rb Lines 113 to 117 in d8840c0
This is just a quick fix to make Dependabot work with gradle included builds in git submodules. This might require some refactoring later but maybe wait for #1164? |
all_buildfiles_in_build(dir) | ||
rescue Dependabot::DependencyFileNotFound | ||
# included build can be in a submodule | ||
nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just realized this is going to catch all failures to find a file, which seems overly broad.
Is there a way to definitively identify that it's in a git submodule? (since it sounds like Gradle Submodules refer to files in git submodules?)
You pointed out the file_exists_in_submodule?
method, could we just use that here too?
dependabot-core/gradle/lib/dependabot/gradle/file_fetcher.rb
Lines 130 to 135 in 4cab0ee
def file_exists_in_submodule?(path) | |
fetch_file_from_host(path, fetch_submodules: true) | |
true | |
rescue Dependabot::DependencyFileNotFound | |
false | |
end |
Ie,
next nil if file_exists_in_submodule?(path)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm more of a Maven guy, but indeed, this solution sounds more logical and aligned with the existing implementation, if we only ignore the File Not Found from submodule
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
For a submodule, GitHub doesn't return a 404, but instead a 200 with I think for submodules the reason it's failing is we don't pass So I think I'm with @jeffwidman, it would be good to check if it's caused by a submodule vs a completely missing directory. |
Another reason why a 404 might be returned can be due to permission denied(401) error. For some reason, the Github API was designed to behave that way How do dependabot token work when they need to cross the boundaries of a repository? |
The 404 comes from request to I added a commit to ignore included build only if its in a git submodule. |
I've setup what I think the situation is here: https://github.com/dsp-testing/gradle-simple/tree/f43d406d67a96305fe5f0adce7a104d541ff5acd If I dry-run this with the CLI
Hitting https://api.github.com/repos/dsp-testing/gradle-simple/contents/include?ref=f43d406d67a96305fe5f0adce7a104d541ff5acd I get a 200 with 404 due to not authorized isn't possible because it's getting the submodule directory from the current project, not trying to get the contents of the submodule from another repo. If you're getting a 404 still from this I'm interested in what your setup is to reproduce that. |
Oh yeah, my included build is in subfolder of a git submodule so requests are little different. The 404 comes from request to I updated spec to match original case (=included build in root of a submodule), the fix works for both cases. |
Thanks for creating this PR, I am running into the same issue. There is an issue #7201 with some details. I checked the logs and for me it's a 404 error. My included build is also in subfolder of a git submodule, and private as well. |
For more people that may find this issue through the PR, there is a work-around suggested by @patari here: |
This should be fixed with #9278, since we're cloning and fetching submodules up front the file should be present. Let me know if it's working for you without this PR. |
If gradle included build is in submodule, dependabot gives error
dependency_file_not_found
from request tohttps://api.github.com:443/repos/<owner>/<repo>/contents/<submodule_path>?ref=<ref>
.This fixes it by ignoring 404 errors from included build files (gradle subprojects already has similar ignore).