Implement readTree for GitlabReader (#3547)
* This change adds an implementation for the readTree method in GitlabReader. The implementation is similar to the readTree method in GithubReader with the exception of the 'path' variable used for subpaths in the archive. To facilitate this, GitlabIntegrationConfig now has an apiUrl field which was missing for Gitlab but was present for Bitbucket & GH. * As part of this change, there are also new tests added to GitlabReader to mirror what has been done with the GH reader. For now the archive format chosen is 'zip', follow-up action includes having a look at whether tar.gz is preferable. Signed-off-by: Matei David <madavid@expediagroup.com>
This commit is contained in:
@@ -18,6 +18,7 @@ import { Config } from '@backstage/config';
|
||||
import { isValidHost } from '../helpers';
|
||||
|
||||
const GITLAB_HOST = 'gitlab.com';
|
||||
const GITLAB_API_BASE_URL = 'gitlab.com/api/v4';
|
||||
|
||||
/**
|
||||
* The configuration parameters for a single GitLab integration.
|
||||
@@ -28,6 +29,17 @@ export type GitLabIntegrationConfig = {
|
||||
*/
|
||||
host: string;
|
||||
|
||||
/**
|
||||
* The base URL of the API of this provider, e.g. "https://gitlab.com/api/v4",
|
||||
* with no trailing slash.
|
||||
*
|
||||
* May be omitted specifically for GitLab; then it will be deduced.
|
||||
*
|
||||
* The API will always be preferred if both its base URL and a token are
|
||||
* present.
|
||||
*/
|
||||
apiBaseUrl?: string;
|
||||
|
||||
/**
|
||||
* The authorization token to use for requests this provider.
|
||||
*
|
||||
@@ -45,6 +57,7 @@ export function readGitLabIntegrationConfig(
|
||||
config: Config,
|
||||
): GitLabIntegrationConfig {
|
||||
const host = config.getOptionalString('host') ?? GITLAB_HOST;
|
||||
let apiBaseUrl = config.getOptionalString('apiBaseUrl');
|
||||
const token = config.getOptionalString('token');
|
||||
|
||||
if (!isValidHost(host)) {
|
||||
@@ -53,7 +66,12 @@ export function readGitLabIntegrationConfig(
|
||||
);
|
||||
}
|
||||
|
||||
return { host, token };
|
||||
if (apiBaseUrl) {
|
||||
apiBaseUrl = apiBaseUrl.replace(/\/+$/, '');
|
||||
} else if (host === GITLAB_HOST) {
|
||||
apiBaseUrl = GITLAB_API_BASE_URL;
|
||||
}
|
||||
return { host, token, apiBaseUrl };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user