Skip to content

Commit

Permalink
Add Github PR in URL validation (#2546)
Browse files Browse the repository at this point in the history
* feat: add Github PR in URL validation

* feat: update spec

* fix: typo in validation prop
  • Loading branch information
AlreadyBored authored Nov 3, 2024
1 parent 3f70893 commit 9404a0b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 3 deletions.
6 changes: 6 additions & 0 deletions client/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7559,6 +7559,12 @@ export interface Validations {
* @memberof Validations
*/
'githubIdInUrl': boolean;
/**
*
* @type {boolean}
* @memberof Validations
*/
'githubPrInUrl': boolean;
}
/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useRouter } from 'next/router';
import { useEffect, useMemo, useState, useContext } from 'react';
import { useAsync } from 'react-use';
import { CourseService, CrossCheckComment, CrossCheckCriteria, CrossCheckReview, TaskSolution } from 'services/course';
import { privateRsRepoPattern, urlWithIpPattern } from 'services/validators';
import { githubPrUrl, privateRsRepoPattern, urlWithIpPattern } from 'services/validators';
import { getQueryString } from 'utils/queryParams-utils';
import { CoursesTasksApi, CrossCheckFeedbackDto, CrossCheckMessageDtoRoleEnum } from 'api';
import { SessionContext, useActiveCourseContext } from 'modules/Course/contexts';
Expand All @@ -34,6 +34,12 @@ const validUrlRule: Rule = {
message: 'Please provide a valid link (must start with `http://` or `https://`)',
};

const githubPrInUrlRule: Rule = {
required: true,
pattern: githubPrUrl,
message: 'Link should be a valid GitHub Pull Request URL',
};

const notPrivateRsRepoRule: Rule = {
validator: (_, value) => {
if (privateRsRepoPattern.test(value)) {
Expand Down Expand Up @@ -199,6 +205,7 @@ export function CrossCheckSubmit() {
validUrlRule,
notPrivateRsRepoRule,
...(task.validations?.githubIdInUrl ? [createGithubInUrlRule(session.githubId)] : []),
...(task.validations?.githubPrInUrl ? [githubPrInUrlRule] : []),
]}
>
<Input placeholder="link in the form of https://www.google.com" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ export function CourseTaskModal(props: Props) {
<Form.Item name={['validations', 'githubIdInUrl']} valuePropName="checked">
<Checkbox>Require Github Username in URL</Checkbox>
</Form.Item>
<Form.Item name={['validations', 'githubPrInUrl']} valuePropName="checked">
<Checkbox>Require Github Pull Request in URL</Checkbox>
</Form.Item>
</>
) : null}
</ModalForm>
Expand Down
2 changes: 2 additions & 0 deletions nestjs/src/courses/course-tasks/dto/course-task.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { TaskSolutionDto } from 'src/courses/task-solutions/dto';
class Validations {
@ApiProperty()
[CourseTaskValidation.githubIdInUrl]: boolean;
@ApiProperty()
[CourseTaskValidation.githubPrInUrl]: boolean;
}

@ApiResponse({})
Expand Down
4 changes: 2 additions & 2 deletions nestjs/src/spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -3070,8 +3070,8 @@
},
"Validations": {
"type": "object",
"properties": { "githubIdInUrl": { "type": "boolean" } },
"required": ["githubIdInUrl"]
"properties": { "githubIdInUrl": { "type": "boolean" }, "githubPrInUrl": { "type": "boolean" } },
"required": ["githubIdInUrl", "githubPrInUrl"]
},
"CourseTaskDto": {
"type": "object",
Expand Down
1 change: 1 addition & 0 deletions server/src/models/courseTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export enum CrossCheckStatus {

export enum CourseTaskValidation {
githubIdInUrl = 'githubIdInUrl',
githubPrInUrl = 'githubPrInUrl',
}

@Entity()
Expand Down

0 comments on commit 9404a0b

Please sign in to comment.