dependabot-core icon indicating copy to clipboard operation
dependabot-core copied to clipboard

Adds exception to handle nil buildfile issue

Open sachin-sandhu opened this issue 1 year ago • 4 comments

What are you trying to accomplish?

Fixes following issue:

NoMethodError: undefined method 'content' for nil:NilClass

  original_content = buildfile.content.dup
                              ^^^^^^^^
  gradle/lib/dependabot/gradle/file_updater.rb:116:in `update_version_in_buildfile'
  gradle/lib/dependabot/gradle/file_updater.rb:74:in `block in update_buildfiles_for_dependency'
  gradle/lib/dependabot/gradle/file_updater.rb:62:in `each'
  gradle/lib/dependabot/gradle/file_updater.rb:62:in `update_buildfiles_for_dependency'
  gradle/lib/dependabot/gradle/file_updater.rb:28:in `block in updated_dependency_files'
...
(27 additional frame(s) were not displayed)

Preface:

When managing a large project with several sub-modules, user can work with different configurations. user can create a single repo with all the submodules as part of single project. In this way, all sub modules can be handled as part of single repository.

Another approach would be to manage the submodules in separate repos. Submodules can be added to a parent project via git submodule add https://github.com/<user>/repo repo This way each project (main and sub modules) can be managed differently from each other, this is helpful in cases when a project is intended to be used a sub module in several projects. an example snapshot of a sub module is as following. Here, blockmiui and xtoast are added as submodules to a project. These submodules are managed from their own separate repos.

image

Issue: This issue exists when :dependabot: makes an update to a gradle project. It is observed that dependabot is parsing the files in submodules and treating the files as part of a single repo. This is evident when file_fetcher also treats files ( build.gradle, build.gradle.kts ) from submodules eligible for update. Incidentally, when the file_updater module runs, the submodule project files are not parsed. So in this scenario, a dependency from a submodule while found to be eligible to update, does not have a valid file where it can be updated as submodule files are filtered out in file_updater stage. So no relevant build file is found at original_content = buildfile.content.dup in update_version_in_buildfile.

Fix: Raise "No files changed!" exception if file_updater is not able to find a valid build file eligible for update.

Anything you want to highlight for special attention from reviewers?

How will you know you've accomplished your goal?

If Build file update is not successful, a new exception with message "No files changed!" will be raised.

Checklist

  • [x] I have run the complete test suite to ensure all tests and linters pass.
  • [x] I have thoroughly tested my code changes to ensure they work as expected, including adding additional tests for new functionality.
  • [x] I have written clear and descriptive commit messages.
  • [x] I have provided a detailed description of the changes in the pull request, including the problem it addresses, how it fixes the problem, and any relevant details about the implementation.
  • [x] I have ensured that the code is well-documented and easy to understand.

sachin-sandhu avatar Jun 22 '24 15:06 sachin-sandhu

Is this happening because we don't have sub-modules support?

abdulapopoola avatar Jun 24 '24 17:06 abdulapopoola

Is this happening because we don't have sub-modules support?

I could not confirm it because :dependabot: is parsing the target repo (with sub modules) as one repo in file_fetcher stage. So while making list of dependencies, it is also taking the sub module files into account. But when running the file_updater, :dependabot: filters out the sub module folders from list. But in either of cases, sub modules should have their own dependency management.

sachin-sandhu avatar Jun 24 '24 21:06 sachin-sandhu

Also, great description of the underlying problem... thanks for including the screenshots and code notes, really helped me grok it.

jeffwidman avatar Jun 25 '24 20:06 jeffwidman

@jeffwidman , Please review once you have some time today , thanks !

sachin-sandhu avatar Jun 26 '24 19:06 sachin-sandhu

@jeffwidman , please review once you are available , thanks !

sachin-sandhu avatar Jul 02 '24 14:07 sachin-sandhu