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

Fix NullPointerException when autoboxing #460

Merged
merged 4 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
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 @@ -52,8 +52,10 @@
if (!sourceContext.mrCommentTriggerEnabled()) {
continue;
}
if (gitLabSCMSource.getProjectId()
== getPayload().getMergeRequest().getTargetProjectId()
Long projectId = gitLabSCMSource.getProjectId();
if (projectId != null
&& projectId.equals(
getPayload().getMergeRequest().getTargetProjectId())

Check warning on line 58 in src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabMergeRequestCommentTrigger.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 55-58 are not covered by tests
&& isTrustedMember(gitLabSCMSource, sourceContext.getOnlyTrustedMembersCanTrigger())) {
for (Job<?, ?> job : owner.getAllJobs()) {
if (MultiBranchProject.class.isAssignableFrom(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,12 @@ public HashMap<String, AccessLevel> getMembers() {
return members;
}

public long getProjectId() {
public Long getProjectId() {
return projectId;
}

@DataBoundSetter
public void setProjectId(long projectId) {
public void setProjectId(Long projectId) {
this.projectId = projectId;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.jenkins.plugins.gitlabbranchsource;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.lang.reflect.Field;
Expand Down Expand Up @@ -43,4 +44,25 @@ public void afterRestartingJenkinsTransientFieldsAreNotNull() throws Exception {
assertNotNull(mergeRequestContributorCache.get(source));
});
}

@Test
public void projectIdSurvivesConfigRoundtrip() {
plan.then(j -> {
GitLabSCMSourceBuilder sb =
new GitLabSCMSourceBuilder(SOURCE_ID, "server", "creds", "po", "group/project", "project");
WorkflowMultiBranchProject project = j.createProject(WorkflowMultiBranchProject.class, PROJECT_NAME);
GitLabSCMSource source = sb.build();
project.getSourcesList().add(new BranchSource(source));
long p = 42;
source.setProjectId(p);
j.configRoundtrip(project);

WorkflowMultiBranchProject item =
j.jenkins.getItemByFullName(PROJECT_NAME, WorkflowMultiBranchProject.class);
assertNotNull(item);
GitLabSCMSource scmSource = (GitLabSCMSource) item.getSCMSource(SOURCE_ID);
assertNotNull(scmSource);
assertEquals(Long.valueOf(p), scmSource.getProjectId());
});
}
}