MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / getValidGitLabToken

Function getValidGitLabToken

apps/web/src/lib/integrations/gitlab-service.ts:89–148  ·  view source on GitHub ↗
(integration: PlatformIntegration)

Source from the content-addressed store, hash-verified

87): string | undefined {
88 const value = metadata[key];
89 if (value === undefined) return undefined;
90 if (typeof value !== 'string') throw new Error(`GitLab metadata ${key} must be a string`);
91 return value;
92}
93
94function requireMetadataRecord(metadata: unknown): Readonly<Record<string, unknown>> {
95 if (metadata === null) return {};
96 if (typeof metadata !== 'object' || Array.isArray(metadata)) {
97 throw new TRPCError({ code: 'UNAUTHORIZED', message: 'Invalid GitLab integration metadata' });
98 }
99 return { ...metadata };
100}
101
102function copyMetadataObject(
103 metadata: Readonly<Record<string, unknown>>,
104 key: string
105): Record<string, unknown> {
106 const value = metadata[key];
107 if (value === undefined) return {};
108 if (typeof value !== 'object' || value === null || Array.isArray(value)) {
109 throw new Error(`GitLab metadata ${key} must be an object`);
110 }
111 return { ...value };
112}
113
114function countMetadataObjectEntries(value: unknown): number {
115 return typeof value === 'object' && value !== null && !Array.isArray(value)
116 ? Object.keys(value).length
117 : 0;
118}
119
120function getGitLabIntegrationOwner(integration: PlatformIntegration): Owner {
121 if (integration.owned_by_user_id && !integration.owned_by_organization_id) {
122 return { type: 'user', id: integration.owned_by_user_id };
123 }
124 if (integration.owned_by_organization_id && !integration.owned_by_user_id) {
125 return { type: 'org', id: integration.owned_by_organization_id };
126 }
127 throw new Error('GitLab integration must have exactly one owner');
128}
129
130function requireGitLabProjectId(projectId: string | number): string {
131 const value = String(projectId);
132 if (!/^[1-9][0-9]*$/.test(value)) {
133 throw new Error('GitLab project ID must be a positive decimal');
134 }
135 return value;
136}
137
138/**
139 * Get GitLab integration for an owner
140 */
141export async function getGitLabIntegration(owner: Owner): Promise<PlatformIntegration | null> {
142 const ownershipCondition =
143 owner.type === 'user'
144 ? eq(platform_integrations.owned_by_user_id, owner.id)
145 : eq(platform_integrations.owned_by_organization_id, owner.id);
146

Calls 6

isTokenExpiredFunction · 0.90
refreshGitLabOAuthTokenFunction · 0.90
calculateTokenExpiryFunction · 0.90
normalizeInstanceUrlFunction · 0.85
setMethod · 0.65
updateMethod · 0.65

Tested by

no test coverage detected