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

Let ListAction skip pull requests having no binary data #818

Closed
Closed
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 @@ -19,20 +19,21 @@

import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException;

import com.google.common.base.Strings;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

import javax.annotation.Nullable;

import org.apache.commons.lang.StringUtils;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.api.web.UserRole;
import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
Expand All @@ -51,10 +52,10 @@
import org.sonarqube.ws.ProjectPullRequests;
import org.springframework.beans.factory.annotation.Autowired;

import com.google.common.base.Strings;

public class ListAction extends ProjectWsAction {

private static final Logger logger = Loggers.get(ListAction.class);

private final UserSession userSession;
private final ProtoBufWriter protoBufWriter;

Expand Down Expand Up @@ -120,7 +121,12 @@ private static void addPullRequest(ProjectPullRequests.ListWsResponse.Builder re
ProjectPullRequests.PullRequest.Builder builder = ProjectPullRequests.PullRequest.newBuilder();
builder.setKey(branch.getKey());

DbProjectBranches.PullRequestData pullRequestData = Objects.requireNonNull(branch.getPullRequestData(), "Pull request data should be available for branch type PULL_REQUEST");
DbProjectBranches.PullRequestData pullRequestData = branch.getPullRequestData();
if (pullRequestData == null) {
logger.info("No pull request data available for branch of type PULL_REQUEST with key '%s'", branch.getKey());
return;
}

builder.setBranch(pullRequestData.getBranch());
Optional.ofNullable(Strings.emptyToNull(pullRequestData.getUrl())).ifPresent(builder::setUrl);
Optional.ofNullable(Strings.emptyToNull(pullRequestData.getTitle())).ifPresent(builder::setTitle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ void shouldExecuteRequestWithValidParameter() {
.setBranch("prBranch2")
.setTitle("title3")
.setUrl("url3")
.build())));
.build()),
new BranchDto()
.setBranchType(BranchType.PULL_REQUEST)
.setKey("prKey4")
.setUuid("uuid5")
.setMergeBranchUuid("uuid2")));

when(branchDao.selectByUuids(any(), any())).thenReturn(List.of(new BranchDto()
.setUuid("uuid2")
Expand Down Expand Up @@ -189,4 +194,4 @@ void shouldNotExecuteRequestIfUserDoesNotHaveAnyPermissions() {
verifyNoMoreInteractions(protoBufWriter);
}

}
}