Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DojoBackendAPI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dojo Project (HES-SO)
Projects
Backend
DojoBackendAPI
Commits
9eb102a0
Commit
9eb102a0
authored
1 year ago
by
michael.minelli
Browse files
Options
Downloads
Patches
Plain Diff
AssignmentRoutes => Add ci on assignment creation
parent
e1a55831
No related branches found
No related tags found
No related merge requests found
Pipeline
#26622
passed
1 year ago
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
ExpressAPI/assets/assignment_gitlab_ci.yml
+26
-0
26 additions, 0 deletions
ExpressAPI/assets/assignment_gitlab_ci.yml
ExpressAPI/src/routes/AssignmentRoutes.ts
+46
-14
46 additions, 14 deletions
ExpressAPI/src/routes/AssignmentRoutes.ts
with
72 additions
and
14 deletions
ExpressAPI/assets/assignment_gitlab_ci.yml
0 → 100644
+
26
−
0
View file @
9eb102a0
###################################################################################################################
# DO NOT MODIFY THIS FILE
# This file is the ci/cd pipeline that will be used to test your assignment
###################################################################################################################
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_assignment
services
:
-
docker:dind
image
:
name
:
dojohesso/dojo_assignment_checker:latest
script
:
-
dojo_assignment_checker
allow_failure
:
false
\ No newline at end of file
This diff is collapsed.
Click to expand it.
ExpressAPI/src/routes/AssignmentRoutes.ts
+
46
−
14
View file @
9eb102a0
...
...
@@ -20,16 +20,25 @@ import db from '../helpers/DatabaseHelper';
import
{
Assignment
}
from
'
../types/DatabaseTypes
'
;
import
AssignmentManager
from
'
../managers/AssignmentManager
'
;
import
GitlabVisibility
from
'
../shared/types/Gitlab/GitlabVisibility
'
;
import
fs
from
'
fs
'
;
import
path
from
'
path
'
;
class
AssignmentRoutes
implements
RoutesManager
{
private
readonly
assignmentValidator
:
ExpressValidator
.
Schema
=
{
name
:
{
trim
:
true
,
notEmpty
:
true
},
members
:
{
trim
:
true
,
notEmpty
:
true
,
customSanitizer
:
DojoValidators
.
jsonSanitizer
},
template
:
{
trim
:
true
,
custom
:
DojoValidators
.
templateUrlValidator
,
customSanitizer
:
DojoValidators
.
templateUrlSanitizer
trim
:
true
,
notEmpty
:
true
},
members
:
{
trim
:
true
,
notEmpty
:
true
,
customSanitizer
:
DojoValidators
.
jsonSanitizer
},
template
:
{
trim
:
true
,
custom
:
DojoValidators
.
templateUrlValidator
,
customSanitizer
:
DojoValidators
.
templateUrlSanitizer
}
};
...
...
@@ -78,6 +87,8 @@ class AssignmentRoutes implements RoutesManager {
repository
=
await
GitlabManager
.
createRepository
(
params
.
name
,
Config
.
assignment
.
default
.
description
.
replace
(
'
{{ASSIGNMENT_NAME}}
'
,
params
.
name
),
Config
.
assignment
.
default
.
visibility
,
Config
.
assignment
.
default
.
initReadme
,
Config
.
gitlab
.
group
.
assignments
,
Config
.
assignment
.
default
.
sharedRunnersEnabled
,
Config
.
assignment
.
default
.
wikiEnabled
,
params
.
template
);
await
GitlabManager
.
protectBranch
(
repository
.
id
,
'
*
'
,
true
,
GitlabAccessLevel
.
DEVELOPER
,
GitlabAccessLevel
.
DEVELOPER
,
GitlabAccessLevel
.
OWNER
);
await
GitlabManager
.
addRepositoryBadge
(
repository
.
id
,
Config
.
gitlab
.
badges
.
pipeline
.
link
,
Config
.
gitlab
.
badges
.
pipeline
.
imageUrl
,
'
Pipeline Status
'
);
}
catch
(
error
)
{
if
(
error
instanceof
AxiosError
)
{
if
(
error
.
response
?.
data
.
message
.
name
&&
error
.
response
.
data
.
message
.
name
==
'
has already been taken
'
)
{
...
...
@@ -91,6 +102,18 @@ class AssignmentRoutes implements RoutesManager {
return
res
.
status
(
StatusCodes
.
INTERNAL_SERVER_ERROR
).
send
();
}
try
{
await
GitlabManager
.
createFile
(
repository
.
id
,
'
.gitlab-ci.yml
'
,
fs
.
readFileSync
(
path
.
join
(
__dirname
,
'
../../assets/assignment_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
(
params
.
members
.
map
(
member
=>
member
.
id
).
map
(
async
(
memberId
:
number
):
Promise
<
GitlabMember
|
false
>
=>
{
try
{
...
...
@@ -102,12 +125,20 @@ class AssignmentRoutes implements RoutesManager {
const
assignment
:
Assignment
=
await
db
.
assignment
.
create
({
data
:
{
name
:
repository
.
name
,
gitlabId
:
repository
.
id
,
gitlabLink
:
repository
.
web_url
,
gitlabCreationInfo
:
repository
as
unknown
as
Prisma
.
JsonObject
,
gitlabLastInfo
:
repository
as
unknown
as
Prisma
.
JsonObject
,
gitlabLastInfoDate
:
new
Date
(),
staff
:
{
name
:
repository
.
name
,
gitlabId
:
repository
.
id
,
gitlabLink
:
repository
.
web_url
,
gitlabCreationInfo
:
repository
as
unknown
as
Prisma
.
JsonObject
,
gitlabLastInfo
:
repository
as
unknown
as
Prisma
.
JsonObject
,
gitlabLastInfoDate
:
new
Date
(),
staff
:
{
connectOrCreate
:
[
...
params
.
members
.
map
(
gitlabUser
=>
{
return
{
create
:
{
gitlabId
:
gitlabUser
.
id
,
firstname
:
gitlabUser
.
name
},
where
:
{
gitlabId
:
gitlabUser
.
id
,
firstname
:
gitlabUser
.
name
},
where
:
{
gitlabId
:
gitlabUser
.
id
}
};
...
...
@@ -135,7 +166,8 @@ class AssignmentRoutes implements RoutesManager {
await
db
.
assignment
.
update
({
where
:
{
name
:
req
.
boundParams
.
assignment
!
.
name
},
data
:
{
},
data
:
{
published
:
publish
}
});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment