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.

webhooks.ts 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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, postJSON } from '../helpers/request';
  22. export function createWebhook(data: {
  23. name: string;
  24. project?: string;
  25. secret?: string;
  26. url: string;
  27. }): Promise<{ webhook: T.Webhook }> {
  28. return postJSON('/api/webhooks/create', data).catch(throwGlobalError);
  29. }
  30. export function deleteWebhook(data: { webhook: string }): Promise<void | Response> {
  31. return post('/api/webhooks/delete', data).catch(throwGlobalError);
  32. }
  33. export function searchWebhooks(data: { project?: string }): Promise<{ webhooks: T.Webhook[] }> {
  34. return getJSON('/api/webhooks/list', data).catch(throwGlobalError);
  35. }
  36. export function updateWebhook(data: {
  37. webhook: string;
  38. name: string;
  39. secret?: string;
  40. url: string;
  41. }): Promise<void | Response> {
  42. return post('/api/webhooks/update', data).catch(throwGlobalError);
  43. }
  44. export function searchDeliveries(data: {
  45. ceTaskId?: string;
  46. componentKey?: string;
  47. webhook?: string;
  48. p?: number;
  49. ps?: number;
  50. }): Promise<{
  51. deliveries: T.WebhookDelivery[];
  52. paging: T.Paging;
  53. }> {
  54. return getJSON('/api/webhooks/deliveries', data).catch(throwGlobalError);
  55. }
  56. export function getDelivery(data: {
  57. deliveryId: string;
  58. }): Promise<{ delivery: T.WebhookDelivery & { payload: string } }> {
  59. return getJSON('/api/webhooks/delivery', data).catch(throwGlobalError);
  60. }