Welcome to mirror list, hosted at ThFree Co, Russian Federation.

api.js « subscriptions « jira_connect « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c79d7002111dde523ef194b5796c88695841d791 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import axios from 'axios';
import { buildApiUrl } from '~/api/api_utils';

import { GITLAB_COM_BASE_PATH } from '~/jira_connect/subscriptions/constants';
import { getJwt } from './utils';

const CURRENT_USER_PATH = '/api/:version/user';
const JIRA_CONNECT_SUBSCRIPTIONS_PATH = '/api/:version/integrations/jira_connect/subscriptions';
const JIRA_CONNECT_INSTALLATIONS_PATH = '/-/jira_connect/installations';
const JIRA_CONNECT_OAUTH_APPLICATION_ID_PATH = '/-/jira_connect/oauth_application_id';

// This export is only used for testing purposes
export const axiosInstance = axios.create();

export const setApiBaseURL = (baseURL = null) => {
  axiosInstance.defaults.baseURL = baseURL;
};

export const addSubscription = async (addPath, namespace) => {
  const jwt = await getJwt();

  return axiosInstance.post(addPath, {
    jwt,
    namespace_path: namespace,
  });
};

export const removeSubscription = async (removePath) => {
  const jwt = await getJwt();

  return axiosInstance.delete(removePath, {
    params: {
      jwt,
    },
  });
};

export const fetchGroups = async (groupsPath, { page, perPage, search }) => {
  return axiosInstance.get(groupsPath, {
    params: {
      page,
      per_page: perPage,
      search,
    },
  });
};

export const fetchSubscriptions = async (subscriptionsPath) => {
  const jwt = await getJwt();

  return axiosInstance.get(subscriptionsPath, {
    params: {
      jwt,
    },
  });
};

export const getCurrentUser = (options) => {
  const url = buildApiUrl(CURRENT_USER_PATH);
  return axiosInstance.get(url, { ...options });
};

export const addJiraConnectSubscription = (namespacePath, { jwt, accessToken }) => {
  const url = buildApiUrl(JIRA_CONNECT_SUBSCRIPTIONS_PATH);

  return axiosInstance.post(
    url,
    {
      jwt,
      namespace_path: namespacePath,
    },
    {
      headers: {
        Authorization: `Bearer ${accessToken}`,
      },
    },
  );
};

export const updateInstallation = async (instanceUrl) => {
  const jwt = await getJwt();

  return axiosInstance.put(JIRA_CONNECT_INSTALLATIONS_PATH, {
    jwt,
    installation: {
      instance_url: instanceUrl === GITLAB_COM_BASE_PATH ? null : instanceUrl,
    },
  });
};

export const fetchOAuthApplicationId = () => {
  return axiosInstance.get(JIRA_CONNECT_OAUTH_APPLICATION_ID_PATH);
};

export const fetchOAuthToken = (oauthTokenPath, data = {}) => {
  return axiosInstance.post(oauthTokenPath, data);
};