From 9768001c3a81c1e19cb8f940f2016a0878524397 Mon Sep 17 00:00:00 2001 From: Sriramajeyam Sugumaran <153843+yesoreyeram@users.noreply.github.com> Date: Tue, 2 Apr 2024 10:35:06 +0100 Subject: [PATCH] updated query validaton / filtering --- src/validation.ts | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/validation.ts b/src/validation.ts index 50a7f82d..6642f73c 100644 --- a/src/validation.ts +++ b/src/validation.ts @@ -2,15 +2,32 @@ import { isEmpty } from 'lodash'; import { GitHubQuery, ProjectQueryType, QueryType } from './types'; export const isValid = (query: GitHubQuery): boolean => { - // The current requirement is that the query has a querytype - // TODO: have each option implement a validation function - if (query.queryType === QueryType.Projects) { - if (isEmpty(query.options?.organization) && query.options?.kind === ProjectQueryType.ORG) { + if (query.queryType === QueryType.Repositories) { + if (isEmpty(query.owner)) { + return false; + } + } + if ( + query.queryType === QueryType.Commits || + query.queryType === QueryType.Contributors || + query.queryType === QueryType.Tags || + query.queryType === QueryType.Releases || + query.queryType === QueryType.Labels || + query.queryType === QueryType.Milestones || + query.queryType === QueryType.Vulnerabilities || + query.queryType === QueryType.Stargazers + ) { + if (isEmpty(query.owner) || isEmpty(query.repository)) { return false; } + } + if (query.queryType === QueryType.Projects) { if (isEmpty(query.options?.user) && query.options?.kind === ProjectQueryType.USER) { return false; } + if (isEmpty(query.options?.organization)) { + return false; + } } return !!query.queryType; };