Skip to content

Commit

Permalink
updated query validaton / filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
yesoreyeram committed Apr 2, 2024
1 parent 29a2b2b commit 9768001
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit 9768001

Please sign in to comment.