Invalid body
'); + + await processGitlabEvent(webtriggerRequest, MOCK_CONTEXT); + + expect(mockHandlePushEvent).not.toHaveBeenCalled(); + expect(serverResponse).toHaveBeenCalledWith('Invalid event format', 400); + }); + + it('handles pipeline event when FF is enabled', async () => { + const webtriggerRequest = generateWebtriggerRequest(JSON.stringify(MOCK_PIPELINE_EVENT)); + + await processGitlabEvent(webtriggerRequest, MOCK_CONTEXT); + + expect(mockHandlePipelineEvent).toHaveBeenCalledWith(MOCK_PIPELINE_EVENT, TEST_TOKEN, MOCK_CLOUD_ID); + expect(serverResponse).toHaveBeenCalledWith('Processed webhook event'); + }); + + it('handles merge request event', async () => { + const webtriggerRequest = generateWebtriggerRequest(JSON.stringify(MOCK_MERGE_REQUEST_EVENT)); + + await processGitlabEvent(webtriggerRequest, MOCK_CONTEXT); + + expect(mockHandleMergeRequestEvent).toHaveBeenCalledWith(MOCK_MERGE_REQUEST_EVENT, TEST_TOKEN, MOCK_CLOUD_ID); + expect(serverResponse).toHaveBeenCalledWith('Processed webhook event'); + }); + + it('handles deployment event when FF is enabled', async () => { + const webtriggerRequest = generateWebtriggerRequest(JSON.stringify(MOCK_DEPLOYMENT_EVENT)); + + await processGitlabEvent(webtriggerRequest, MOCK_CONTEXT); + + expect(mockDeploymentEvent).toHaveBeenCalledWith(MOCK_DEPLOYMENT_EVENT, TEST_TOKEN, MOCK_CLOUD_ID); + expect(serverResponse).toHaveBeenCalledWith('Processed webhook event'); + }); +}); diff --git a/src/entry/webtriggers/process-gitlab-event.ts b/src/entry/webtriggers/process-gitlab-event.ts new file mode 100644 index 0000000..a6b3985 --- /dev/null +++ b/src/entry/webtriggers/process-gitlab-event.ts @@ -0,0 +1,77 @@ +import { storage } from '@forge/api'; + +import { + DeploymentEvent, + GitlabEvent, + MergeRequestEvent, + PipelineEvent, + PushEvent, + WebtriggerRequest, + WebtriggerResponse, +} from '../../types'; +import { serverResponse } from '../../utils/webtrigger-utils'; +import { parse } from '../../utils/parse-ari'; +import { STORAGE_KEYS, STORAGE_SECRETS } from '../../constants'; +import { + handlePushEvent, + handleMergeRequestEvent, + handleDeploymentEvent, + handlePipelineEvent, +} from './gitlab-event-handlers'; +import { listFeatures } from '../../services/feature-flags'; + +type Context = { + principal: undefined; + installContext: string; +}; + +class ValidateWebhookSignatureError extends Error {} + +const validateWebhookSignature = (eventSignature: string, controlSignature: string): void | never => { + if (eventSignature !== controlSignature) { + throw new ValidateWebhookSignatureError(); + } +}; + +export const processGitlabEvent = async (event: WebtriggerRequest, context: Context): Promise+ {ErrorMessages[AuthErrorTypes.INVALID_GROUP_TOKEN].description[0]} + {ErrorMessages[AuthErrorTypes.INVALID_GROUP_TOKEN].description[1]} + {ErrorMessages[AuthErrorTypes.INVALID_GROUP_TOKEN].description[2]} +
+{ErrorMessages[AuthErrorTypes.INVALID_GROUP_TOKEN_NAME].description}
++ {ErrorMessages[AuthErrorTypes.INCORRECT_GROUP_TOKEN_SCOPES].description[0]} + {ErrorMessages[AuthErrorTypes.INCORRECT_GROUP_TOKEN_SCOPES].description[1]} + {ErrorMessages[AuthErrorTypes.INCORRECT_GROUP_TOKEN_SCOPES].description[2]} + {ErrorMessages[AuthErrorTypes.INCORRECT_GROUP_TOKEN_SCOPES].description[3]} + {ErrorMessages[AuthErrorTypes.INCORRECT_GROUP_TOKEN_SCOPES].description[4]} +
+{ErrorMessages[AuthErrorTypes.UNEXPECTED_ERROR].description}
++ Create and retrieve your group access token from your GitLab account to connect to Compass. When creating + your group access token, make sure you: +
+
+
+ Import projects from {groupName} as components to track in Compass. +
+ + {isImportInProgress ? ( +{lastSyncTimeErrorMessage}
+Please, try to reload a page.
+Unfortunately, we can't show a current progress status. Please, refresh a page or try again later.
+Something went wrong! Try to reload a page.
+Status
+
+ Manage components with configuration files in the connected GitLab workspace and sync any updates back to
+ Compass.{' '}
+
+ You can choose to let Compass set up the configuration files for all your components during the import. Or, + you can import your components first, and then set up the configuration files manually later. +
++ When you start the import, Compass adds the compass.yml configuration file to each project and raises + merge requests. Approve and merge the merge requests for the projects to sync with Compass. +
+{projectsImportingData.errors[0].message}
+{projectsImportingData.errors[0].message}
+