mirror of
https://github.com/jdalrymple/gitbeaker.git
synced 2026-01-18 15:55:30 +00:00
Add support for the JobTokenScopes API (#3571)
This commit is contained in:
parent
2f6335a227
commit
32ed802eb7
@ -86,6 +86,7 @@ import { IssueStateEvents } from './IssueStateEvents';
|
||||
import { IssueWeightEvents } from './IssueWeightEvents';
|
||||
import { JobArtifacts } from './JobArtifacts';
|
||||
import { Jobs } from './Jobs';
|
||||
import { JobTokenScopes } from './JobTokenScopes';
|
||||
import { MergeRequestApprovals } from './MergeRequestApprovals';
|
||||
import { MergeRequestAwardEmojis } from './MergeRequestAwardEmojis';
|
||||
import { MergeRequestContextCommits } from './MergeRequestContextCommits';
|
||||
@ -278,6 +279,7 @@ export interface Gitlab<C extends boolean = false> extends BaseResource<C> {
|
||||
IssueWeightEvents: IssueWeightEvents<C>;
|
||||
JobArtifacts: JobArtifacts<C>;
|
||||
Jobs: Jobs<C>;
|
||||
JobTokenScopes: JobTokenScopes<C>;
|
||||
MergeRequestApprovals: MergeRequestApprovals<C>;
|
||||
MergeRequestAwardEmojis: MergeRequestAwardEmojis<C>;
|
||||
MergeRequestContextCommits: MergeRequestContextCommits<C>;
|
||||
@ -468,6 +470,7 @@ const resources = {
|
||||
IssueWeightEvents,
|
||||
JobArtifacts,
|
||||
Jobs,
|
||||
JobTokenScopes,
|
||||
MergeRequestApprovals,
|
||||
MergeRequestAwardEmojis,
|
||||
MergeRequestContextCommits,
|
||||
|
||||
74
packages/core/src/resources/JobTokenScopes.ts
Normal file
74
packages/core/src/resources/JobTokenScopes.ts
Normal file
@ -0,0 +1,74 @@
|
||||
import { BaseResource } from '@gitbeaker/requester-utils';
|
||||
import { RequestHelper, endpoint } from '../infrastructure';
|
||||
import type { GitlabAPIResponse, ShowExpanded, Sudo } from '../infrastructure';
|
||||
import { SimpleProjectSchema } from './Projects';
|
||||
|
||||
export interface JobTokenScopeSchema extends Record<string, unknown> {
|
||||
inbound_enabled: boolean;
|
||||
outbound_enabled: boolean;
|
||||
}
|
||||
|
||||
export interface AllowListSchema extends Record<string, unknown> {
|
||||
source_project_id: number;
|
||||
target_project_id: number;
|
||||
}
|
||||
|
||||
export class JobTokenScopes<C extends boolean = false> extends BaseResource<C> {
|
||||
show<E extends boolean = false>(
|
||||
projectId: string | number,
|
||||
options?: Sudo & ShowExpanded<E>,
|
||||
): Promise<GitlabAPIResponse<JobTokenScopeSchema, C, E, void>> {
|
||||
return RequestHelper.get<JobTokenScopeSchema>()(
|
||||
this,
|
||||
endpoint`projects/${projectId}/job_token_scope`,
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
edit<E extends boolean = false>(
|
||||
projectId: string | number,
|
||||
enabled: boolean,
|
||||
options?: Sudo & ShowExpanded<E>,
|
||||
): Promise<GitlabAPIResponse<JobTokenScopeSchema, C, E, void>> {
|
||||
return RequestHelper.patch<JobTokenScopeSchema>()(
|
||||
this,
|
||||
endpoint`projects/${projectId}/job_token_scope`,
|
||||
{ ...options, enabled },
|
||||
);
|
||||
}
|
||||
|
||||
showInboundAllowList<E extends boolean = false>(
|
||||
projectId: string | number,
|
||||
options?: Sudo & ShowExpanded<E>,
|
||||
): Promise<GitlabAPIResponse<SimpleProjectSchema[], C, E, void>> {
|
||||
return RequestHelper.get<SimpleProjectSchema[]>()(
|
||||
this,
|
||||
endpoint`projects/${projectId}/job_token_scope/allowlist`,
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
addToInboundAllowList<E extends boolean = false>(
|
||||
projectId: string | number,
|
||||
targetProjectId: string | number,
|
||||
options?: Sudo & ShowExpanded<E>,
|
||||
): Promise<GitlabAPIResponse<AllowListSchema, C, E, void>> {
|
||||
return RequestHelper.post<AllowListSchema>()(
|
||||
this,
|
||||
endpoint`projects/${projectId}/job_token_scope/allowlist/${targetProjectId}`,
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
removeFromInboundAllowList<E extends boolean = false>(
|
||||
projectId: string | number,
|
||||
targetProjectId: string | number,
|
||||
options?: Sudo & ShowExpanded<E>,
|
||||
): Promise<GitlabAPIResponse<void, C, E, void>> {
|
||||
return RequestHelper.del()(
|
||||
this,
|
||||
endpoint`projects/${projectId}/job_token_scope/allowlist/${targetProjectId}`,
|
||||
options,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -85,6 +85,7 @@ export * from './Issues';
|
||||
export * from './IssuesStatistics';
|
||||
export * from './JobArtifacts';
|
||||
export * from './Jobs';
|
||||
export * from './JobTokenScopes';
|
||||
export * from './MergeRequestApprovals';
|
||||
export * from './MergeRequestAwardEmojis';
|
||||
export * from './MergeRequestContextCommits';
|
||||
|
||||
@ -81,6 +81,7 @@ describe('API Map', () => {
|
||||
'IssueWeightEvents',
|
||||
'JobArtifacts',
|
||||
'Jobs',
|
||||
'JobTokenScopes',
|
||||
'MergeRequestApprovals',
|
||||
'MergeRequestAwardEmojis',
|
||||
'MergeRequestContextCommits',
|
||||
|
||||
74
packages/core/test/unit/resources/JobTokenScopes.ts
Normal file
74
packages/core/test/unit/resources/JobTokenScopes.ts
Normal file
@ -0,0 +1,74 @@
|
||||
import { JobTokenScopes } from '../../../src';
|
||||
import { RequestHelper } from '../../../src/infrastructure';
|
||||
|
||||
jest.mock(
|
||||
'../../../src/infrastructure/RequestHelper',
|
||||
() => require('../../__mocks__/RequestHelper').default,
|
||||
);
|
||||
|
||||
let service: JobTokenScopes;
|
||||
|
||||
beforeEach(() => {
|
||||
service = new JobTokenScopes({
|
||||
requesterFn: jest.fn(),
|
||||
token: 'abcdefg',
|
||||
});
|
||||
});
|
||||
|
||||
describe('JobTokenScopes.show', () => {
|
||||
it('should request GET /projects/:id/job_token_scope', async () => {
|
||||
await service.show(1);
|
||||
|
||||
expect(RequestHelper.get()).toHaveBeenCalledWith(
|
||||
service,
|
||||
'projects/1/job_token_scope',
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('JobTokenScopes.edit', () => {
|
||||
it('should request PATCH /projects/:id/job_token_scope', async () => {
|
||||
await service.edit(1, false);
|
||||
|
||||
expect(RequestHelper.get()).toHaveBeenCalledWith(service, 'projects/1/job_token_scope', {
|
||||
enabled: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('JobTokenScopes.showInboundAllowList', () => {
|
||||
it('should request GET /projects/:id/job_token_scope/allowlist', async () => {
|
||||
await service.showInboundAllowList(1);
|
||||
|
||||
expect(RequestHelper.get()).toHaveBeenCalledWith(
|
||||
service,
|
||||
'projects/1/job_token_scope/allowlist',
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('JobTokenScopes.addToInboundAllowList', () => {
|
||||
it('should request POST /projects/:id/job_token_scope/allowlist/:targetId', async () => {
|
||||
await service.addToInboundAllowList(1, 2);
|
||||
|
||||
expect(RequestHelper.post()).toHaveBeenCalledWith(
|
||||
service,
|
||||
'projects/1/job_token_scope/allowlist/2',
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('JobTokenScopes.removeFromInboundAllowList', () => {
|
||||
it('should request DEL /projects/:id/job_token_scope/allowlist/:targetId', async () => {
|
||||
await service.removeFromInboundAllowList(1, 2);
|
||||
|
||||
expect(RequestHelper.del()).toHaveBeenCalledWith(
|
||||
service,
|
||||
'projects/1/job_token_scope/allowlist/2',
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
});
|
||||
@ -96,6 +96,7 @@ export const {
|
||||
IssueWeightEvents,
|
||||
JobArtifacts,
|
||||
Jobs,
|
||||
JobTokenScopes,
|
||||
MergeRequestApprovals,
|
||||
MergeRequestAwardEmojis,
|
||||
MergeRequestContextCommits,
|
||||
|
||||
@ -89,6 +89,7 @@ describe('Browser Import', () => {
|
||||
'IssueWeightEvents',
|
||||
'JobArtifacts',
|
||||
'Jobs',
|
||||
'JobTokenScopes',
|
||||
'MergeRequestApprovals',
|
||||
'MergeRequestAwardEmojis',
|
||||
'MergeRequestContextCommits',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user