mirror of
https://github.com/jdalrymple/gitbeaker.git
synced 2026-01-18 15:55:30 +00:00
* Fix incorrect Feature Flags endpoint * Refactor endpoint generation, using tagged template to encode parameters * Add basic unit test for the endpoint function
87 lines
2.0 KiB
TypeScript
87 lines
2.0 KiB
TypeScript
import { BaseResource } from '@gitbeaker/requester-utils';
|
|
import {
|
|
BaseRequestOptions,
|
|
endpoint,
|
|
PaginatedRequestOptions,
|
|
RequestHelper,
|
|
Sudo,
|
|
} from '../infrastructure';
|
|
|
|
export interface FeatureFlagStrategyScope {
|
|
id: number;
|
|
environment_scope: string;
|
|
}
|
|
export interface FeatureFlagStrategy {
|
|
id: number;
|
|
name: string;
|
|
parameters: {
|
|
user_ids: string;
|
|
};
|
|
scopes?: FeatureFlagStrategyScope[];
|
|
}
|
|
|
|
export interface FeatureFlagSchema extends Record<string, unknown> {
|
|
name: string;
|
|
description: string;
|
|
active: boolean;
|
|
version: string;
|
|
created_at: string;
|
|
updated_at: string;
|
|
scopes?: string[];
|
|
strategies?: FeatureFlagStrategy[];
|
|
}
|
|
|
|
export class FeatureFlags<C extends boolean = false> extends BaseResource<C> {
|
|
all(
|
|
projectId: string | number,
|
|
options: { scopes?: 'enabled' | 'disabled' } & PaginatedRequestOptions = {},
|
|
) {
|
|
return RequestHelper.get<FeatureFlagSchema[]>()(
|
|
this,
|
|
endpoint`projects/${projectId}/feature_flags`,
|
|
options,
|
|
);
|
|
}
|
|
|
|
create(
|
|
projectId: string | number,
|
|
flagName: string,
|
|
version: string,
|
|
options?: BaseRequestOptions,
|
|
) {
|
|
return RequestHelper.post<FeatureFlagSchema>()(
|
|
this,
|
|
endpoint`projects/${projectId}/feature_flags`,
|
|
{
|
|
name: flagName,
|
|
version,
|
|
...options,
|
|
},
|
|
);
|
|
}
|
|
|
|
edit(projectId: string | number, flagName: string, options?: BaseRequestOptions) {
|
|
return RequestHelper.put<FeatureFlagSchema>()(
|
|
this,
|
|
endpoint`projects/${projectId}/feature_flags/${flagName}`,
|
|
options,
|
|
);
|
|
}
|
|
|
|
remove(projectId: string | number, flagName: string, options?: Sudo) {
|
|
return RequestHelper.del()(
|
|
this,
|
|
endpoint`projects/${projectId}/feature_flags/${flagName}`,
|
|
options,
|
|
);
|
|
}
|
|
|
|
show(projectId: string | number, flagName: string, options?: Sudo) {
|
|
return RequestHelper.get<FeatureFlagSchema>()(
|
|
this,
|
|
endpoint`projects/${projectId}/feature_flags/${flagName}`,
|
|
options,
|
|
);
|
|
}
|
|
}
|