fix: handle main/master branch fallback and add branch support in comments#1053
Conversation
✅ Deploy Preview for eclipsefdn-adoptium-trss ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
BugPredict/gw.sh
Outdated
| # Try default branches in order of preference (master first to match bugspots default) | ||
| branches=("master" "main") |
There was a problem hiding this comment.
There is no need to guess user branches at all. If the branch is set, use it in git clone. If the branch is not specified, simply run git clone without the branch.
There was a problem hiding this comment.
There is no need to guess user branches at all. If the branch is set, use it in git clone. If the branch is not specified, simply run
git clonewithout the branch.
@llxia This handles the scenario where a Git branch is not explicitly specified. In such cases, the Ruby script defaults to using master. Since most GitHub repositories default to either main or master, the assumption is that one of these branches should be available. Therefore, when a branch is not provided via the comment, the script should attempt to resolve to main or master. Without this fallback logic, the script will fail for repositories that only use main, if master is assumed by default. The core idea is to make the script resilient by defaulting to main or master when no branch is specified.
This approach prevents failures when analyzing repositories like https://github.com/OpenElements/hiero-enterprise-java, which uses 'main', without requiring users to always specify a branch. By prioritizing 'main' and falling back to 'master', we cover the most common default branch names while maintaining flexibility for user-specified branches.
There was a problem hiding this comment.
I think the overall logic should be
if the user provides userBranch
git clone userRepo userBranch
else
git clone userRepo
set userBranch via git cmd (i.e., git rev-parse --abbrev-ref HEAD)
bugspots -b userBranch userRepoDir
There was a problem hiding this comment.
An example of using branch in bugspots is:
bugspots -b main /root/hiero-enterprise-java
Scanning /root/hiero-enterprise-java repo
Found 38 bugfix commits, with 109 hotspots
There was a problem hiding this comment.
An example of using branch in bugspots is:
bugspots -b main /root/hiero-enterprise-java Scanning /root/hiero-enterprise-java repo Found 38 bugfix commits, with 109 hotspots
@llxia @LongyuZhang this is what I mean. The ruby script defaults master as a branch. Imagine a scennario where we have not specified the branch, that means the repos that default to main as a branch will fail. I will provide examples from the ruby script below.
Note: My assumption is every github repo that is created defaults to main or master but the ruby script only defaults to master which could be wrong on repos that have main as default.
Note: ONLY IMAGINE SCENARIOS WHERE WE DONT SPECIFY THE BRANCH
This error happens because hiero-enterprise-java defaults to main
bugspots /Users/mac/Hiero/hiero-enterprise-java
Scanning /Users/mac/Hiero/hiero-enterprise-java repo
/Users/mac/.rvm/gems/ruby-3.0.0/gems/bugspots-0.2.2/lib/bugspots/scanner.rb:13:in `scan': no such branch in the repo: master (ArgumentError)
from /Users/mac/.rvm/gems/ruby-3.0.0/gems/bugspots-0.2.2/bin/bugspots:49:in `<top (required)>'
from /Users/mac/.rvm/gems/ruby-3.0.0/bin/bugspots:23:in `load'
from /Users/mac/.rvm/gems/ruby-3.0.0/bin/bugspots:23:in `<main>'
This one passes because the project defaults to master
bugspots /Users/mac/maven/maven-dependency-plugin
Scanning /Users/mac/maven/maven-dependency-plugin repo
Found 186 bugfix commits, with 418 hotspots:
Fixes:
- fix: remove duplicate maven-resolver-api and maven-resolver-util dependencies in pom.xml (#526)
- Fix broken link on analyze-exclusions-mojo (#521)
- Bump org.apache.maven.plugins:maven-plugins from 43 to 44 (#516)
- Fix broken link for dependency:collect
- [MDEP-689] Fixes ignored dependency filtering in go-offline goal (#417)
- [MDEP-960] Repair silent logging (#447)
- [MNG-2961] Remove workaround for fixed bug (#441)
- Fix SCM tag
- Delete obsolete commented code for issue that was won't fixed 10 years ago (#446)
- [MDEP-903] Upgrade to Doxia 2.0.0 Milestone Stack
Hotspots:
3.3144 - pom.xml
1.4030 - src/site/apt/index.apt.vm
1.2976 - src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependencySourcesMojo.java
1.1938 - src/test/java/org/apache/maven/plugins/dependency/TestCollectMojo.java
1.1415 - src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestUnpackDependenciesMojo.java
1.0123 - src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo.java
0.9551 - src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestIncludeExcludeUnpackMojo.java
0.9485 - src/it/projects/sources/pom.xml
0.8771 - src/test/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojoTest.java
0.8608 - src/main/java/org/apache/maven/plugins/dependency/analyze/AbstractAnalyzeMojo.java
0.7905 - src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestIncludeExcludeUnpackDependenciesMojo.java
There was a problem hiding this comment.
Branch should be set in bugspots. We should not rely on the default in bugspots. See #1053 (comment)
There was a problem hiding this comment.
When the userBranch is not specified, its value can be obtained with git command, e.g.
cd hiero-enterprise-java; git rev-parse --abbrev-ref HEAD
main
There was a problem hiding this comment.
Branch should be set in bugspots. We should not rely on the default in bugspots. See #1053 (comment)
@llxia @LongyuZhang my bad. It took me long to notice that we are resolving branches using git rev-parse --abbrev-ref HEAD. I will push a fix
No description provided.