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.

security-hotspots.ts 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 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. import throwGlobalError from '../app/utils/throwGlobalError';
  21. import { getJSON, post } from '../helpers/request';
  22. import { BranchParameters } from '../types/branch-like';
  23. import {
  24. Hotspot,
  25. HotspotAssignRequest,
  26. HotspotComment,
  27. HotspotResolution,
  28. HotspotSearchResponse,
  29. HotspotSetStatusRequest,
  30. HotspotStatus
  31. } from '../types/security-hotspots';
  32. const HOTSPOTS_SEARCH_URL = '/api/hotspots/search';
  33. export function assignSecurityHotspot(
  34. hotspotKey: string,
  35. data: HotspotAssignRequest
  36. ): Promise<void> {
  37. return post('/api/hotspots/assign', { hotspot: hotspotKey, ...data }).catch(throwGlobalError);
  38. }
  39. export function setSecurityHotspotStatus(
  40. hotspotKey: string,
  41. data: HotspotSetStatusRequest
  42. ): Promise<void> {
  43. return post('/api/hotspots/change_status', { hotspot: hotspotKey, ...data }).catch(
  44. throwGlobalError
  45. );
  46. }
  47. export function commentSecurityHotspot(hotspotKey: string, comment: string): Promise<void> {
  48. return post('/api/hotspots/add_comment', { hotspot: hotspotKey, comment }).catch(
  49. throwGlobalError
  50. );
  51. }
  52. export function deleteSecurityHotspotComment(commentKey: string): Promise<void> {
  53. return post('/api/hotspots/delete_comment', { comment: commentKey }).catch(throwGlobalError);
  54. }
  55. export function editSecurityHotspotComment(
  56. commentKey: string,
  57. comment: string
  58. ): Promise<HotspotComment> {
  59. return post('/api/hotspots/edit_comment', { comment: commentKey, text: comment }).catch(
  60. throwGlobalError
  61. );
  62. }
  63. export function getSecurityHotspots(
  64. data: {
  65. projectKey: string;
  66. p: number;
  67. ps: number;
  68. status?: HotspotStatus;
  69. resolution?: HotspotResolution;
  70. onlyMine?: boolean;
  71. sinceLeakPeriod?: boolean;
  72. } & BranchParameters
  73. ): Promise<HotspotSearchResponse> {
  74. return getJSON(HOTSPOTS_SEARCH_URL, data).catch(throwGlobalError);
  75. }
  76. export function getSecurityHotspotList(
  77. hotspotKeys: string[],
  78. data: {
  79. projectKey: string;
  80. } & BranchParameters
  81. ): Promise<HotspotSearchResponse> {
  82. return getJSON(HOTSPOTS_SEARCH_URL, { ...data, hotspots: hotspotKeys.join() }).catch(
  83. throwGlobalError
  84. );
  85. }
  86. export function getSecurityHotspotDetails(securityHotspotKey: string): Promise<Hotspot> {
  87. return getJSON('/api/hotspots/show', { hotspot: securityHotspotKey })
  88. .then((response: Hotspot & { users: T.UserBase[] }) => {
  89. const { users, ...hotspot } = response;
  90. if (users) {
  91. if (hotspot.assignee) {
  92. hotspot.assigneeUser = users.find(u => u.login === hotspot.assignee) || {
  93. active: true,
  94. login: hotspot.assignee
  95. };
  96. }
  97. hotspot.authorUser = users.find(u => u.login === hotspot.author) || {
  98. active: true,
  99. login: hotspot.author
  100. };
  101. hotspot.comment.forEach(c => {
  102. c.user = users.find(u => u.login === c.login) || { active: true, login: c.login };
  103. });
  104. }
  105. return hotspot;
  106. })
  107. .catch(throwGlobalError);
  108. }