Skip to content
Snippets Groups Projects
Commit 9d2917d5 authored by michael.minelli's avatar michael.minelli
Browse files

ExerciceRoutes => Add the ci/cd file on exercice creation

parent febe78eb
No related branches found
No related tags found
No related merge requests found
###################################################################################################################
# DO NOT MODIFY THIS FILE
# This file is the ci/cd pipeline that will be used to test your exercice
###################################################################################################################
variables:
GIT_SUBMODULE_STRATEGY: recursive
GIT_SUBMODULE_FORCE_HTTPS: "true"
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR:
DOCKER_DRIVER: overlay2
stages:
- dojo
dojo:
stage: dojo
tags:
- dojo_exercice
services:
- docker:dind
image:
name: dojohesso/dojo_exercice_checker:latest
script:
- dojo_exercice_checker
artifacts:
when: always
paths:
- $DOJO_RESULTS_FOLDER/*
allow_failure: false
\ No newline at end of file
......@@ -186,6 +186,17 @@ class GitlabManager {
return response.data;
}
async createFile(repoId: number, filePath: string, fileBase64: string, commitMessage: string, branch: string = 'main', authorName: string = 'Dojo', authorMail: string | undefined = undefined) {
await axios.post(this.getApiUrl(GitlabRoutes.REPOSITORY_FILE).replace('{{id}}', String(repoId)).replace('{{filePath}}', encodeURIComponent(filePath)), {
encoding : 'base64',
branch : branch,
commit_message: commitMessage,
content : fileBase64,
author_name : authorName,
author_email : authorMail
});
}
}
......
......@@ -120,6 +120,18 @@ class ExerciceRoutes implements RoutesManager {
return res.status(StatusCodes.INSUFFICIENT_SPACE_ON_RESOURCE).send();
}
try {
await GitlabManager.createFile(repository.id, '.gitlab-ci.yml', fs.readFileSync(path.join(__dirname, '../../assets/exercice_gitlab_ci.yml'), 'base64'), 'Add .gitlab-ci.yml (DO NOT MODIFY THIS FILE)');
} catch ( error ) {
logger.error(error);
if ( error instanceof AxiosError ) {
return res.status(error.response?.status ?? HttpStatusCode.InternalServerError).send();
}
return res.status(StatusCodes.INTERNAL_SERVER_ERROR).send();
}
try {
await Promise.all([ ...new Set([ ...enonce.staff.map(user => user.gitlabId), ...params.members.map(member => member.id) ]) ].map(async (memberId: number): Promise<GitlabMember | false> => {
try {
......@@ -158,11 +170,12 @@ class ExerciceRoutes implements RoutesManager {
return req.session.sendResponse(res, StatusCodes.OK, exercice);
} catch ( error ) {
logger.error(error);
if ( error instanceof AxiosError ) {
return res.status(error.response?.status ?? HttpStatusCode.InternalServerError).send();
}
logger.error(error);
return res.status(StatusCodes.INTERNAL_SERVER_ERROR).send();
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment