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: Issue 453 - NPE #454

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -334,23 +334,25 @@
request.setBranches(gitLabApi.getRepositoryApi().getBranches(gitlabProject));
}
if (request.isFetchMRs() && gitlabProject.getMergeRequestsEnabled()) {
if (!ctx.buildMRForksNotMirror() && gitlabProject.getForkedFromProject() != null) {
final boolean forkedFromProject = (gitlabProject.getForkedFromProject() != null);
if (!ctx.buildMRForksNotMirror() && forkedFromProject) {
listener.getLogger().format("%nIgnoring merge requests as project is a mirror...%n");
} else {
// If not authenticated GitLabApi cannot detect if it is a fork
// If `forkedFromProject` is null it doesn't mean anything
// If `forkedFromProject` is false it doesn't mean anything
listener.getLogger()
.format(
gitlabProject.getForkedFromProject() == null
!forkedFromProject
? "%nUnable to detect if it is a mirror or not still fetching MRs anyway...%n"
: "%nCollecting MRs for fork except those that target its upstream...%n");
Stream<MergeRequest> mrs =
gitLabApi
.getMergeRequestApi()
.getMergeRequests(gitlabProject, MergeRequestState.OPENED)
.stream()
.filter(mr -> mr.getSourceProjectId() != null);
if (ctx.buildMRForksNotMirror()) {
// Patch for issue 453 - avoid an NPE if this isn't a forked project
if (ctx.buildMRForksNotMirror() && forkedFromProject) {

Check warning on line 355 in src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSource.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 337-355 are not covered by tests
mrs = mrs.filter(mr -> !mr.getTargetProjectId()
.equals(gitlabProject.getForkedFromProject().getId()));
}
Expand Down