Skip to content

Commit da46ba6

Browse files
authored
Merge pull request #18 from Abhay-soni-developer/feature/external-url
url can be passed from app-config.yaml
2 parents b1a2773 + f5b4726 commit da46ba6

File tree

4 files changed

+17101
-12326
lines changed

4 files changed

+17101
-12326
lines changed

package.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,21 @@
7878
"backstage",
7979
"statusneo",
8080
"github"
81-
]
81+
],
82+
"configSchema": {
83+
"$schema": "https://backstage.io/schema/config-v1",
84+
"title": "@statusneo/backstage-plugin-github",
85+
"type": "object",
86+
"properties": {
87+
"gh-plugin": {
88+
"type": "object",
89+
"properties": {
90+
"url": {
91+
"type": "string",
92+
"visibility": "frontend"
93+
}
94+
}
95+
}
96+
}
97+
}
8298
}

src/api/GithubClient.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { GithubApi } from './GithubApi';
2-
import { OAuthApi, FetchApi } from '@backstage/core-plugin-api';
2+
import { OAuthApi, FetchApi, ConfigApi } from '@backstage/core-plugin-api';
33
import { ResponseError } from '@backstage/errors';
44
import {
55
SearchApiFetchRequest,
@@ -17,20 +17,30 @@ import {
1717
export class GithubClient implements GithubApi {
1818
private readonly authApi: OAuthApi;
1919
private readonly fetchApi: FetchApi;
20+
private readonly configApi: ConfigApi;
2021

21-
constructor(options: { authApi: OAuthApi; fetchApi: FetchApi }) {
22+
constructor(options: {
23+
authApi: OAuthApi;
24+
fetchApi: FetchApi;
25+
configApi: ConfigApi;
26+
}) {
2227
this.authApi = options.authApi;
2328
this.fetchApi = options.fetchApi;
29+
this.configApi = options.configApi;
2430
}
2531

2632
private async get<T>(
2733
path: string,
2834
params: { [key in string]: any } = {},
2935
): Promise<T> {
3036
const query = new URLSearchParams(params);
37+
38+
const baseUrl: string =
39+
this.configApi.get('gh-plugin.url') || 'https://api.github.com/';
40+
3141
const url = new URL(
3242
`${path}?${query.toString().replaceAll('%2B', '+')}`,
33-
'https://api.github.com/',
43+
baseUrl,
3444
);
3545

3646
const token = await this.authApi.getAccessToken();
@@ -82,11 +92,9 @@ export class GithubClient implements GithubApi {
8292
);
8393
}
8494

85-
public getAuthenticatedUserReposByType (params: UserRepositoryApiRequest): Promise<UserRepositoryApiResponse> {
86-
return this.get<UserRepositoryApiResponse>(
87-
`/user/repos`,
88-
params,
89-
);
95+
public getAuthenticatedUserReposByType(
96+
params: UserRepositoryApiRequest,
97+
): Promise<UserRepositoryApiResponse> {
98+
return this.get<UserRepositoryApiResponse>(`/user/repos`, params);
9099
}
91-
92100
}

src/plugin.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ import {
44
fetchApiRef,
55
createApiFactory,
66
createComponentExtension,
7+
configApiRef
78
} from '@backstage/core-plugin-api';
89
import { githubApiRef, GithubClient } from './api';
910

1011
export const backstageGithubPlugin = createPlugin({
11-
id: 'backstage-plugin-github',
12+
id: 'backstage-statusneo-plugin-github',
1213
apis: [
1314
createApiFactory({
1415
api: githubApiRef,
15-
deps: { authApi: githubAuthApiRef, fetchApi: fetchApiRef },
16+
deps: { authApi: githubAuthApiRef, fetchApi: fetchApiRef, configApi: configApiRef },
1617
factory(deps) {
1718
return new GithubClient(deps);
1819
},

0 commit comments

Comments
 (0)