-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathservicesHelper.tsx
55 lines (45 loc) · 1.46 KB
/
servicesHelper.tsx
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
import { CommonServiceIds, IProjectPageService, IProjectInfo, ILocationService } from 'azure-devops-extension-api';
import { CoreRestClient } from 'azure-devops-extension-api/Core';
import React from 'react';
import { SDKContext } from '../dal/azureDevOpsContextProvider';
/**
* Get the project info
*/
const getProjectInfo = async (): Promise<IProjectInfo> => {
const { SDK } = React.useContext(SDKContext);
const projectPageService = await SDK.getService<IProjectPageService>(CommonServiceIds.ProjectPageService);
return projectPageService.getProject();
}
/**
* Get the project id
*/
export const getProjectId = async (): Promise<string> => {
const projectInfo = await getProjectInfo();
return projectInfo.id;
}
/**
* Get the project name
*/
export const getProjectName = async (): Promise<string> => {
const projectInfo = await getProjectInfo();
return projectInfo.name;
}
/**
* Get the host base URL
*/
export const getHostBaseUrl = async (): Promise<string> => {
const { SDK } = React.useContext(SDKContext);
const locationService = await SDK.getService<ILocationService>(CommonServiceIds.LocationService);
const hostBaseUrl = await locationService.getResourceAreaLocation(
CoreRestClient.RESOURCE_AREA_ID
);
return hostBaseUrl;
}
/**
* Get the host authority
*/
export const getHostAuthority = async (): Promise<string> => {
const hostBaseUrl = await getHostBaseUrl();
const { hostname } = new URL(hostBaseUrl);
return hostname;
}