Skip to content

Commit

Permalink
see #180 coursecontroller can now stand on its own, 310controller is …
Browse files Browse the repository at this point in the history
…just coursecontroller, pass lateautotest to backend.
  • Loading branch information
rtholmes committed Dec 20, 2018
1 parent b30d07c commit 233659a
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 170 deletions.
3 changes: 2 additions & 1 deletion packages/autotest/src/autotest/mocks/MockClassPortal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export class MockClassPortal implements IClassPortal {
regressionDelivIds: [],
custom: {},
openTimestamp: new Date(2018, 1, 1).getTime(),
closeTimestamp: new Date(2018, 6, 1).getTime()
closeTimestamp: new Date(2018, 6, 1).getTime(),
lateAutoTest: false
};
}
Log.error('MockClassPortal::getContainerDetails() - MockClassPortal should not be used with: ' + name);
Expand Down
6 changes: 3 additions & 3 deletions packages/autotest/src/github/GitHubAutoTest.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as Docker from "dockerode";
import Config, {ConfigKey} from "../../../common/Config";
import Log from "../../../common/Log";
import {AutoTestResult, IFeedbackGiven} from "../../../common/types/AutoTestTypes";
Expand All @@ -11,8 +12,6 @@ import {
} from "../../../common/types/PortalTypes";
import Util from "../../../common/Util";
import {AutoTest} from "../autotest/AutoTest";

import * as Docker from "dockerode";
import {IClassPortal} from "../autotest/ClassPortal";
import {IDataStore} from "../autotest/DataStore";
import {GitHubService, IGitHubMessage} from "./GitHubService";
Expand Down Expand Up @@ -169,7 +168,8 @@ export class GitHubAutoTest extends AutoTest implements IGitHubTestManager {
return false;
}

if (deliv.closeTimestamp < info.timestamp) {
// late is ok if lateAutoTest is true
if (deliv.closeTimestamp < info.timestamp || deliv.lateAutoTest === false) {
Log.warn("GitHubAutoTest::checkCommentPreconditions(..) - ignored, deliverable closed to AutoTest.");
// closed
const msg = "This deliverable is closed to grading.";
Expand Down
5 changes: 5 additions & 0 deletions packages/common/types/PortalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ export interface AutoTestConfigTransport {
openTimestamp: number;

closeTimestamp: number;

/**
* Whether AutoTest can be invoked after the closeTimestamp has passed
*/
lateAutoTest: boolean;
}

export interface AutoTestAuthPayload {
Expand Down
79 changes: 56 additions & 23 deletions packages/portal/backend/src/controllers/CourseController.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,9 @@
import * as rp from "request-promise-native";

import Config, {ConfigKey} from "../../../../common/Config";
import Log from "../../../../common/Log";
import {
AutoTestDashboardTransport,
AutoTestGradeTransport,
AutoTestResultSummaryTransport,
CourseTransport,
DeliverableTransport,
GradeTransport,
ProvisionTransport,
RepositoryTransport,
StudentTransport,
TeamTransport
} from '../../../../common/types/PortalTypes';
import Util from "../../../../common/Util";
import {AuditLabel, Course, Deliverable, Grade, Person, PersonKind, Repository, Result, Team} from "../Types";
import {ProvisionTransport} from '../../../../common/types/PortalTypes';
import {Deliverable, Grade, Person} from "../Types";

import {DatabaseController} from "./DatabaseController";
import {DeliverablesController} from "./DeliverablesController";
import {GitHubActions} from "./GitHubActions";
import {GitHubController, IGitHubController} from "./GitHubController";
import {IGitHubController} from "./GitHubController";
import {GradesController} from "./GradesController";
import {PersonController} from "./PersonController";
import {RepositoryController} from "./RepositoryController";
Expand Down Expand Up @@ -76,7 +59,10 @@ export interface ICourseController {
computeNames(deliv: Deliverable, people: Person[]): Promise<{teamName: string | null, repoName: string | null}>;
}

export abstract class CourseController implements ICourseController {
/**
* This is a default course controller for courses that do not want to do anything unusual.
*/
export class CourseController implements ICourseController {

protected dbc = DatabaseController.getInstance();
protected pc = new PersonController();
Expand Down Expand Up @@ -117,7 +103,11 @@ export abstract class CourseController implements ICourseController {
public handleNewAutoTestGrade(deliv: Deliverable, newGrade: Grade, existingGrade: Grade): Promise<boolean> {
Log.info("CourseController::handleNewAutoTestGrade( " + deliv.id + ", " +
newGrade.personId + ", " + newGrade.score + ", ... ) - start");
if ((existingGrade === null || newGrade.score >= existingGrade.score) && newGrade.timestamp <= deliv.closeTimestamp) {

const gradeIsLarger = (existingGrade === null || newGrade.score >= existingGrade.score);
const gradeBeforeDeadline = newGrade.timestamp <= deliv.closeTimestamp;

if (gradeIsLarger === true && gradeBeforeDeadline === true) {
Log.trace("CourseController::handleNewAutoTestGrade( " + deliv.id + ", " +
newGrade.personId + ", " + newGrade.score + ", ... ) - returning true");
return Promise.resolve(true);
Expand All @@ -128,7 +118,50 @@ export abstract class CourseController implements ICourseController {
}
}

public abstract computeNames(deliv: Deliverable, people: Person[]): Promise<{teamName: string | null, repoName: string | null}>;
public async computeNames(deliv: Deliverable, people: Person[]): Promise<{teamName: string | null, repoName: string | null}> {
Log.info('CourseController::computeNames( ' + deliv.id + ', ... ) - start');

if (people.length < 1) {
throw new Error("CourseController::computeNames( ... ) - must provide people");
}

// sort people alph by their id
people = people.sort(function compare(p1: Person, p2: Person) {
return p1.id.localeCompare(p2.id);
}
);

let postfix = '';
for (const person of people) {
postfix = postfix + '_' + person.githubId;
}

let tName = '';
if (deliv.teamPrefix.length > 0) {
tName = deliv.teamPrefix + '_' + deliv.id + postfix;
} else {
tName = deliv.id + postfix;
}

let rName = '';
if (deliv.repoPrefix.length > 0) {
rName = deliv.repoPrefix + '_' + deliv.id + postfix;
} else {
rName = deliv.id + postfix;
}

const db = DatabaseController.getInstance();
const team = await db.getTeam(tName);
const repo = await db.getRepository(rName);

if (team === null && repo === null) {
Log.info('CourseController::computeNames( ... ) - done; t: ' + tName + ', r: ' + rName);
return {teamName: tName, repoName: rName};
} else {
// TODO: should really verify that the existing teams contain the right people already
return {teamName: tName, repoName: rName};
}
}

// NOTE: the default implementation is currently broken; do not use it.
/**
Expand Down
Loading

0 comments on commit 233659a

Please sign in to comment.