Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DojoCLI
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
UI
DojoCLI
Commits
a488fc6d
Commit
a488fc6d
authored
1 year ago
by
michael.minelli
Browse files
Options
Downloads
Patches
Plain Diff
Commands => Add exercise correction command
parent
706ea013
No related branches found
No related tags found
No related merge requests found
Pipeline
#29608
passed
1 year ago
Stage: code_quality
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
NodeApp/src/commander/exercise/ExerciseCommand.ts
+5
-3
5 additions, 3 deletions
NodeApp/src/commander/exercise/ExerciseCommand.ts
NodeApp/src/commander/exercise/subcommands/ExerciseCorrectionCommand.ts
+76
-0
76 additions, 0 deletions
...mmander/exercise/subcommands/ExerciseCorrectionCommand.ts
with
81 additions
and
3 deletions
NodeApp/src/commander/exercise/ExerciseCommand.ts
+
5
−
3
View file @
a488fc6d
import
CommanderCommand
from
'
../CommanderCommand
'
;
import
CommanderCommand
from
'
../CommanderCommand
'
;
import
ExerciseCreateCommand
from
'
./subcommands/ExerciseCreateCommand
'
;
import
ExerciseCreateCommand
from
'
./subcommands/ExerciseCreateCommand
'
;
import
ExerciseRunCommand
from
'
./subcommands/ExerciseRunCommand
'
;
import
ExerciseRunCommand
from
'
./subcommands/ExerciseRunCommand
'
;
import
ExerciseCorrectionCommand
from
'
./subcommands/ExerciseCorrectionCommand
'
;
class
ExerciseCommand
extends
CommanderCommand
{
class
ExerciseCommand
extends
CommanderCommand
{
...
@@ -14,6 +15,7 @@ class ExerciseCommand extends CommanderCommand {
...
@@ -14,6 +15,7 @@ class ExerciseCommand extends CommanderCommand {
protected
defineSubCommands
()
{
protected
defineSubCommands
()
{
ExerciseCreateCommand
.
registerOnCommand
(
this
.
command
);
ExerciseCreateCommand
.
registerOnCommand
(
this
.
command
);
ExerciseRunCommand
.
registerOnCommand
(
this
.
command
);
ExerciseRunCommand
.
registerOnCommand
(
this
.
command
);
ExerciseCorrectionCommand
.
registerOnCommand
(
this
.
command
);
}
}
protected
async
commandAction
():
Promise
<
void
>
{
}
protected
async
commandAction
():
Promise
<
void
>
{
}
...
...
This diff is collapsed.
Click to expand it.
NodeApp/src/commander/exercise/subcommands/ExerciseCorrectionCommand.ts
0 → 100644
+
76
−
0
View file @
a488fc6d
import
CommanderCommand
from
'
../../CommanderCommand
'
;
import
ora
from
'
ora
'
;
import
DojoBackendManager
from
'
../../../managers/DojoBackendManager
'
;
import
Config
from
'
../../../config/Config
'
;
import
Assignment
from
'
../../../sharedByClients/models/Assignment
'
;
import
inquirer
from
'
inquirer
'
;
import
open
from
'
open
'
;
import
chalk
from
'
chalk
'
;
type
CorrectionResume
=
{
name
:
string
,
value
:
string
}
class
ExerciseCorrectionCommand
extends
CommanderCommand
{
protected
commandName
:
string
=
'
correction
'
;
protected
defineCommand
()
{
this
.
command
.
description
(
'
link an exercise repo as a correction for an assignment
'
)
.
requiredOption
(
'
-a, --assignment <string>
'
,
'
id or url of the assignment of the correction
'
)
.
action
(
this
.
commandAction
.
bind
(
this
));
}
protected
async
commandAction
(
options
:
{
assignment
:
string
}):
Promise
<
void
>
{
const
assignmentGetSpinner
:
ora
.
Ora
=
ora
(
'
Fetching assignment data
'
).
start
();
const
assignment
=
await
DojoBackendManager
.
getAssignment
(
options
.
assignment
);
if
(
!
assignment
)
{
assignmentGetSpinner
.
fail
(
`The assignment doesn't exists`
);
return
;
}
if
(
assignment
.
corrections
&&
assignment
.
corrections
.
length
>
0
)
{
Config
.
interactiveMode
?
await
this
.
showCorrectionsInteractive
(
assignment
,
assignmentGetSpinner
)
:
this
.
showCorrections
(
assignment
,
assignmentGetSpinner
);
}
else
{
assignmentGetSpinner
.
fail
(
`The assignment doesn't have any corrections yet`
);
return
;
}
}
private
getCorrections
(
assignment
:
Assignment
):
Array
<
CorrectionResume
>
{
return
assignment
.
corrections
.
map
(
correction
=>
{
return
{
name
:
correction
.
name
.
replace
(
correction
.
assignmentName
,
''
).
split
(
'
-
'
)[
2
].
trim
(),
value
:
correction
.
correctionCommit
!
.
web_url
?.
replace
(
'
/commit/
'
,
'
/tree/
'
)
??
''
};
});
}
private
showCorrections
(
assignment
:
Assignment
,
spinner
:
ora
.
Ora
)
{
spinner
.
succeed
(
`Here are corrections of the assignment '
${
assignment
.
name
}
':`
);
this
.
getCorrections
(
assignment
).
forEach
(
correction
=>
{
console
.
log
(
chalk
.
green
(
`-
${
correction
.
name
}
`
));
console
.
log
(
`
${
correction
.
value
}
`
);
});
}
private
async
showCorrectionsInteractive
(
assignment
:
Assignment
,
spinner
:
ora
.
Ora
)
{
spinner
.
stop
();
const
correctionUrl
:
string
=
(
await
inquirer
.
prompt
({
name
:
'
correctionUrl
'
,
message
:
'
Which correction do you want to consult? (use arrow keys then enter)
'
,
type
:
'
list
'
,
choices
:
this
.
getCorrections
(
assignment
),
default
:
false
})).
correctionUrl
;
console
.
log
(
chalk
.
green
(
correctionUrl
));
open
(
correctionUrl
).
then
();
}
}
export
default
new
ExerciseCorrectionCommand
();
\ No newline at end of file
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