No need to be more strict than server side.tags/7.5
@@ -46,7 +46,7 @@ public class ProjectConfigurationFactory { | |||
Settings projectSettings = new ChildSettings(globalSettings); | |||
addSettings(projectSettings, projectKey); | |||
if (branch.getType() == BranchType.PULL_REQUEST) { | |||
addSettings(projectSettings, generatePullRequestKey(projectKey, branch.getPullRequestId())); | |||
addSettings(projectSettings, generatePullRequestKey(projectKey, branch.getPullRequestKey())); | |||
} else { | |||
addSettings(projectSettings, generateBranchKey(projectKey, branch.getName())); | |||
} |
@@ -105,7 +105,7 @@ public interface AnalysisMetadataHolder { | |||
* | |||
* @throws IllegalStateException if current analysis is not a pull request | |||
*/ | |||
String getPullRequestId(); | |||
String getPullRequestKey(); | |||
/** | |||
* The project as represented by the main branch. It is used to load settings |
@@ -40,7 +40,7 @@ public class AnalysisMetadataHolderImpl implements MutableAnalysisMetadataHolder | |||
private final InitializedProperty<Analysis> baseProjectSnapshot = new InitializedProperty<>(); | |||
private final InitializedProperty<Boolean> crossProjectDuplicationEnabled = new InitializedProperty<>(); | |||
private final InitializedProperty<Branch> branch = new InitializedProperty<>(); | |||
private final InitializedProperty<String> pullRequestId = new InitializedProperty<>(); | |||
private final InitializedProperty<String> pullRequestKey = new InitializedProperty<>(); | |||
private final InitializedProperty<Project> project = new InitializedProperty<>(); | |||
private final InitializedProperty<Integer> rootComponentRef = new InitializedProperty<>(); | |||
private final InitializedProperty<Map<String, QualityProfile>> qProfilesPerLanguage = new InitializedProperty<>(); | |||
@@ -151,16 +151,16 @@ public class AnalysisMetadataHolderImpl implements MutableAnalysisMetadataHolder | |||
} | |||
@Override | |||
public MutableAnalysisMetadataHolder setPullRequestId(String pullRequestId) { | |||
checkState(!this.pullRequestId.isInitialized(), "Pull request id has already been set"); | |||
this.pullRequestId.setProperty(pullRequestId); | |||
public MutableAnalysisMetadataHolder setPullRequestKey(String pullRequestKey) { | |||
checkState(!this.pullRequestKey.isInitialized(), "Pull request key has already been set"); | |||
this.pullRequestKey.setProperty(pullRequestKey); | |||
return this; | |||
} | |||
@Override | |||
public String getPullRequestId() { | |||
checkState(pullRequestId.isInitialized(), "Pull request id has not been set"); | |||
return pullRequestId.getProperty(); | |||
public String getPullRequestKey() { | |||
checkState(pullRequestKey.isInitialized(), "Pull request key has not been set"); | |||
return pullRequestKey.getProperty(); | |||
} | |||
@Override |
@@ -57,5 +57,5 @@ public interface Branch extends ComponentKeyGenerator { | |||
/** | |||
* @throws IllegalStateException if this branch configuration is not a pull request. | |||
*/ | |||
String getPullRequestId(); | |||
String getPullRequestKey(); | |||
} |
@@ -62,9 +62,9 @@ public interface MutableAnalysisMetadataHolder extends AnalysisMetadataHolder { | |||
MutableAnalysisMetadataHolder setBranch(Branch branch); | |||
/** | |||
* @throws IllegalStateException if pull request id has already been set | |||
* @throws IllegalStateException if pull request key has already been set | |||
*/ | |||
MutableAnalysisMetadataHolder setPullRequestId(String pullRequestId); | |||
MutableAnalysisMetadataHolder setPullRequestKey(String pullRequestKey); | |||
/** | |||
* @throws IllegalStateException if project has already been set |
@@ -181,7 +181,7 @@ public class PostProjectAnalysisTasksExecutor implements ComputationStepExecutor | |||
private BranchImpl createBranch() { | |||
org.sonar.server.computation.task.projectanalysis.analysis.Branch analysisBranch = analysisMetadataHolder.getBranch(); | |||
if (!analysisBranch.isLegacyFeature()) { | |||
String branchKey = analysisBranch.getType() == PULL_REQUEST ? analysisBranch.getPullRequestId() : analysisBranch.getName(); | |||
String branchKey = analysisBranch.getType() == PULL_REQUEST ? analysisBranch.getPullRequestKey() : analysisBranch.getName(); | |||
return new BranchImpl(analysisBranch.isMain(), branchKey, Branch.Type.valueOf(analysisBranch.getType().name())); | |||
} | |||
return null; |
@@ -88,7 +88,7 @@ public class BranchPersisterImpl implements BranchPersister { | |||
dto.setMergeBranchUuid(branch.getMergeBranchUuid().orElse(null)); | |||
if (branch.getType() == BranchType.PULL_REQUEST) { | |||
dto.setKey(analysisMetadataHolder.getPullRequestId()); | |||
dto.setKey(analysisMetadataHolder.getPullRequestKey()); | |||
DbProjectBranches.PullRequestData pullRequestData = DbProjectBranches.PullRequestData.newBuilder() | |||
.setBranch(branch.getName()) |
@@ -86,7 +86,7 @@ public class DefaultBranchImpl implements Branch { | |||
} | |||
@Override | |||
public String getPullRequestId() { | |||
public String getPullRequestKey() { | |||
throw new IllegalStateException("Only a branch of type PULL_REQUEST can have a pull request id."); | |||
} | |||
@@ -224,7 +224,7 @@ public class SendIssueNotificationsStep implements ComputationStep { | |||
@CheckForNull | |||
private String getPullRequest() { | |||
Branch branch = analysisMetadataHolder.getBranch(); | |||
return branch.getType() == PULL_REQUEST ? analysisMetadataHolder.getPullRequestId() : null; | |||
return branch.getType() == PULL_REQUEST ? analysisMetadataHolder.getPullRequestKey() : null; | |||
} | |||
} |
@@ -247,27 +247,27 @@ public class AnalysisMetadataHolderImplTest { | |||
AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl(); | |||
String pullRequestId = "pr-123"; | |||
underTest.setPullRequestId(pullRequestId); | |||
underTest.setPullRequestKey(pullRequestId); | |||
assertThat(underTest.getPullRequestId()).isEqualTo(pullRequestId); | |||
assertThat(underTest.getPullRequestKey()).isEqualTo(pullRequestId); | |||
} | |||
@Test | |||
public void getPullRequestId_throws_ISE_when_holder_is_not_initialized() { | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Pull request id has not been set"); | |||
expectedException.expectMessage("Pull request key has not been set"); | |||
new AnalysisMetadataHolderImpl().getPullRequestId(); | |||
new AnalysisMetadataHolderImpl().getPullRequestKey(); | |||
} | |||
@Test | |||
public void setPullRequestId_throws_ISE_when_called_twice() { | |||
AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl(); | |||
underTest.setPullRequestId("pr-123"); | |||
underTest.setPullRequestKey("pr-123"); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Pull request id has already been set"); | |||
underTest.setPullRequestId("pr-234"); | |||
expectedException.expectMessage("Pull request key has already been set"); | |||
underTest.setPullRequestKey("pr-234"); | |||
} | |||
@Test |
@@ -171,13 +171,13 @@ public class AnalysisMetadataHolderRule extends ExternalResource implements Muta | |||
} | |||
@Override | |||
public MutableAnalysisMetadataHolder setPullRequestId(String pullRequestId) { | |||
this.pullRequestId.setProperty(pullRequestId); | |||
public MutableAnalysisMetadataHolder setPullRequestKey(String pullRequestKey) { | |||
this.pullRequestId.setProperty(pullRequestKey); | |||
return this; | |||
} | |||
@Override | |||
public String getPullRequestId() { | |||
public String getPullRequestKey() { | |||
checkState(pullRequestId.isInitialized(), "Pull request id has not been set"); | |||
return pullRequestId.getProperty(); | |||
} |
@@ -122,13 +122,13 @@ public class MutableAnalysisMetadataHolderRule extends ExternalResource implemen | |||
} | |||
@Override | |||
public String getPullRequestId() { | |||
return delegate.getPullRequestId(); | |||
public String getPullRequestKey() { | |||
return delegate.getPullRequestKey(); | |||
} | |||
@Override | |||
public MutableAnalysisMetadataHolder setPullRequestId(String pullRequestId) { | |||
delegate.setPullRequestId(pullRequestId); | |||
public MutableAnalysisMetadataHolder setPullRequestKey(String pullRequestKey) { | |||
delegate.setPullRequestKey(pullRequestKey); | |||
return this; | |||
} | |||
@@ -302,7 +302,7 @@ public class PostProjectAnalysisTasksExecutorTest { | |||
} | |||
@Override | |||
public String getPullRequestId() { | |||
public String getPullRequestKey() { | |||
throw new UnsupportedOperationException(); | |||
} | |||
@@ -87,7 +87,7 @@ public class BranchPersisterImplTest { | |||
public void persist_pull_request_data() { | |||
String pullRequestId = "pr-123"; | |||
analysisMetadataHolder.setBranch(createBranch(BranchType.PULL_REQUEST, false, pullRequestId)); | |||
analysisMetadataHolder.setPullRequestId(pullRequestId); | |||
analysisMetadataHolder.setPullRequestKey(pullRequestId); | |||
treeRootHolder.setRoot(BRANCH); | |||
// add main branch in project table and in metadata |
@@ -944,7 +944,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { | |||
} | |||
@Override | |||
public String getPullRequestId() { | |||
public String getPullRequestKey() { | |||
throw new UnsupportedOperationException(); | |||
} | |||
@@ -20,23 +20,18 @@ | |||
package org.sonar.server.computation.task.projectanalysis.step; | |||
import java.io.IOException; | |||
import java.util.Arrays; | |||
import java.util.Collections; | |||
import java.util.Date; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.Random; | |||
import java.util.stream.Collectors; | |||
import java.util.stream.IntStream; | |||
import java.util.stream.Stream; | |||
import org.apache.commons.lang.RandomStringUtils; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.TemporaryFolder; | |||
import org.mockito.ArgumentCaptor; | |||
import org.mockito.exceptions.verification.junit.ArgumentsAreDifferent; | |||
import org.sonar.api.notifications.Notification; | |||
import org.sonar.api.rules.RuleType; | |||
import org.sonar.api.utils.Duration; | |||
@@ -68,7 +63,6 @@ import static java.util.Arrays.stream; | |||
import static java.util.Collections.shuffle; | |||
import static java.util.stream.Collectors.toList; | |||
import static java.util.stream.Stream.concat; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.mockito.ArgumentCaptor.forClass; | |||
import static org.mockito.ArgumentMatchers.eq; | |||
@@ -233,7 +227,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { | |||
new DefaultIssue().setType(randomRuleType).setEffort(ISSUE_DURATION).setCreationDate(new Date(ANALYSE_DATE))).close(); | |||
when(notificationService.hasProjectSubscribersForTypes(branch.uuid(), NOTIF_TYPES)).thenReturn(true); | |||
analysisMetadataHolder.setBranch(newPullRequest()); | |||
analysisMetadataHolder.setPullRequestId(PULL_REQUEST_ID); | |||
analysisMetadataHolder.setPullRequestKey(PULL_REQUEST_ID); | |||
underTest.execute(); | |||
@@ -500,7 +494,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { | |||
when(branch.isMain()).thenReturn(false); | |||
when(branch.getType()).thenReturn(PULL_REQUEST); | |||
when(branch.getName()).thenReturn(BRANCH_NAME); | |||
when(branch.getPullRequestId()).thenReturn(PULL_REQUEST_ID); | |||
when(branch.getPullRequestKey()).thenReturn(PULL_REQUEST_ID); | |||
return branch; | |||
} | |||