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

AssignmentPublish => Add test if it is publishable based on the pipeline state

parent 5364c1a8
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@ import SessionManager from '../../../managers/SessionManager';
import ora from 'ora';
import DojoBackendManager from '../../../managers/DojoBackendManager';
import Assignment from '../../../sharedByClients/models/Assignment';
import SharedAssignmentHelper from '../../../shared/helpers/Dojo/SharedAssignmentHelper';
abstract class AssignmentPublishUnpublishCommandBase extends CommanderCommand {
......@@ -21,7 +22,9 @@ abstract class AssignmentPublishUnpublishCommandBase extends CommanderCommand {
protected async commandAction(assignmentNameOrUrl: string, options: { force: boolean }): Promise<void> {
if ( !options.force ) {
options.force = (await inquirer.prompt({
type: 'confirm', name: 'force', message: this.publish ? 'Are you sure you want to publish this assignment?' : 'Are you sure you want to unpublish this assignment?'
type : 'confirm',
name : 'force',
message: this.publish ? 'Are you sure you want to publish this assignment?' : 'Are you sure you want to unpublish this assignment?'
})).force;
}
......@@ -40,10 +43,12 @@ abstract class AssignmentPublishUnpublishCommandBase extends CommanderCommand {
ora('Checking assignment:').start().info();
ora({
text: assignmentNameOrUrl, indent: 4
text : assignmentNameOrUrl,
indent: 4
}).start().info();
const assignmentGetSpinner: ora.Ora = ora({
text: 'Checking if assignment exists', indent: 8
text : 'Checking if assignment exists',
indent: 8
}).start();
assignment = await DojoBackendManager.getAssignment(assignmentNameOrUrl);
if ( !assignment ) {
......@@ -52,6 +57,7 @@ abstract class AssignmentPublishUnpublishCommandBase extends CommanderCommand {
}
assignmentGetSpinner.succeed(`The assignment exists`);
const assignmentCheckAccessSpinner: ora.Ora = ora({
text: 'Checking accesses', indent: 8
}).start();
......@@ -60,6 +66,18 @@ abstract class AssignmentPublishUnpublishCommandBase extends CommanderCommand {
return;
}
assignmentCheckAccessSpinner.succeed(`You are in the staff of this assignment`);
const assignmentIsPublishable: ora.Ora = ora({
text : 'Checking if the assignment is publishable',
indent: 8
}).start();
const isPublishable = await SharedAssignmentHelper.isPublishable(assignment.gitlabId);
if ( !isPublishable.isPublishable ) {
assignmentIsPublishable.fail(`The assignment is not publishable: ${ isPublishable.status?.message }`);
return;
}
assignmentIsPublishable.succeed(`The assignment is publishable`);
}
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment