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'; ...@@ -5,6 +5,7 @@ import SessionManager from '../../../managers/SessionManager';
import ora from 'ora'; import ora from 'ora';
import DojoBackendManager from '../../../managers/DojoBackendManager'; import DojoBackendManager from '../../../managers/DojoBackendManager';
import Assignment from '../../../sharedByClients/models/Assignment'; import Assignment from '../../../sharedByClients/models/Assignment';
import SharedAssignmentHelper from '../../../shared/helpers/Dojo/SharedAssignmentHelper';
abstract class AssignmentPublishUnpublishCommandBase extends CommanderCommand { abstract class AssignmentPublishUnpublishCommandBase extends CommanderCommand {
...@@ -21,7 +22,9 @@ abstract class AssignmentPublishUnpublishCommandBase extends CommanderCommand { ...@@ -21,7 +22,9 @@ abstract class AssignmentPublishUnpublishCommandBase extends CommanderCommand {
protected async commandAction(assignmentNameOrUrl: string, options: { force: boolean }): Promise<void> { protected async commandAction(assignmentNameOrUrl: string, options: { force: boolean }): Promise<void> {
if ( !options.force ) { if ( !options.force ) {
options.force = (await inquirer.prompt({ 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; })).force;
} }
...@@ -40,10 +43,12 @@ abstract class AssignmentPublishUnpublishCommandBase extends CommanderCommand { ...@@ -40,10 +43,12 @@ abstract class AssignmentPublishUnpublishCommandBase extends CommanderCommand {
ora('Checking assignment:').start().info(); ora('Checking assignment:').start().info();
ora({ ora({
text: assignmentNameOrUrl, indent: 4 text : assignmentNameOrUrl,
indent: 4
}).start().info(); }).start().info();
const assignmentGetSpinner: ora.Ora = ora({ const assignmentGetSpinner: ora.Ora = ora({
text: 'Checking if assignment exists', indent: 8 text : 'Checking if assignment exists',
indent: 8
}).start(); }).start();
assignment = await DojoBackendManager.getAssignment(assignmentNameOrUrl); assignment = await DojoBackendManager.getAssignment(assignmentNameOrUrl);
if ( !assignment ) { if ( !assignment ) {
...@@ -52,6 +57,7 @@ abstract class AssignmentPublishUnpublishCommandBase extends CommanderCommand { ...@@ -52,6 +57,7 @@ abstract class AssignmentPublishUnpublishCommandBase extends CommanderCommand {
} }
assignmentGetSpinner.succeed(`The assignment exists`); assignmentGetSpinner.succeed(`The assignment exists`);
const assignmentCheckAccessSpinner: ora.Ora = ora({ const assignmentCheckAccessSpinner: ora.Ora = ora({
text: 'Checking accesses', indent: 8 text: 'Checking accesses', indent: 8
}).start(); }).start();
...@@ -60,6 +66,18 @@ abstract class AssignmentPublishUnpublishCommandBase extends CommanderCommand { ...@@ -60,6 +66,18 @@ abstract class AssignmentPublishUnpublishCommandBase extends CommanderCommand {
return; return;
} }
assignmentCheckAccessSpinner.succeed(`You are in the staff of this assignment`); 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