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.

IssuesService.java 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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.sonarqube.ws.client.issues;
  21. import java.io.InputStream;
  22. import java.util.stream.Collectors;
  23. import javax.annotation.Generated;
  24. import org.sonarqube.ws.Issues.AddCommentResponse;
  25. import org.sonarqube.ws.Issues.AssignResponse;
  26. import org.sonarqube.ws.Issues.AuthorsResponse;
  27. import org.sonarqube.ws.Issues.BulkChangeWsResponse;
  28. import org.sonarqube.ws.Issues.ChangelogWsResponse;
  29. import org.sonarqube.ws.Issues.DeleteCommentResponse;
  30. import org.sonarqube.ws.Issues.DoTransitionResponse;
  31. import org.sonarqube.ws.Issues.SearchWsResponse;
  32. import org.sonarqube.ws.Issues.SetSeverityResponse;
  33. import org.sonarqube.ws.Issues.SetTagsResponse;
  34. import org.sonarqube.ws.Issues.SetTypeResponse;
  35. import org.sonarqube.ws.Issues.TagsResponse;
  36. import org.sonarqube.ws.MediaTypes;
  37. import org.sonarqube.ws.client.BaseService;
  38. import org.sonarqube.ws.client.GetRequest;
  39. import org.sonarqube.ws.client.PostRequest;
  40. import org.sonarqube.ws.client.WsConnector;
  41. /**
  42. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/issues">Further information about this web service online</a>
  43. */
  44. @Generated("sonar-ws-generator")
  45. public class IssuesService extends BaseService {
  46. public IssuesService(WsConnector wsConnector) {
  47. super(wsConnector, "api/issues");
  48. }
  49. /**
  50. *
  51. * This is part of the internal API.
  52. * This is a POST request.
  53. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/issues/add_comment">Further information about this action online (including a response example)</a>
  54. * @since 3.6
  55. */
  56. public AddCommentResponse addComment(AddCommentRequest request) {
  57. return call(
  58. new PostRequest(path("add_comment"))
  59. .setParam("issue", request.getIssue())
  60. .setParam("text", request.getText()),
  61. AddCommentResponse.parser());
  62. }
  63. /**
  64. *
  65. * This is part of the internal API.
  66. * This is a POST request.
  67. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/issues/assign">Further information about this action online (including a response example)</a>
  68. * @since 3.6
  69. */
  70. public AssignResponse assign(AssignRequest request) {
  71. return call(
  72. new PostRequest(path("assign"))
  73. .setParam("assignee", request.getAssignee())
  74. .setParam("issue", request.getIssue()),
  75. AssignResponse.parser());
  76. }
  77. /**
  78. *
  79. * This is part of the internal API.
  80. * This is a GET request.
  81. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/issues/authors">Further information about this action online (including a response example)</a>
  82. * @since 5.1
  83. */
  84. public AuthorsResponse authors(AuthorsRequest request) {
  85. return call(
  86. new GetRequest(path("authors"))
  87. .setParam("project", request.getProject())
  88. .setParam("ps", request.getPs())
  89. .setParam("q", request.getQ()),
  90. AuthorsResponse.parser());
  91. }
  92. /**
  93. *
  94. * This is part of the internal API.
  95. * This is a POST request.
  96. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/issues/bulk_change">Further information about this action online (including a response example)</a>
  97. * @since 3.7
  98. */
  99. public BulkChangeWsResponse bulkChange(BulkChangeRequest request) {
  100. return call(
  101. new PostRequest(path("bulk_change"))
  102. .setParam("add_tags", request.getAddTags())
  103. .setParam("assign", request.getAssign() == null ? null : request.getAssign().stream().collect(Collectors.joining(",")))
  104. .setParam("comment", request.getComment() == null ? null : request.getComment().stream().collect(Collectors.joining(",")))
  105. .setParam("do_transition", request.getDoTransition())
  106. .setParam("issues", request.getIssues() == null ? null : request.getIssues().stream().collect(Collectors.joining(",")))
  107. .setParam("remove_tags", request.getRemoveTags())
  108. .setParam("sendNotifications", request.getSendNotifications())
  109. .setParam("set_severity", request.getSetSeverity() == null ? null : request.getSetSeverity().stream().collect(Collectors.joining(",")))
  110. .setParam("set_type", request.getSetType() == null ? null : request.getSetType().stream().collect(Collectors.joining(","))),
  111. BulkChangeWsResponse.parser());
  112. }
  113. /**
  114. *
  115. * This is part of the internal API.
  116. * This is a GET request.
  117. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/issues/changelog">Further information about this action online (including a response example)</a>
  118. * @since 4.1
  119. */
  120. public ChangelogWsResponse changelog(ChangelogRequest request) {
  121. return call(
  122. new GetRequest(path("changelog"))
  123. .setParam("issue", request.getIssue()),
  124. ChangelogWsResponse.parser());
  125. }
  126. /**
  127. *
  128. * This is part of the internal API.
  129. * This is a GET request.
  130. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/issues/component_tags">Further information about this action online (including a response example)</a>
  131. * @since 5.1
  132. */
  133. public String componentTags(ComponentTagsRequest request) {
  134. return call(
  135. new GetRequest(path("component_tags"))
  136. .setParam("componentUuid", request.getComponentUuid())
  137. .setParam("createdAfter", request.getCreatedAfter())
  138. .setParam("ps", request.getPs())
  139. .setMediaType(MediaTypes.JSON)).content();
  140. }
  141. /**
  142. *
  143. * This is part of the internal API.
  144. * This is a POST request.
  145. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/issues/delete_comment">Further information about this action online (including a response example)</a>
  146. * @since 3.6
  147. */
  148. public DeleteCommentResponse deleteComment(DeleteCommentRequest request) {
  149. return call(
  150. new PostRequest(path("delete_comment"))
  151. .setParam("comment", request.getComment()),
  152. DeleteCommentResponse.parser());
  153. }
  154. /**
  155. *
  156. * This is part of the internal API.
  157. * This is a POST request.
  158. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/issues/do_transition">Further information about this action online (including a response example)</a>
  159. * @since 3.6
  160. */
  161. public DoTransitionResponse doTransition(DoTransitionRequest request) {
  162. return call(
  163. new PostRequest(path("do_transition"))
  164. .setParam("issue", request.getIssue())
  165. .setParam("transition", request.getTransition()),
  166. DoTransitionResponse.parser());
  167. }
  168. /**
  169. *
  170. * This is part of the internal API.
  171. * This is a POST request.
  172. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/issues/edit_comment">Further information about this action online (including a response example)</a>
  173. * @since 3.6
  174. */
  175. public String editComment(EditCommentRequest request) {
  176. return call(
  177. new PostRequest(path("edit_comment"))
  178. .setParam("comment", request.getComment())
  179. .setParam("text", request.getText())
  180. .setMediaType(MediaTypes.JSON)).content();
  181. }
  182. /**
  183. *
  184. * This is part of the internal API.
  185. * This is a POST request.
  186. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/issues/reindex">Further information about this action online (including a response example)</a>
  187. * @since 9.8
  188. */
  189. public void reindex() {
  190. call(
  191. new PostRequest(path("reindex"))
  192. .setMediaType(MediaTypes.JSON)).content();
  193. }
  194. /**
  195. *
  196. * This is part of the internal API.
  197. * This is a GET request.
  198. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/issues/search">Further information about this action online (including a response example)</a>
  199. * @since 3.6
  200. */
  201. public SearchWsResponse search(SearchRequest request) {
  202. return call(
  203. new GetRequest(path("search"))
  204. .setParam("additionalFields", request.getAdditionalFields() == null ? null : request.getAdditionalFields().stream().collect(Collectors.joining(",")))
  205. .setParam("asc", request.getAsc())
  206. .setParam("assigned", request.getAssigned())
  207. .setParam("assignees", request.getAssignees() == null ? null : request.getAssignees().stream().collect(Collectors.joining(",")))
  208. .setParam("author", request.getAuthor())
  209. .setParam("branch", request.getBranch())
  210. .setParam("components", request.getComponentKeys() == null ? null : request.getComponentKeys().stream().collect(Collectors.joining(",")))
  211. .setParam("createdAfter", request.getCreatedAfter())
  212. .setParam("createdAt", request.getCreatedAt())
  213. .setParam("createdBefore", request.getCreatedBefore())
  214. .setParam("createdInLast", request.getCreatedInLast())
  215. .setParam("cwe", request.getCwe() == null ? null : request.getCwe().stream().collect(Collectors.joining(",")))
  216. .setParam("directories", request.getDirectories() == null ? null : request.getDirectories().stream().collect(Collectors.joining(",")))
  217. .setParam("facets", request.getFacets() == null ? null : request.getFacets().stream().collect(Collectors.joining(",")))
  218. .setParam("fileUuids", request.getFileUuids() == null ? null : request.getFileUuids().stream().collect(Collectors.joining(",")))
  219. .setParam("issues", request.getIssues() == null ? null : request.getIssues().stream().collect(Collectors.joining(",")))
  220. .setParam("languages", request.getLanguages() == null ? null : request.getLanguages().stream().collect(Collectors.joining(",")))
  221. .setParam("onComponentOnly", request.getOnComponentOnly())
  222. .setParam("owaspTop10", request.getOwaspTop10() == null ? null : request.getOwaspTop10().stream().collect(Collectors.joining(",")))
  223. .setParam("p", request.getP())
  224. .setParam("projects", request.getProjects() == null ? null : request.getProjects().stream().collect(Collectors.joining(",")))
  225. .setParam("ps", request.getPs())
  226. .setParam("pullRequest", request.getPullRequest())
  227. .setParam("resolutions", request.getResolutions() == null ? null : request.getResolutions().stream().collect(Collectors.joining(",")))
  228. .setParam("resolved", request.getResolved())
  229. .setParam("rules", request.getRules() == null ? null : request.getRules().stream().collect(Collectors.joining(",")))
  230. .setParam("s", request.getS())
  231. .setParam("sansTop25", request.getSansTop25() == null ? null : request.getSansTop25().stream().collect(Collectors.joining(",")))
  232. .setParam("sonarsourceSecurity", request.getSonarsourceSecurity() == null ? null : request.getSonarsourceSecurity().stream().collect(Collectors.joining(",")))
  233. .setParam("severities", request.getSeverities() == null ? null : request.getSeverities().stream().collect(Collectors.joining(",")))
  234. .setParam("inNewCodePeriod", request.isInNewCodePeriod())
  235. .setParam("statuses", request.getStatuses() == null ? null : request.getStatuses().stream().collect(Collectors.joining(",")))
  236. .setParam("tags", request.getTags() == null ? null : request.getTags().stream().collect(Collectors.joining(",")))
  237. .setParam("types", request.getTypes() == null ? null : request.getTypes().stream().collect(Collectors.joining(","))),
  238. SearchWsResponse.parser());
  239. }
  240. /**
  241. *
  242. * This is part of the internal API.
  243. * This is a POST request.
  244. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/issues/set_severity">Further information about this action online (including a response example)</a>
  245. * @since 3.6
  246. */
  247. public SetSeverityResponse setSeverity(SetSeverityRequest request) {
  248. return call(
  249. new PostRequest(path("set_severity"))
  250. .setParam("issue", request.getIssue())
  251. .setParam("severity", request.getSeverity()),
  252. SetSeverityResponse.parser());
  253. }
  254. /**
  255. *
  256. * This is part of the internal API.
  257. * This is a POST request.
  258. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/issues/set_tags">Further information about this action online (including a response example)</a>
  259. * @since 5.1
  260. */
  261. public SetTagsResponse setTags(SetTagsRequest request) {
  262. return call(
  263. new PostRequest(path("set_tags"))
  264. .setParam("issue", request.getIssue())
  265. .setParam("tags", request.getTags() == null ? null : request.getTags().stream().collect(Collectors.joining(","))),
  266. SetTagsResponse.parser());
  267. }
  268. /**
  269. *
  270. * This is part of the internal API.
  271. * This is a POST request.
  272. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/issues/set_type">Further information about this action online (including a response example)</a>
  273. * @since 5.5
  274. */
  275. public SetTypeResponse setType(SetTypeRequest request) {
  276. return call(
  277. new PostRequest(path("set_type"))
  278. .setParam("issue", request.getIssue())
  279. .setParam("type", request.getType()),
  280. SetTypeResponse.parser());
  281. }
  282. /**
  283. *
  284. * This is part of the internal API.
  285. * This is a GET request.
  286. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/issues/tags">Further information about this action online (including a response example)</a>
  287. * @since 5.1
  288. */
  289. public TagsResponse tags(TagsRequest request) {
  290. return call(
  291. new GetRequest(path("tags"))
  292. .setParam("project", request.getProject())
  293. .setParam("ps", request.getPs())
  294. .setParam("q", request.getQ()),
  295. TagsResponse.parser());
  296. }
  297. /**
  298. *
  299. * This is part of the internal API.
  300. * This is a GET request.
  301. * @see <a href="https://next.sonarqube.com/sonarqube/api/issues/pull">Further information about this action online (including a response example)</a>
  302. * @since 9.5
  303. */
  304. public InputStream pull(PullRequest request) {
  305. return call(
  306. new GetRequest(path("pull"))
  307. .setParam("projectKey", request.getProjectKey())
  308. .setParam("branchName", request.getBranchName())
  309. .setParam("languages", request.getLanguages())
  310. .setParam("ruleRepositories", request.getRuleRepositories())
  311. .setParam("resolvedOnly", request.getResolvedOnly())
  312. .setParam("changedSince", request.getChangedSince())
  313. ).contentStream();
  314. }
  315. /**
  316. *
  317. * This is part of the internal API.
  318. * This is a GET request.
  319. * @see <a href="https://next.sonarqube.com/sonarqube/api/issues/pull_taint">Further information about this action online (including a response example)</a>
  320. * @since 9.5
  321. */
  322. public InputStream pullTaint(PullRequest request) {
  323. return call(
  324. new GetRequest(path("pull_taint"))
  325. .setParam("projectKey", request.getProjectKey())
  326. .setParam("branchName", request.getBranchName())
  327. .setParam("languages", request.getLanguages())
  328. .setParam("changedSince", request.getChangedSince())
  329. ).contentStream();
  330. }
  331. /**
  332. * This is part of the internal API.
  333. * This is a POST request.
  334. *
  335. * @see <a href="https://next.sonarqube.com/sonarqube/api/issues/anticipated_transitions">Further information about this action online (including a response example)</a>
  336. * @since 10.2
  337. */
  338. public int anticipatedTransitions(String projectKey, String body) {
  339. return call(
  340. new PostRequest(path("anticipated_transitions?projectKey=" + projectKey))
  341. .setBody(body)).code();
  342. }
  343. }