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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/jira_connect/subscriptions/api.js')
-rw-r--r--app/assets/javascripts/jira_connect/subscriptions/api.js64
1 files changed, 60 insertions, 4 deletions
diff --git a/app/assets/javascripts/jira_connect/subscriptions/api.js b/app/assets/javascripts/jira_connect/subscriptions/api.js
index de67703356f..c79d7002111 100644
--- a/app/assets/javascripts/jira_connect/subscriptions/api.js
+++ b/app/assets/javascripts/jira_connect/subscriptions/api.js
@@ -1,10 +1,25 @@
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 axios.post(addPath, {
+ return axiosInstance.post(addPath, {
jwt,
namespace_path: namespace,
});
@@ -13,7 +28,7 @@ export const addSubscription = async (addPath, namespace) => {
export const removeSubscription = async (removePath) => {
const jwt = await getJwt();
- return axios.delete(removePath, {
+ return axiosInstance.delete(removePath, {
params: {
jwt,
},
@@ -21,7 +36,7 @@ export const removeSubscription = async (removePath) => {
};
export const fetchGroups = async (groupsPath, { page, perPage, search }) => {
- return axios.get(groupsPath, {
+ return axiosInstance.get(groupsPath, {
params: {
page,
per_page: perPage,
@@ -33,9 +48,50 @@ export const fetchGroups = async (groupsPath, { page, perPage, search }) => {
export const fetchSubscriptions = async (subscriptionsPath) => {
const jwt = await getJwt();
- return axios.get(subscriptionsPath, {
+ 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);
+};