You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IssueQueryFactory.java 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2023 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.server.issue.index;
  21. import com.google.common.base.Joiner;
  22. import com.google.common.collect.ImmutableList;
  23. import java.time.Clock;
  24. import java.time.DateTimeException;
  25. import java.time.OffsetDateTime;
  26. import java.time.Period;
  27. import java.time.ZoneId;
  28. import java.util.ArrayList;
  29. import java.util.Arrays;
  30. import java.util.Collection;
  31. import java.util.Collections;
  32. import java.util.Date;
  33. import java.util.HashSet;
  34. import java.util.List;
  35. import java.util.Locale;
  36. import java.util.Map;
  37. import java.util.Objects;
  38. import java.util.Optional;
  39. import java.util.Set;
  40. import java.util.stream.Collectors;
  41. import javax.annotation.Nullable;
  42. import org.apache.commons.lang.BooleanUtils;
  43. import org.jetbrains.annotations.NotNull;
  44. import org.slf4j.Logger;
  45. import org.slf4j.LoggerFactory;
  46. import org.sonar.api.resources.Qualifiers;
  47. import org.sonar.api.rule.RuleKey;
  48. import org.sonar.api.rules.RuleType;
  49. import org.sonar.api.server.ServerSide;
  50. import org.sonar.db.DbClient;
  51. import org.sonar.db.DbSession;
  52. import org.sonar.db.component.BranchDto;
  53. import org.sonar.db.component.ComponentDto;
  54. import org.sonar.db.component.SnapshotDto;
  55. import org.sonar.db.permission.GlobalPermission;
  56. import org.sonar.db.rule.RuleDto;
  57. import org.sonar.server.issue.SearchRequest;
  58. import org.sonar.server.issue.index.IssueQuery.PeriodStart;
  59. import org.sonar.server.user.UserSession;
  60. import static com.google.common.base.Preconditions.checkArgument;
  61. import static com.google.common.base.Strings.isNullOrEmpty;
  62. import static com.google.common.collect.Collections2.transform;
  63. import static java.lang.String.format;
  64. import static java.util.Collections.singleton;
  65. import static java.util.Collections.singletonList;
  66. import static org.sonar.api.issue.Issue.STATUSES;
  67. import static org.sonar.api.issue.Issue.STATUS_REVIEWED;
  68. import static org.sonar.api.issue.Issue.STATUS_TO_REVIEW;
  69. import static org.sonar.api.measures.CoreMetrics.ANALYSIS_FROM_SONARQUBE_9_4_KEY;
  70. import static org.sonar.api.utils.DateUtils.longToDate;
  71. import static org.sonar.api.utils.DateUtils.parseEndingDateOrDateTime;
  72. import static org.sonar.api.utils.DateUtils.parseStartingDateOrDateTime;
  73. import static org.sonar.api.web.UserRole.SCAN;
  74. import static org.sonar.api.web.UserRole.USER;
  75. import static org.sonar.db.newcodeperiod.NewCodePeriodType.REFERENCE_BRANCH;
  76. import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENTS;
  77. import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_UUIDS;
  78. import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_CREATED_AFTER;
  79. import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_CREATED_IN_LAST;
  80. import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_IN_NEW_CODE_PERIOD;
  81. /**
  82. * This component is used to create an IssueQuery, in order to transform the component and component roots keys into uuid.
  83. */
  84. @ServerSide
  85. public class IssueQueryFactory {
  86. private static final Logger LOGGER = LoggerFactory.getLogger(IssueQueryFactory.class);
  87. public static final String UNKNOWN = "<UNKNOWN>";
  88. public static final List<String> ISSUE_STATUSES = STATUSES.stream()
  89. .filter(s -> !s.equals(STATUS_TO_REVIEW))
  90. .filter(s -> !s.equals(STATUS_REVIEWED))
  91. .collect(ImmutableList.toImmutableList());
  92. public static final Set<String> ISSUE_TYPE_NAMES = Arrays.stream(RuleType.values())
  93. .filter(t -> t != RuleType.SECURITY_HOTSPOT)
  94. .map(Enum::name)
  95. .collect(Collectors.toSet());
  96. private static final ComponentDto UNKNOWN_COMPONENT = new ComponentDto().setUuid(UNKNOWN).setBranchUuid(UNKNOWN);
  97. private static final Set<String> QUALIFIERS_WITHOUT_LEAK_PERIOD = new HashSet<>(Arrays.asList(Qualifiers.APP, Qualifiers.VIEW, Qualifiers.SUBVIEW));
  98. private final DbClient dbClient;
  99. private final Clock clock;
  100. private final UserSession userSession;
  101. public IssueQueryFactory(DbClient dbClient, Clock clock, UserSession userSession) {
  102. this.dbClient = dbClient;
  103. this.clock = clock;
  104. this.userSession = userSession;
  105. }
  106. public IssueQuery create(SearchRequest request) {
  107. try (DbSession dbSession = dbClient.openSession(false)) {
  108. final ZoneId timeZone = parseTimeZone(request.getTimeZone()).orElse(clock.getZone());
  109. Collection<RuleDto> ruleDtos = ruleKeysToRuleId(dbSession, request.getRules());
  110. Collection<String> ruleUuids = ruleDtos.stream().map(RuleDto::getUuid).collect(Collectors.toSet());
  111. if (request.getRules() != null && request.getRules().stream().collect(Collectors.toSet()).size() != ruleDtos.size()) {
  112. ruleUuids.add("non-existing-uuid");
  113. }
  114. IssueQuery.Builder builder = IssueQuery.builder()
  115. .issueKeys(request.getIssues())
  116. .severities(request.getSeverities())
  117. .cleanCodeAttributesCategories(request.getCleanCodeAttributesCategories())
  118. .impactSoftwareQualities(request.getImpactSoftwareQualities())
  119. .impactSeverities(request.getImpactSeverities())
  120. .statuses(request.getStatuses())
  121. .resolutions(request.getResolutions())
  122. .issueStatuses(request.getIssueStatuses())
  123. .resolved(request.getResolved())
  124. .rules(ruleDtos)
  125. .ruleUuids(ruleUuids)
  126. .assigneeUuids(request.getAssigneeUuids())
  127. .authors(request.getAuthors())
  128. .scopes(request.getScopes())
  129. .languages(request.getLanguages())
  130. .tags(request.getTags())
  131. .types(request.getTypes())
  132. .pciDss32(request.getPciDss32())
  133. .pciDss40(request.getPciDss40())
  134. .owaspAsvs40(request.getOwaspAsvs40())
  135. .owaspAsvsLevel(request.getOwaspAsvsLevel())
  136. .owaspTop10(request.getOwaspTop10())
  137. .owaspTop10For2021(request.getOwaspTop10For2021())
  138. .sansTop25(request.getSansTop25())
  139. .cwe(request.getCwe())
  140. .sonarsourceSecurity(request.getSonarsourceSecurity())
  141. .assigned(request.getAssigned())
  142. .createdAt(parseStartingDateOrDateTime(request.getCreatedAt(), timeZone))
  143. .createdBefore(parseEndingDateOrDateTime(request.getCreatedBefore(), timeZone))
  144. .facetMode(request.getFacetMode())
  145. .timeZone(timeZone)
  146. .codeVariants(request.getCodeVariants());
  147. List<ComponentDto> allComponents = new ArrayList<>();
  148. boolean effectiveOnComponentOnly = mergeDeprecatedComponentParameters(dbSession, request, allComponents);
  149. addComponentParameters(builder, dbSession, effectiveOnComponentOnly, allComponents, request);
  150. setCreatedAfterFromRequest(dbSession, builder, request, allComponents, timeZone);
  151. String sort = request.getSort();
  152. if (!isNullOrEmpty(sort)) {
  153. builder.sort(sort);
  154. builder.asc(request.getAsc());
  155. }
  156. return builder.build();
  157. }
  158. }
  159. private static Optional<ZoneId> parseTimeZone(@Nullable String timeZone) {
  160. if (timeZone == null) {
  161. return Optional.empty();
  162. }
  163. try {
  164. return Optional.of(ZoneId.of(timeZone));
  165. } catch (DateTimeException e) {
  166. LOGGER.warn("TimeZone '" + timeZone + "' cannot be parsed as a valid zone ID");
  167. return Optional.empty();
  168. }
  169. }
  170. private void setCreatedAfterFromDates(IssueQuery.Builder builder, @Nullable Date createdAfter, @Nullable String createdInLast, boolean createdAfterInclusive) {
  171. Date actualCreatedAfter = createdAfter;
  172. if (createdInLast != null) {
  173. actualCreatedAfter = Date.from(
  174. OffsetDateTime.now(clock)
  175. .minus(Period.parse("P" + createdInLast.toUpperCase(Locale.ENGLISH)))
  176. .toInstant());
  177. }
  178. builder.createdAfter(actualCreatedAfter, createdAfterInclusive);
  179. }
  180. private void setCreatedAfterFromRequest(DbSession dbSession, IssueQuery.Builder builder, SearchRequest request, List<ComponentDto> componentUuids, ZoneId timeZone) {
  181. Date createdAfter = parseStartingDateOrDateTime(request.getCreatedAfter(), timeZone);
  182. String createdInLast = request.getCreatedInLast();
  183. if (notInNewCodePeriod(request)) {
  184. checkArgument(createdAfter == null || createdInLast == null, format("Parameters %s and %s cannot be set simultaneously", PARAM_CREATED_AFTER, PARAM_CREATED_IN_LAST));
  185. setCreatedAfterFromDates(builder, createdAfter, createdInLast, true);
  186. } else {
  187. // If the filter is on leak period
  188. checkArgument(createdAfter == null, "Parameters '%s' and '%s' cannot be set simultaneously", PARAM_CREATED_AFTER, PARAM_IN_NEW_CODE_PERIOD);
  189. checkArgument(createdInLast == null,
  190. format("Parameters '%s' and '%s' cannot be set simultaneously", PARAM_CREATED_IN_LAST, PARAM_IN_NEW_CODE_PERIOD));
  191. checkArgument(componentUuids.size() == 1, "One and only one component must be provided when searching in new code period");
  192. ComponentDto component = componentUuids.iterator().next();
  193. if (!QUALIFIERS_WITHOUT_LEAK_PERIOD.contains(component.qualifier()) && request.getPullRequest() == null) {
  194. Optional<SnapshotDto> snapshot = getLastAnalysis(dbSession, component);
  195. if (!snapshot.isEmpty() && isLastAnalysisFromReAnalyzedReferenceBranch(dbSession, snapshot.get())) {
  196. builder.newCodeOnReference(true);
  197. return;
  198. }
  199. // if last analysis has no period date, then no issue should be considered new.
  200. Date createdAfterFromSnapshot = findCreatedAfterFromComponentUuid(snapshot);
  201. setCreatedAfterFromDates(builder, createdAfterFromSnapshot, null, false);
  202. }
  203. }
  204. }
  205. private static boolean notInNewCodePeriod(SearchRequest request) {
  206. Boolean inNewCodePeriod = request.getInNewCodePeriod();
  207. inNewCodePeriod = Boolean.TRUE.equals(inNewCodePeriod);
  208. return !inNewCodePeriod;
  209. }
  210. private Date findCreatedAfterFromComponentUuid(Optional<SnapshotDto> snapshot) {
  211. return snapshot.map(s -> longToDate(s.getPeriodDate())).orElseGet(() -> new Date(clock.millis()));
  212. }
  213. private static boolean isLastAnalysisUsingReferenceBranch(SnapshotDto snapshot) {
  214. return !isNullOrEmpty(snapshot.getPeriodMode()) && snapshot.getPeriodMode().equals(REFERENCE_BRANCH.name());
  215. }
  216. private boolean isLastAnalysisFromSonarQube94Onwards(DbSession dbSession, String componentUuid) {
  217. return dbClient.liveMeasureDao().selectMeasure(dbSession, componentUuid, ANALYSIS_FROM_SONARQUBE_9_4_KEY).isPresent();
  218. }
  219. private Optional<SnapshotDto> getLastAnalysis(DbSession dbSession, ComponentDto component) {
  220. return dbClient.snapshotDao().selectLastAnalysisByComponentUuid(dbSession, component.uuid());
  221. }
  222. private List<SnapshotDto> getLastAnalysis(DbSession dbSession, Set<String> projectUuids) {
  223. return dbClient.snapshotDao().selectLastAnalysesByRootComponentUuids(dbSession, projectUuids);
  224. }
  225. private boolean mergeDeprecatedComponentParameters(DbSession session, SearchRequest request, List<ComponentDto> allComponents) {
  226. Boolean onComponentOnly = request.getOnComponentOnly();
  227. Collection<String> componentKeys = request.getComponentKeys();
  228. Collection<String> componentUuids = request.getComponentUuids();
  229. String branch = request.getBranch();
  230. String pullRequest = request.getPullRequest();
  231. boolean effectiveOnComponentOnly = false;
  232. checkArgument(atMostOneNonNullElement(componentKeys, componentUuids),
  233. "At most one of the following parameters can be provided: %s and %s", PARAM_COMPONENTS, PARAM_COMPONENT_UUIDS);
  234. if (componentKeys != null) {
  235. allComponents.addAll(getComponentsFromKeys(session, componentKeys, branch, pullRequest));
  236. effectiveOnComponentOnly = BooleanUtils.isTrue(onComponentOnly);
  237. } else if (componentUuids != null) {
  238. allComponents.addAll(getComponentsFromUuids(session, componentUuids));
  239. effectiveOnComponentOnly = BooleanUtils.isTrue(onComponentOnly);
  240. }
  241. return effectiveOnComponentOnly;
  242. }
  243. private static boolean atMostOneNonNullElement(Object... objects) {
  244. return Arrays.stream(objects)
  245. .filter(Objects::nonNull)
  246. .count() <= 1;
  247. }
  248. private void addComponentParameters(IssueQuery.Builder builder, DbSession session, boolean onComponentOnly, List<ComponentDto> components,
  249. SearchRequest request) {
  250. builder.onComponentOnly(onComponentOnly);
  251. if (onComponentOnly) {
  252. builder.componentUuids(components.stream().map(ComponentDto::uuid).toList());
  253. setBranch(builder, components.get(0), request.getBranch(), request.getPullRequest(), session);
  254. return;
  255. }
  256. List<String> projectKeys = request.getProjectKeys();
  257. if (projectKeys != null) {
  258. List<ComponentDto> branchComponents = getComponentsFromKeys(session, projectKeys, request.getBranch(), request.getPullRequest());
  259. Set<String> projectUuids = retrieveProjectUuidsFromComponents(session, branchComponents);
  260. builder.projectUuids(projectUuids);
  261. setBranch(builder, branchComponents.get(0), request.getBranch(), request.getPullRequest(), session);
  262. }
  263. builder.directories(request.getDirectories());
  264. builder.files(request.getFiles());
  265. addComponentsBasedOnQualifier(builder, session, components, request);
  266. }
  267. @NotNull
  268. private Set<String> retrieveProjectUuidsFromComponents(DbSession session, List<ComponentDto> branchComponents) {
  269. Set<String> branchUuids = branchComponents.stream().map(ComponentDto::branchUuid).collect(Collectors.toSet());
  270. return dbClient.branchDao().selectByUuids(session, branchUuids).stream()
  271. .map(BranchDto::getProjectUuid)
  272. .collect(Collectors.toSet());
  273. }
  274. private void addComponentsBasedOnQualifier(IssueQuery.Builder builder, DbSession dbSession, List<ComponentDto> components, SearchRequest request) {
  275. if (components.isEmpty()) {
  276. return;
  277. }
  278. if (components.stream().map(ComponentDto::uuid).anyMatch(uuid -> uuid.equals(UNKNOWN))) {
  279. builder.componentUuids(singleton(UNKNOWN));
  280. return;
  281. }
  282. Set<String> qualifiers = components.stream().map(ComponentDto::qualifier).collect(Collectors.toSet());
  283. checkArgument(qualifiers.size() == 1, "All components must have the same qualifier, found %s", String.join(",", qualifiers));
  284. setBranch(builder, components.get(0), request.getBranch(), request.getPullRequest(), dbSession);
  285. String qualifier = qualifiers.iterator().next();
  286. switch (qualifier) {
  287. case Qualifiers.VIEW, Qualifiers.SUBVIEW:
  288. addViewsOrSubViews(builder, components);
  289. break;
  290. case Qualifiers.APP:
  291. addApplications(builder, dbSession, components, request);
  292. addProjectUuidsForApplication(builder, dbSession, request);
  293. break;
  294. case Qualifiers.PROJECT:
  295. builder.projectUuids(retrieveProjectUuidsFromComponents(dbSession, components));
  296. break;
  297. case Qualifiers.DIRECTORY:
  298. addDirectories(builder, components);
  299. break;
  300. case Qualifiers.FILE, Qualifiers.UNIT_TEST_FILE:
  301. builder.componentUuids(components.stream().map(ComponentDto::uuid).toList());
  302. break;
  303. default:
  304. throw new IllegalArgumentException("Unable to set search root context for components " + Joiner.on(',').join(components));
  305. }
  306. }
  307. private BranchDto findComponentBranch(DbSession dbSession, ComponentDto componentDto) {
  308. Optional<BranchDto> optionalBranch = dbClient.branchDao().selectByUuid(dbSession, componentDto.branchUuid());
  309. checkArgument(optionalBranch.isPresent(), "All components must belong to a branch. This error may indicate corrupted data.");
  310. return optionalBranch.get();
  311. }
  312. private void addProjectUuidsForApplication(IssueQuery.Builder builder, DbSession session, SearchRequest request) {
  313. List<String> projectKeys = request.getProjectKeys();
  314. if (projectKeys != null) {
  315. // On application, branch should only be applied on the application, not on projects
  316. List<ComponentDto> appBranchComponents = getComponentsFromKeys(session, projectKeys, null, null);
  317. Set<String> appUuids = retrieveProjectUuidsFromComponents(session, appBranchComponents);
  318. builder.projectUuids(appUuids);
  319. }
  320. }
  321. private void addViewsOrSubViews(IssueQuery.Builder builder, Collection<ComponentDto> viewOrSubViewUuids) {
  322. List<String> filteredViewUuids = viewOrSubViewUuids.stream()
  323. .filter(uuid -> (userSession.hasComponentPermission(USER, uuid) || userSession.hasComponentPermission(SCAN, uuid) || userSession.hasPermission(GlobalPermission.SCAN)))
  324. .map(ComponentDto::uuid)
  325. .collect(Collectors.toCollection(ArrayList::new));
  326. if (filteredViewUuids.isEmpty()) {
  327. filteredViewUuids.add(UNKNOWN);
  328. }
  329. builder.viewUuids(filteredViewUuids);
  330. }
  331. private void addApplications(IssueQuery.Builder builder, DbSession dbSession, List<ComponentDto> appBranchComponents, SearchRequest request) {
  332. Set<String> authorizedAppBranchUuids = appBranchComponents.stream()
  333. .filter(app -> userSession.hasComponentPermission(USER, app) && userSession.hasChildProjectsPermission(USER, app))
  334. .map(ComponentDto::uuid)
  335. .collect(Collectors.toSet());
  336. builder.viewUuids(authorizedAppBranchUuids.isEmpty() ? singleton(UNKNOWN) : authorizedAppBranchUuids);
  337. addCreatedAfterByProjects(builder, dbSession, request, authorizedAppBranchUuids);
  338. }
  339. private void addCreatedAfterByProjects(IssueQuery.Builder builder, DbSession dbSession, SearchRequest request, Set<String> appBranchUuids) {
  340. if (notInNewCodePeriod(request) || request.getPullRequest() != null) {
  341. return;
  342. }
  343. Set<String> projectBranchUuids = appBranchUuids.stream()
  344. .flatMap(app -> dbClient.componentDao().selectProjectBranchUuidsFromView(dbSession, app, app).stream())
  345. .collect(Collectors.toSet());
  346. List<SnapshotDto> snapshots = getLastAnalysis(dbSession, projectBranchUuids);
  347. Set<String> newCodeReferenceByProjects = snapshots
  348. .stream()
  349. .filter(s -> isLastAnalysisFromReAnalyzedReferenceBranch(dbSession, s))
  350. .map(SnapshotDto::getRootComponentUuid)
  351. .collect(Collectors.toSet());
  352. Map<String, PeriodStart> leakByProjects = snapshots
  353. .stream()
  354. .filter(s -> s.getPeriodDate() != null && !isLastAnalysisFromReAnalyzedReferenceBranch(dbSession, s))
  355. .collect(Collectors.toMap(SnapshotDto::getRootComponentUuid, s1 -> new PeriodStart(longToDate(s1.getPeriodDate()), false)));
  356. builder.createdAfterByProjectUuids(leakByProjects);
  357. builder.newCodeOnReferenceByProjectUuids(newCodeReferenceByProjects);
  358. }
  359. private boolean isLastAnalysisFromReAnalyzedReferenceBranch(DbSession dbSession, SnapshotDto snapshot) {
  360. return isLastAnalysisUsingReferenceBranch(snapshot) &&
  361. isLastAnalysisFromSonarQube94Onwards(dbSession, snapshot.getRootComponentUuid());
  362. }
  363. private static void addDirectories(IssueQuery.Builder builder, List<ComponentDto> directories) {
  364. Set<String> paths = directories.stream().map(ComponentDto::path).collect(Collectors.toSet());
  365. builder.directories(paths);
  366. }
  367. private List<ComponentDto> getComponentsFromKeys(DbSession dbSession, Collection<String> componentKeys, @Nullable String branch, @Nullable String pullRequest) {
  368. List<ComponentDto> componentDtos = dbClient.componentDao().selectByKeys(dbSession, componentKeys, branch, pullRequest);
  369. if (!componentKeys.isEmpty() && componentDtos.isEmpty()) {
  370. return singletonList(UNKNOWN_COMPONENT);
  371. }
  372. return componentDtos;
  373. }
  374. private List<ComponentDto> getComponentsFromUuids(DbSession dbSession, Collection<String> componentUuids) {
  375. List<ComponentDto> componentDtos = dbClient.componentDao().selectByUuids(dbSession, componentUuids);
  376. if (!componentUuids.isEmpty() && componentDtos.isEmpty()) {
  377. return singletonList(UNKNOWN_COMPONENT);
  378. }
  379. return componentDtos;
  380. }
  381. private Collection<RuleDto> ruleKeysToRuleId(DbSession dbSession, @Nullable Collection<String> rules) {
  382. if (rules != null) {
  383. return dbClient.ruleDao().selectByKeys(dbSession, transform(rules, RuleKey::parse));
  384. }
  385. return Collections.emptyList();
  386. }
  387. private void setBranch(IssueQuery.Builder builder, ComponentDto component, @Nullable String branch, @Nullable String pullRequest,
  388. DbSession session) {
  389. builder.branchUuid(branch == null && pullRequest == null ? null : component.branchUuid());
  390. if (UNKNOWN_COMPONENT.equals(component) || (pullRequest == null && branch == null)) {
  391. builder.mainBranch(true);
  392. } else {
  393. BranchDto branchDto = findComponentBranch(session, component);
  394. builder.mainBranch(branchDto.isMain());
  395. }
  396. }
  397. }