Skip to content
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
19 changes: 19 additions & 0 deletions app/libs/tenant-query.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { ExpressionBuilder } from 'kysely'
import type * as TenantDB from '~/app/services/tenant-type'

/**
* companyGithubUsers.type が Bot でない行のみ残すフィルタ。
* LEFT JOIN で companyGithubUsers に結合している前提で使う。
* NULL(未登録ユーザー)も通す。
*/
export function excludeBots(
eb: ExpressionBuilder<
TenantDB.DB & { companyGithubUsers: TenantDB.CompanyGithubUsers },
keyof TenantDB.DB | 'companyGithubUsers'
>,
) {
return eb.or([
eb('companyGithubUsers.type', 'is', null),
eb('companyGithubUsers.type', '!=', 'Bot'),
])
}
15 changes: 3 additions & 12 deletions app/routes/$orgSlug/analysis/reviews/+functions/queries.server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { sql } from 'kysely'
import { excludeBots } from '~/app/libs/tenant-query.server'
import { getTenantDb } from '~/app/services/tenant-db.server'
import type { OrganizationId } from '~/app/types/organization'

Expand Down Expand Up @@ -122,12 +123,7 @@ export const getWipCycleRawData = async (
.$if(teamId != null, (qb) =>
qb.where('repositories.teamId', '=', teamId as string),
)
.where((eb) =>
eb.or([
eb('companyGithubUsers.type', 'is', null),
eb('companyGithubUsers.type', '!=', 'Bot'),
]),
)
.where(excludeBots)
.leftJoin('pullRequestFeedbacks', (join) =>
join
.onRef(
Expand Down Expand Up @@ -188,12 +184,7 @@ export const getPRSizeDistribution = async (
.$if(teamId != null, (qb) =>
qb.where('repositories.teamId', '=', teamId as string),
)
.where((eb) =>
eb.or([
eb('companyGithubUsers.type', 'is', null),
eb('companyGithubUsers.type', '!=', 'Bot'),
]),
)
.where(excludeBots)
.leftJoin('pullRequestFeedbacks', (join) =>
join
.onRef(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { pipe, sortBy } from 'remeda'
import { calculateBusinessHours } from '~/app/libs/business-hours'
import dayjs from '~/app/libs/dayjs'
import { excludeBots } from '~/app/libs/tenant-query.server'
import { getTenantDb } from '~/app/services/tenant-db.server'
import type { OrganizationId } from '~/app/types/organization'

Expand Down Expand Up @@ -31,12 +32,7 @@ export const getDeployedPullRequestReport = async (
.$if(teamId != null, (qb) =>
qb.where('repositories.teamId', '=', teamId as string),
)
.where((eb) =>
eb.or([
eb('companyGithubUsers.type', 'is', null),
eb('companyGithubUsers.type', '!=', 'Bot'),
]),
)
.where(excludeBots)
.leftJoin('pullRequestFeedbacks', (join) =>
join
.onRef(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { pipe, sortBy } from 'remeda'
import { calculateBusinessHours } from '~/app/libs/business-hours'
import dayjs from '~/app/libs/dayjs'
import { excludeBots } from '~/app/libs/tenant-query.server'
import { getTenantDb } from '~/app/services/tenant-db.server'
import type { OrganizationId } from '~/app/types/organization'

Expand Down Expand Up @@ -30,12 +31,7 @@ export const getMergedPullRequestReport = async (
.$if(teamId != null, (qb) =>
qb.where('repositories.teamId', '=', teamId as string),
)
.where((eb) =>
eb.or([
eb('companyGithubUsers.type', 'is', null),
eb('companyGithubUsers.type', '!=', 'Bot'),
]),
)
.where(excludeBots)
.leftJoin('pullRequestFeedbacks', (join) =>
join
.onRef(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { pipe, sortBy } from 'remeda'
import { calculateBusinessHours } from '~/app/libs/business-hours'
import dayjs from '~/app/libs/dayjs'
import { excludeBots } from '~/app/libs/tenant-query.server'
import { getTenantDb } from '~/app/services/tenant-db.server'
import type { OrganizationId } from '~/app/types/organization'

Expand Down Expand Up @@ -33,12 +34,7 @@ export const getOngoingPullRequestReport = async (
)
.where('mergedAt', 'is', null)
.where('state', '=', 'open')
.where((eb) =>
eb.or([
eb('companyGithubUsers.type', 'is', null),
eb('companyGithubUsers.type', '!=', 'Bot'),
]),
)
.where(excludeBots)
.leftJoin('pullRequestFeedbacks', (join) =>
join
.onRef(
Expand Down
13 changes: 7 additions & 6 deletions app/routes/$orgSlug/workload/+functions/stacks.server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { sql } from 'kysely'
import { excludeBots } from '~/app/libs/tenant-query.server'
import { getTenantDb } from '~/app/services/tenant-db.server'
import type { OrganizationId } from '~/app/types/organization'

Expand Down Expand Up @@ -26,12 +27,7 @@ export const getOpenPullRequests = async (
.$if(teamId != null, (qb) =>
qb.where('repositories.teamId', '=', teamId as string),
)
.where((eb) =>
eb.or([
eb('companyGithubUsers.type', 'is', null),
eb('companyGithubUsers.type', '!=', 'Bot'),
]),
)
.where(excludeBots)
.select([
'pullRequests.author',
'pullRequests.number',
Expand All @@ -48,6 +44,10 @@ export const getOpenPullRequests = async (
select 1 from ${sql.ref('pullRequestReviewers')}
where ${sql.ref('pullRequestReviewers.pullRequestNumber')} = ${sql.ref('pullRequests.number')}
and ${sql.ref('pullRequestReviewers.repositoryId')} = ${sql.ref('pullRequests.repositoryId')}
and lower(${sql.ref('pullRequestReviewers.reviewer')}) not in (
select lower(${sql.ref('companyGithubUsers.login')}) from ${sql.ref('companyGithubUsers')}
where ${sql.ref('companyGithubUsers.type')} = 'Bot'
)
)`.as('hasAnyReviewer'),
)
.execute()
Expand Down Expand Up @@ -92,6 +92,7 @@ export const getPendingReviewAssignments = async (
.where('pullRequests.mergedAt', 'is', null)
.where('pullRequests.closedAt', 'is', null)
.where('pullRequestReviewers.requestedAt', 'is not', null)
.where(excludeBots)
.$if(teamId != null, (qb) =>
qb.where('repositories.teamId', '=', teamId as string),
)
Expand Down