Skip to content
Snippets Groups Projects
Verified Commit 53ed56e9 authored by orestis.malaspin's avatar orestis.malaspin
Browse files

Fixes bug cloning assignment instead of exercise

parent 74614ffa
No related branches found
No related tags found
1 merge request!3Resolve "Option -c for exercise subcommand clones assignment"
Pipeline #27912 passed
This commit is part of merge request !3. Comments created here will be created in the context of that merge request.
import CommanderCommand from '../../CommanderCommand'; import CommanderCommand from '../../CommanderCommand';
import chalk from 'chalk'; import chalk from 'chalk';
import GitlabManager from '../../../managers/GitlabManager'; import GitlabManager from '../../../managers/GitlabManager';
import GitlabUser from '../../../shared/types/Gitlab/GitlabUser'; import GitlabUser from '../../../shared/types/Gitlab/GitlabUser';
import ora from 'ora'; import ora from 'ora';
import DojoBackendManager from '../../../managers/DojoBackendManager'; import DojoBackendManager from '../../../managers/DojoBackendManager';
import AccessesHelper from '../../../helpers/AccessesHelper'; import AccessesHelper from '../../../helpers/AccessesHelper';
import Assignment from '../../../sharedByClients/models/Assignment'; import Assignment from '../../../sharedByClients/models/Assignment';
import Exercise from '../../../sharedByClients/models/Exercise'; import Exercise from '../../../sharedByClients/models/Exercise';
class ExerciseCreateCommand extends CommanderCommand { class ExerciseCreateCommand extends CommanderCommand {
...@@ -14,12 +14,12 @@ class ExerciseCreateCommand extends CommanderCommand { ...@@ -14,12 +14,12 @@ class ExerciseCreateCommand extends CommanderCommand {
protected defineCommand() { protected defineCommand() {
this.command this.command
.description('create a new exercise from an assignment') .description('create a new exercise from an assignment')
.requiredOption('-a, --assignment <value>', 'assignment source (Dojo assignment ID, Dojo assignment name or Gitlab assignment URL)') .requiredOption('-a, --assignment <value>', 'assignment source (Dojo assignment ID, Dojo assignment name or Gitlab assignment URL)')
.option('-i, --members_id <ids...>', 'list of gitlab members ids (group\'s student) to add to the repository') .option('-i, --members_id <ids...>', 'list of gitlab members ids (group\'s student) to add to the repository')
.option('-u, --members_username <usernames...>', 'list of gitlab members username (group\'s student) to add to the repository') .option('-u, --members_username <usernames...>', 'list of gitlab members username (group\'s student) to add to the repository')
.option('-c, --clone [string]', 'automatically clone the repository (SSH required) in the specified directory (this will create a subdirectory with the assignment name)') .option('-c, --clone [string]', 'automatically clone the repository (SSH required) in the specified directory (this will create a subdirectory with the assignment name)')
.action(this.commandAction.bind(this)); .action(this.commandAction.bind(this));
} }
protected async commandAction(options: { assignment: string, members_id?: Array<number>, members_username?: Array<string>, clone?: string | boolean }): Promise<void> { protected async commandAction(options: { assignment: string, members_id?: Array<number>, members_username?: Array<string>, clone?: string | boolean }): Promise<void> {
...@@ -31,36 +31,36 @@ class ExerciseCreateCommand extends CommanderCommand { ...@@ -31,36 +31,36 @@ class ExerciseCreateCommand extends CommanderCommand {
{ {
console.log(chalk.cyan('Please wait while we verify and retrieve data...')); console.log(chalk.cyan('Please wait while we verify and retrieve data...'));
if (!await AccessesHelper.checkStudent()) { if ( !await AccessesHelper.checkStudent() ) {
return; return;
} }
members = await GitlabManager.fetchMembers(options); members = await GitlabManager.fetchMembers(options);
if (!members) { if ( !members ) {
return; return;
} }
ora('Checking assignment:').start().info(); ora('Checking assignment:').start().info();
const assignmentGetSpinner: ora.Ora = ora({ const assignmentGetSpinner: ora.Ora = ora({
text: 'Checking if assignment exists', text : 'Checking if assignment exists',
indent: 4 indent: 4
}).start(); }).start();
assignment = await DojoBackendManager.getAssignment(options.assignment); assignment = await DojoBackendManager.getAssignment(options.assignment);
if (!assignment) { if ( !assignment ) {
assignmentGetSpinner.fail(`Assignment "${options.assignment}" doesn't exists`); assignmentGetSpinner.fail(`Assignment "${ options.assignment }" doesn't exists`);
return; return;
} }
assignmentGetSpinner.succeed(`Assignment "${options.assignment}" exists`); assignmentGetSpinner.succeed(`Assignment "${ options.assignment }" exists`);
const assignmentPublishedSpinner: ora.Ora = ora({ const assignmentPublishedSpinner: ora.Ora = ora({
text: 'Checking if assignment is published', text : 'Checking if assignment is published',
indent: 4 indent: 4
}).start(); }).start();
if (!assignment.published) { if ( !assignment.published ) {
assignmentPublishedSpinner.fail(`Assignment "${assignment.name}" isn't published`); assignmentPublishedSpinner.fail(`Assignment "${ assignment.name }" isn't published`);
return; return;
} }
assignmentPublishedSpinner.succeed(`Assignment "${assignment.name}" is published`); assignmentPublishedSpinner.succeed(`Assignment "${ assignment.name }" is published`);
} }
//Create the exercise //Create the exercise
...@@ -72,27 +72,27 @@ class ExerciseCreateCommand extends CommanderCommand { ...@@ -72,27 +72,27 @@ class ExerciseCreateCommand extends CommanderCommand {
const oraInfo = (message: string) => { const oraInfo = (message: string) => {
ora({ ora({
text: message, text : message,
indent: 4 indent: 4
}).start().info(); }).start().info();
}; };
oraInfo(`${chalk.magenta('Id:')} ${exercise.id}`); oraInfo(`${ chalk.magenta('Id:') } ${ exercise.id }`);
oraInfo(`${chalk.magenta('Name:')} ${exercise.name}`); oraInfo(`${ chalk.magenta('Name:') } ${ exercise.name }`);
oraInfo(`${chalk.magenta('Web URL:')} ${exercise.gitlabCreationInfo.web_url}`); oraInfo(`${ chalk.magenta('Web URL:') } ${ exercise.gitlabCreationInfo.web_url }`);
oraInfo(`${chalk.magenta('HTTP Repo:')} ${exercise.gitlabCreationInfo.http_url_to_repo}`); oraInfo(`${ chalk.magenta('HTTP Repo:') } ${ exercise.gitlabCreationInfo.http_url_to_repo }`);
oraInfo(`${chalk.magenta('SSH Repo:')} ${exercise.gitlabCreationInfo.ssh_url_to_repo}`); oraInfo(`${ chalk.magenta('SSH Repo:') } ${ exercise.gitlabCreationInfo.ssh_url_to_repo }`);
} catch (error) { } catch ( error ) {
return; return;
} }
} }
// Clone the repository // Clone the repository
{ {
if (options.clone) { if ( options.clone ) {
console.log(chalk.cyan('Please wait while we are cloning the repository...')); console.log(chalk.cyan('Please wait while we are cloning the repository...'));
await GitlabManager.cloneRepository(options.clone, exercise.gitlabCreationInfo.ssh_url_to_repo, `DojoExercise - ${exercise.assignmentName}`, true, 0); await GitlabManager.cloneRepository(options.clone, exercise.gitlabCreationInfo.ssh_url_to_repo, `DojoExercise - ${ exercise.assignmentName }`, true, 0);
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment