Skip to content
Snippets Groups Projects
Commit 54e82603 authored by joel.vonderwe's avatar joel.vonderwe Committed by michael.minelli
Browse files

Add language to assignment creation

parent 9837dfa7
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,7 @@ import TextStyle from '../../../types/TextStyle.js';
import Config from '../../../config/Config';
type CommandOptions = { name: string, template?: string, members_id?: Array<number>, members_username?: Array<string>, clone?: string | boolean, sonar?: boolean }
type CommandOptions = { name: string, language: string, template?: string, members_id?: Array<number>, members_username?: Array<string>, clone?: string | boolean, sonar?: boolean }
class AssignmentCreateCommand extends CommanderCommand {
......@@ -25,6 +25,7 @@ class AssignmentCreateCommand extends CommanderCommand {
this.command
.description('create a new repository for an assignment')
.requiredOption('-n, --name <name>', 'name of the assignment')
.requiredOption('-l, --language <string>', 'main programming language of the assignment')
.option('-i, --members_id <ids...>', 'list of gitlab members ids (teaching staff) to add to the repository')
.option('-u, --members_username <usernames...>', 'list of gitlab members username (teaching staff) to add to the repository')
.option('-t, --template <string>', 'id or url of the template (http/s and ssh urls are possible)')
......@@ -61,6 +62,18 @@ class AssignmentCreateCommand extends CommanderCommand {
}
assignmentGetSpinner.succeed(`Assignment name "${ options.name }" is available`);
const languagesSpinner: ora.Ora = ora('Checking language support').start();
const languages = await DojoBackendManager.getLanguages();
if ( !languages.includes(options.language) ) {
languagesSpinner.fail(`Language "${ options.language }" is not supported. Choose a supported language or "other"`);
console.log('List of supported languages:');
for ( const l of languages ) {
console.log(` - ${ l }`);
}
return;
}
languagesSpinner.succeed(`Language "${ options.language }" is supported`);
if ( options.template ) {
this.templateIdOrNamespace = options.template;
......@@ -77,7 +90,7 @@ class AssignmentCreateCommand extends CommanderCommand {
private async createAssignment(options: CommandOptions) {
console.log(TextStyle.BLOCK('Please wait while we are creating the assignment (approximately 10 seconds)...'));
this.assignment = await DojoBackendManager.createAssignment(options.name, this.members!, this.templateIdOrNamespace, this.sonar);
this.assignment = await DojoBackendManager.createAssignment(options.name, options.language, this.members!, this.templateIdOrNamespace, this.sonar);
const oraInfo = (message: string) => {
ora({
......
......@@ -247,7 +247,7 @@ class DojoBackendManager {
}
}
public async createAssignment(name: string, members: Array<Gitlab.UserSchema>, templateIdOrNamespace: string | null, sonar: boolean = false, verbose: boolean = true): Promise<Assignment> {
public async createAssignment(name: string, language: string, members: Array<Gitlab.UserSchema>, templateIdOrNamespace: string | null, sonar: boolean = false, verbose: boolean = true): Promise<Assignment> {
const spinner: ora.Ora = ora('Creating assignment...');
if ( verbose ) {
......@@ -257,6 +257,7 @@ class DojoBackendManager {
try {
const response = await axios.post<DojoBackendResponse<Assignment>>(DojoBackendHelper.getApiUrl(ApiRoute.ASSIGNMENT_CREATE), Object.assign({
name : name,
language: language,
members : JSON.stringify(members),
useSonar: String(sonar)
}, templateIdOrNamespace ? { template: templateIdOrNamespace } : {}));
......@@ -374,9 +375,16 @@ class DojoBackendManager {
}
}
public async isSonarEnabled() {
const sonar = await axios.get<DojoBackendResponse<{ sonarEnabled: boolean }>>(this.getApiUrl(ApiRoute.SONAR));
return sonar.data.data.sonarEnabled;
public async isSonarEnabled(): Promise<boolean> {
const response = await axios.get<DojoBackendResponse<{ sonarEnabled: boolean }>>(DojoBackendHelper.getApiUrl(ApiRoute.SONAR));
return response.data.data.sonarEnabled;
}
public async getLanguages(): Promise<Array<string>> {
const response = await axios.get<DojoBackendResponse<Array<string>>>(DojoBackendHelper.getApiUrl(ApiRoute.LANGUAGES));
return response.data.data;
}
public async createTag(name: string, type: string, verbose: boolean = true): Promise<Tag | undefined> {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment