Skip to content

Commit

Permalink
Adding support for GroupJobTokenScopes and moved JobTokenScopes t…
Browse files Browse the repository at this point in the history
…o `ProjectJobTokenScopes`(#3643)
  • Loading branch information
jdalrymple authored Oct 19, 2024
1 parent dc4c9d7 commit 8525268
Show file tree
Hide file tree
Showing 13 changed files with 188 additions and 100 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
yarn dlx --no-install lint-staged
yarn test
9 changes: 6 additions & 3 deletions packages/core/src/resources/Gitlab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ 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';
Expand Down Expand Up @@ -117,6 +116,7 @@ import { ProjectImportExports } from './ProjectImportExports';
import { ProjectInvitations } from './ProjectInvitations';
import { ProjectIssueBoards } from './ProjectIssueBoards';
import { ProjectIterations } from './ProjectIterations';
import { ProjectJobTokenScopes } from './ProjectJobTokenScopes';
import { ProjectLabels } from './ProjectLabels';
import { ProjectMembers } from './ProjectMembers';
import { ProjectMilestones } from './ProjectMilestones';
Expand Down Expand Up @@ -166,6 +166,7 @@ import { GroupImportExports } from './GroupImportExports';
import { GroupInvitations } from './GroupInvitations';
import { GroupIssueBoards } from './GroupIssueBoards';
import { GroupIterations } from './GroupIterations';
import { GroupJobTokenScopes } from './GroupJobTokenScopes';
import { GroupLabels } from './GroupLabels';
import { GroupLDAPLinks } from './GroupLDAPLinks';
import { GroupMembers } from './GroupMembers';
Expand Down Expand Up @@ -279,7 +280,6 @@ 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>;
Expand Down Expand Up @@ -310,6 +310,7 @@ export interface Gitlab<C extends boolean = false> extends BaseResource<C> {
ProjectInvitations: ProjectInvitations<C>;
ProjectIssueBoards: ProjectIssueBoards<C>;
ProjectIterations: ProjectIterations<C>;
ProjectJobTokenScopes: ProjectJobTokenScopes<C>;
ProjectLabels: ProjectLabels<C>;
ProjectMembers: ProjectMembers<C>;
ProjectMilestones: ProjectMilestones<C>;
Expand Down Expand Up @@ -359,6 +360,7 @@ export interface Gitlab<C extends boolean = false> extends BaseResource<C> {
GroupInvitations: GroupInvitations<C>;
GroupIssueBoards: GroupIssueBoards<C>;
GroupIterations: GroupIterations<C>;
GroupJobTokenScopes: GroupJobTokenScopes<C>;
GroupLabels: GroupLabels<C>;
GroupLDAPLinks: GroupLDAPLinks<C>;
GroupMembers: GroupMembers<C>;
Expand Down Expand Up @@ -470,7 +472,6 @@ const resources = {
IssueWeightEvents,
JobArtifacts,
Jobs,
JobTokenScopes,
MergeRequestApprovals,
MergeRequestAwardEmojis,
MergeRequestContextCommits,
Expand Down Expand Up @@ -501,6 +502,7 @@ const resources = {
ProjectInvitations,
ProjectIssueBoards,
ProjectIterations,
ProjectJobTokenScopes,
ProjectLabels,
ProjectMembers,
ProjectMilestones,
Expand Down Expand Up @@ -550,6 +552,7 @@ const resources = {
GroupInvitations,
GroupIssueBoards,
GroupIterations,
GroupJobTokenScopes,
GroupLabels,
GroupLDAPLinks,
GroupMembers,
Expand Down
25 changes: 25 additions & 0 deletions packages/core/src/resources/GroupJobTokenScopes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { BaseResourceOptions } from '@gitbeaker/requester-utils';
import type { GitlabAPIResponse, ShowExpanded, Sudo } from '../infrastructure';
import type { AllowListSchema } from '../templates/ResourceJobTokenScopes';
import { ResourceJobTokenScopes } from '../templates/ResourceJobTokenScopes';

export interface GroupJobTokenScopes<C extends boolean = false> extends ResourceJobTokenScopes<C> {
addToInboundAllowList<E extends boolean = false>(
groupId: string | number,
targetGroupId: string | number,
options?: Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<AllowListSchema, C, E, void>>;

removeFromInboundAllowList<E extends boolean = false>(
groupId: string | number,
targetGroupId: string | number,
options?: Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<void, C, E, void>>;
}

export class GroupJobTokenScopes<C extends boolean = false> extends ResourceJobTokenScopes<C> {
constructor(options: BaseResourceOptions<C>) {
/* istanbul ignore next */
super('groups', options);
}
}
43 changes: 43 additions & 0 deletions packages/core/src/resources/ProjectJobTokenScopes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import type { BaseResourceOptions } from '@gitbeaker/requester-utils';
import type { GitlabAPIResponse, ShowExpanded, Sudo } from '../infrastructure';
import type { SimpleProjectSchema } from './Projects';
import type { AllowListSchema, JobTokenScopeSchema } from '../templates/ResourceJobTokenScopes';
import { ResourceJobTokenScopes } from '../templates/ResourceJobTokenScopes';

export interface ProjectJobTokenScopes<C extends boolean = false>
extends ResourceJobTokenScopes<C> {
edit<E extends boolean = false>(
projectId: string | number,
enabled: boolean,
options?: Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<JobTokenScopeSchema, C, E, void>>;

show<E extends boolean = false>(
projectId: string | number,
options?: Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<JobTokenScopeSchema, C, E, void>>;

showInboundAllowList<E extends boolean = false>(
projectId: string | number,
options?: Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<SimpleProjectSchema[], C, E, void>>;

addToInboundAllowList<E extends boolean = false>(
projectId: string | number,
targetProjectId: string | number,
options?: Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<AllowListSchema, C, E, void>>;

removeFromInboundAllowList<E extends boolean = false>(
projectId: string | number,
targetProjectId: string | number,
options?: Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<void, C, E, void>>;
}

export class ProjectJobTokenScopes<C extends boolean = false> extends ResourceJobTokenScopes<C> {
constructor(options: BaseResourceOptions<C>) {
/* istanbul ignore next */
super('projects', options);
}
}
3 changes: 2 additions & 1 deletion packages/core/src/resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export * from './Issues';
export * from './IssuesStatistics';
export * from './JobArtifacts';
export * from './Jobs';
export * from './JobTokenScopes';
export * from './MergeRequestApprovals';
export * from './MergeRequestAwardEmojis';
export * from './MergeRequestContextCommits';
Expand Down Expand Up @@ -116,6 +115,7 @@ export * from './ProjectImportExports';
export * from './ProjectInvitations';
export * from './ProjectIssueBoards';
export * from './ProjectIterations';
export * from './ProjectJobTokenScopes';
export * from './ProjectLabels';
export * from './ProjectMembers';
export * from './ProjectMilestones';
Expand Down Expand Up @@ -167,6 +167,7 @@ export * from './GroupImportExports';
export * from './GroupInvitations';
export * from './GroupIssueBoards';
export * from './GroupIterations';
export * from './GroupJobTokenScopes';
export * from './GroupLDAPLinks';
export * from './GroupLabels';
export * from './GroupMemberRoles';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { BaseResource } from '@gitbeaker/requester-utils';
import { BaseResource, BaseResourceOptions } 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;
Expand All @@ -13,61 +12,65 @@ export interface AllowListSchema extends Record<string, unknown> {
target_project_id: number;
}

export class JobTokenScopes<C extends boolean = false> extends BaseResource<C> {
export class ResourceJobTokenScopes<C extends boolean = false> extends BaseResource<C> {
constructor(resourceType: string, options: BaseResourceOptions<C>) {
super({ prefixUrl: resourceType, ...options });
}

show<E extends boolean = false>(
projectId: string | number,
resourceId: string | number,
options?: Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<JobTokenScopeSchema, C, E, void>> {
return RequestHelper.get<JobTokenScopeSchema>()(
this,
endpoint`projects/${projectId}/job_token_scope`,
endpoint`${resourceId}/job_token_scope`,
options,
);
}

edit<E extends boolean = false>(
projectId: string | number,
resourceId: 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`,
endpoint`${resourceId}/job_token_scope`,
{ ...options, enabled },
);
}

showInboundAllowList<E extends boolean = false>(
projectId: string | number,
resourceId: string | number,
options?: Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<SimpleProjectSchema[], C, E, void>> {
return RequestHelper.get<SimpleProjectSchema[]>()(
): Promise<GitlabAPIResponse<Record<string, unknown>[], C, E, void>> {
return RequestHelper.get<Record<string, unknown>[]>()(
this,
endpoint`projects/${projectId}/job_token_scope/allowlist`,
endpoint`${resourceId}/job_token_scope/allowlist`,
options,
);
}

addToInboundAllowList<E extends boolean = false>(
projectId: string | number,
targetProjectId: string | number,
resourceId: string | number,
targetResourceId: 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}`,
endpoint`${resourceId}/job_token_scope/allowlist/${targetResourceId}`,
options,
);
}

removeFromInboundAllowList<E extends boolean = false>(
projectId: string | number,
targetProjectId: string | number,
resourceId: string | number,
targetResourceId: string | number,
options?: Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<void, C, E, void>> {
return RequestHelper.del()(
this,
endpoint`projects/${projectId}/job_token_scope/allowlist/${targetProjectId}`,
endpoint`${resourceId}/job_token_scope/allowlist/${targetResourceId}`,
options,
);
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/templates/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ export * from './ResourceLabelEvents';
export * from './ResourceMilestoneEvents';
export * from './ResourceStateEvents';
export * from './ResourceWeightEvents';
export * from './ResourceJobTokenScopes';
3 changes: 2 additions & 1 deletion packages/core/test/integration/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ describe('API Map', () => {
'IssueWeightEvents',
'JobArtifacts',
'Jobs',
'JobTokenScopes',
'MergeRequestApprovals',
'MergeRequestAwardEmojis',
'MergeRequestContextCommits',
Expand Down Expand Up @@ -112,6 +111,7 @@ describe('API Map', () => {
'ProjectInvitations',
'ProjectIssueBoards',
'ProjectIterations',
'ProjectJobTokenScopes',
'ProjectLabels',
'ProjectMembers',
'ProjectMilestones',
Expand Down Expand Up @@ -160,6 +160,7 @@ describe('API Map', () => {
'GroupInvitations',
'GroupIssueBoards',
'GroupIterations',
'GroupJobTokenScopes',
'GroupLabels',
'GroupLDAPLinks',
'GroupMembers',
Expand Down
74 changes: 0 additions & 74 deletions packages/core/test/unit/resources/JobTokenScopes.ts

This file was deleted.

Loading

0 comments on commit 8525268

Please sign in to comment.