Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Github PR in URL validation #2546

Merged
merged 4 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading