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

feat: more filters for deploymentsByFilter #3866

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
20 changes: 18 additions & 2 deletions services/api/src/resources/deployment/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export const getDeploymentsByFilter: ResolverFn = async (
{ sqlClientPool, hasPermission, models, keycloakGrant, keycloakUsersGroups, adminScopes }
) => {

const { openshifts, deploymentStatus = ["NEW", "PENDING", "RUNNING", "QUEUED"] } = input;
const { openshifts, deploymentStatus = ["NEW", "PENDING", "RUNNING", "QUEUED"], month, includeDeleted } = input;

/*
use the same mechanism for viewing all projects
Expand Down Expand Up @@ -181,13 +181,29 @@ export const getDeploymentsByFilter: ResolverFn = async (
queryBuilder = queryBuilder.whereIn('environment.project', userProjectIds);
}

// collect builds for a specific year/month
if (month) {
queryBuilder = queryBuilder.andWhere(
knex.raw(`YEAR(deployment.created) = YEAR(STR_TO_DATE(?, '%Y-%m'))`, month),
)
.andWhere(
knex.raw(`MONTH(deployment.created) = MONTH(STR_TO_DATE(?, '%Y-%m'))`, month),
);
}

if(openshifts) {
queryBuilder = queryBuilder.whereIn('environment.openshift', openshifts);
}

queryBuilder = queryBuilder.whereIn('deployment.status', deploymentStatus);

queryBuilder = queryBuilder.where('environment.deleted', '=', '0000-00-00 00:00:00');
// if includeDeleted is false, exclude deleted environments in the results (default)
if (!includeDeleted) {
queryBuilder = queryBuilder.where('environment.deleted', '=', '0000-00-00 00:00:00');
}

// exclude results where a project doesn't exist
queryBuilder = queryBuilder.whereRaw('environment.project IN (SELECT id FROM project)')

const queryBuilderString = queryBuilder.toString();

Expand Down
2 changes: 1 addition & 1 deletion services/api/src/typeDefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,7 @@ const typeDefs = gql`
deploymentByRemoteId(id: String): Deployment
deploymentByName(input: DeploymentByNameInput): Deployment
deploymentsByBulkId(bulkId: String): [Deployment]
deploymentsByFilter(openshifts: [Int], deploymentStatus: [DeploymentStatusType]): [Deployment]
deploymentsByFilter(openshifts: [Int], deploymentStatus: [DeploymentStatusType], month: Date, includeDeleted: Boolean): [Deployment]
taskByTaskName(taskName: String): Task
taskByRemoteId(id: String): Task
taskById(id: Int): Task
Expand Down