mirror of
https://github.com/jdalrymple/gitbeaker.git
synced 2026-01-18 15:55:30 +00:00
Add support for Freeze Periods (#1231)
See https://gitlab.com/gitlab-org/gitlab/-/blob/master/doc/api/freeze_periods.md
This commit is contained in:
parent
e56009ba4d
commit
13d43b77b4
@ -241,6 +241,7 @@ ContainerRegistry
|
||||
Deployments
|
||||
DeployKeys
|
||||
Environments
|
||||
FreezePeriods
|
||||
Issues
|
||||
IssuesStatistics
|
||||
IssueNotes
|
||||
@ -324,6 +325,7 @@ ContainerRegistry
|
||||
Deployments
|
||||
DeployKeys
|
||||
Environments
|
||||
FreezePeriods
|
||||
Issues
|
||||
IssuesStatistics
|
||||
IssueNotes
|
||||
|
||||
@ -38,6 +38,7 @@ export const {
|
||||
Deployments,
|
||||
DeployKeys,
|
||||
Environments,
|
||||
FreezePeriods,
|
||||
Issues,
|
||||
IssuesStatistics,
|
||||
IssueNotes,
|
||||
|
||||
@ -45,6 +45,7 @@ export const ProjectsBundle = bundler({
|
||||
DeployKeys: APIServices.DeployKeys,
|
||||
Deployments: APIServices.Deployments,
|
||||
Environments: APIServices.Environments,
|
||||
FreezePeriods: APIServices.FreezePeriods,
|
||||
Issues: APIServices.Issues,
|
||||
IssuesStatistics: APIServices.IssuesStatistics,
|
||||
IssueAwardEmojis: APIServices.IssueAwardEmojis,
|
||||
|
||||
57
packages/gitbeaker-core/src/services/FreezePeriods.ts
Normal file
57
packages/gitbeaker-core/src/services/FreezePeriods.ts
Normal file
@ -0,0 +1,57 @@
|
||||
import { BaseService } from '@gitbeaker/requester-utils';
|
||||
import { BaseRequestOptions, RequestHelper } from '../infrastructure';
|
||||
|
||||
export interface CreateFreezePeriodOptions {
|
||||
cronTimezone?: string;
|
||||
}
|
||||
|
||||
export interface EditFreezePeriodOptions {
|
||||
cronTimezone?: string;
|
||||
freezeStart?: string;
|
||||
freezeEnd?: string;
|
||||
}
|
||||
|
||||
export class FreezePeriods extends BaseService {
|
||||
all(projectId: string | number, options?: BaseRequestOptions) {
|
||||
const pId = encodeURIComponent(projectId);
|
||||
|
||||
return RequestHelper.get(this, `projects/${pId}/freeze_periods`, options);
|
||||
}
|
||||
|
||||
show(projectId: string | number, freezePeriodId: number, options?: BaseRequestOptions) {
|
||||
const [pId, fId] = [projectId, freezePeriodId].map(encodeURIComponent);
|
||||
|
||||
return RequestHelper.get(this, `projects/${pId}/freeze_periods/${fId}`, options);
|
||||
}
|
||||
|
||||
create(
|
||||
projectId: number | string,
|
||||
freezeStart: string,
|
||||
freezeEnd: string,
|
||||
options?: CreateFreezePeriodOptions & BaseRequestOptions,
|
||||
) {
|
||||
const pId = encodeURIComponent(projectId);
|
||||
|
||||
return RequestHelper.post(this, `projects/${pId}/freeze_periods`, {
|
||||
freezeStart,
|
||||
freezeEnd,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
|
||||
edit(
|
||||
projectId: number | string,
|
||||
freezePeriodId: number,
|
||||
options?: EditFreezePeriodOptions & BaseRequestOptions,
|
||||
) {
|
||||
const [pId, fId] = [projectId, freezePeriodId].map(encodeURIComponent);
|
||||
|
||||
return RequestHelper.put(this, `projects/${pId}/freeze_periods/${fId}`, options);
|
||||
}
|
||||
|
||||
delete(projectId: number | string, freezePeriodId: number, options?: BaseRequestOptions) {
|
||||
const [pId, fId] = [projectId, freezePeriodId].map(encodeURIComponent);
|
||||
|
||||
return RequestHelper.del(this, `projects/${pId}/freeze_periods/${fId}`, options);
|
||||
}
|
||||
}
|
||||
@ -32,6 +32,7 @@ export { ContainerRegistry } from './ContainerRegistry';
|
||||
export { Deployments } from './Deployments';
|
||||
export { DeployKeys } from './DeployKeys';
|
||||
export { Environments } from './Environments';
|
||||
export { FreezePeriods } from './FreezePeriods';
|
||||
export { Issues } from './Issues';
|
||||
export { IssuesStatistics } from './IssuesStatistics';
|
||||
export { IssueNotes } from './IssueNotes';
|
||||
|
||||
86
packages/gitbeaker-core/test/unit/services/FreezePeriods.ts
Normal file
86
packages/gitbeaker-core/test/unit/services/FreezePeriods.ts
Normal file
@ -0,0 +1,86 @@
|
||||
import { RequesterType } from '@gitbeaker/requester-utils';
|
||||
import { RequestHelper } from '../../../src/infrastructure';
|
||||
import { FreezePeriods } from '../../../src';
|
||||
|
||||
jest.mock('../../../src/infrastructure/RequestHelper');
|
||||
|
||||
let service: FreezePeriods;
|
||||
|
||||
beforeEach(() => {
|
||||
const requester = {
|
||||
get: jest.fn(() => Promise.resolve([])),
|
||||
post: jest.fn(() => Promise.resolve({})),
|
||||
put: jest.fn(() => Promise.resolve({})),
|
||||
delete: jest.fn(() => Promise.resolve({})),
|
||||
} as RequesterType;
|
||||
|
||||
service = new FreezePeriods({
|
||||
requester,
|
||||
token: 'abcdefg',
|
||||
requestTimeout: 3000,
|
||||
});
|
||||
});
|
||||
|
||||
describe('Instantiating FreezePeriods service', () => {
|
||||
it('should create a valid service object', async () => {
|
||||
expect(service).toBeInstanceOf(FreezePeriods);
|
||||
expect(service.url).toBeDefined();
|
||||
expect(service.rejectUnauthorized).toBeTruthy();
|
||||
expect(service.headers).toMatchObject({ 'private-token': 'abcdefg' });
|
||||
expect(service.requestTimeout).toBe(3000);
|
||||
});
|
||||
});
|
||||
|
||||
describe('FreezePeriods.all', () => {
|
||||
it('should request GET /projects/:id/freeze_periods', async () => {
|
||||
await service.all(1);
|
||||
|
||||
expect(RequestHelper.get).toHaveBeenCalledWith(service, 'projects/1/freeze_periods', undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe('FreezePeriods.show', () => {
|
||||
it('should request GET /projects/:id/freeze_periods/:freeze_period_id', async () => {
|
||||
await service.show(1, 2);
|
||||
|
||||
expect(RequestHelper.get).toHaveBeenCalledWith(
|
||||
service,
|
||||
'projects/1/freeze_periods/2',
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('FreezePeriods.create', () => {
|
||||
it('should request POST projects/:id/freeze_periods', async () => {
|
||||
await service.create(1, '* * * * *', '* * * * *', { cronTimezone: 'UTC' });
|
||||
|
||||
expect(RequestHelper.post).toHaveBeenCalledWith(service, 'projects/1/freeze_periods', {
|
||||
freezeStart: '* * * * *',
|
||||
freezeEnd: '* * * * *',
|
||||
cronTimezone: 'UTC',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('FreezePeriods.edit', () => {
|
||||
it('should request PUT projects/:id/freeze_periods/:freeze_period_id', async () => {
|
||||
await service.edit(1, 2, { freezeStart: '* * * * *' });
|
||||
|
||||
expect(RequestHelper.put).toHaveBeenCalledWith(service, 'projects/1/freeze_periods/2', {
|
||||
freezeStart: '* * * * *',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('FreezePeriods.delete', () => {
|
||||
it('should request DELETE projects/:id/freeze_periods/:freeze_period_id', async () => {
|
||||
await service.delete(1, 2);
|
||||
|
||||
expect(RequestHelper.del).toHaveBeenCalledWith(
|
||||
service,
|
||||
'projects/1/freeze_periods/2',
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
});
|
||||
@ -38,6 +38,7 @@ export const {
|
||||
Deployments,
|
||||
DeployKeys,
|
||||
Environments,
|
||||
FreezePeriods,
|
||||
Issues,
|
||||
IssuesStatistics,
|
||||
IssueNotes,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user