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
24 changes: 19 additions & 5 deletions frontend/src/lib/components/nav/nav_header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import { fade } from "svelte/transition";
import { transitionConfig } from "$components/nav/transitions";
import { organisations } from "$lib/wailsjs/go/models";
import { orgSvc } from "$lib/watchtower";
import { goto, invalidateAll } from "$app/navigation";
type Props = {
expand?: boolean;
currentOrg: organisations.OrganisationDTO;
Expand Down Expand Up @@ -33,6 +35,12 @@
let otherOrgs = $derived.by(() => {
return allOrgs.filter((o) => o.id !== currentOrg.id);
});

async function switchOrganisation(orgId: number) {
await orgSvc.setDefault(orgId);
await invalidateAll();
await goto(resolve("/dashboard"));
}
</script>

<div class="flex items-center py-2">
Expand Down Expand Up @@ -60,16 +68,22 @@
</DropdownMenu.Trigger>
<DropdownMenu.Content class="w-56" side="bottom" align="start">
<DropdownMenu.Label>Active Organisation</DropdownMenu.Label>
<DropdownMenu.Item>
<a class="w-full" href={resolve(`/organisations/${currentOrg.id}`)}>
<span class="capitalize">{currentOrg.friendly_name}</span>
</a>
<DropdownMenu.Item
onclick={async () => {
await switchOrganisation(currentOrg.id);
}}
>
<span class="capitalize">{currentOrg.friendly_name}</span>
</DropdownMenu.Item>
{#if otherOrgs.length > 0}
<DropdownMenu.Separator />
<DropdownMenu.Label>Other Organisations</DropdownMenu.Label>
{#each otherOrgs as org (org.id)}
<DropdownMenu.Item>
<DropdownMenu.Item
onclick={async () => {
await switchOrganisation(org.id);
}}
>
<a class="w-full" href={resolve(`/organisations/${org.id}`)}>
<span class="capitalize">{org.friendly_name}</span>
</a>
Expand Down
91 changes: 0 additions & 91 deletions internal/database/insights.sql.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 0 additions & 33 deletions internal/database/queries/insights.sql
Original file line number Diff line number Diff line change
@@ -1,36 +1,3 @@
-- name: GetPullRequestInsights :one
WITH average_days_to_merge AS (
SELECT ROUND((merged_at - created_at) / 86400.0, 2) AS avg_days_to_merge
FROM pull_requests
WHERE state = 'MERGED'
AND created_at >= strftime('%s', 'now', ?)
)
SELECT
ROUND(MIN(avg_days_to_merge),2) AS min_days_to_merge,
ROUND(MAX(avg_days_to_merge),2) AS max_days_to_merge,
ROUND(AVG(avg_days_to_merge),2) AS avg_days_to_merge,
COUNT(*) AS merged,
(SELECT COUNT(*) FROM pull_requests WHERE state = 'CLOSED' AND created_at >= strftime('%s', 'now', ?)) AS closed,
(SELECT COUNT(*) FROM pull_requests WHERE state = 'OPEN' AND created_at >= strftime('%s', 'now', ?)) AS open
FROM average_days_to_merge;

-- name: GetSecuritiesInsights :one
WITH average_days_to_fix AS (
SELECT ROUND((fixed_at - created_at) / 86400, 2) as days_to_fix
FROM securities
WHERE state = 'FIXED'
AND fixed_at IS NOT NULL
AND created_at >= strftime('%s', 'now', ?)
)
SELECT
ROUND(MIN(days_to_fix), 2) AS min_days_to_fix,
ROUND(MAX(days_to_fix), 2) AS max_days_to_fix,
ROUND(AVG(days_to_fix), 2) AS avg_days_to_fix,
(SELECT COUNT(*) FROM securities WHERE state = 'FIXED' AND created_at >= strftime('%s', 'now', ?)) AS fixed,
(SELECT COUNT(*) FROM securities WHERE state = 'OPEN' AND created_at >= strftime('%s', 'now', ?)) AS open

FROM average_days_to_fix;

-- name: GetPullRequestInsightsByOrg :one
WITH
pull_request_with_org AS (
Expand Down
10 changes: 0 additions & 10 deletions internal/watchtower/interfaces.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package watchtower

import (
"context"
"watchtower/internal/database"

"watchtower/internal/github"
)

Expand All @@ -13,10 +10,3 @@ type ghClient interface {
SearchRepos(owner string, topic string, token string) (github.QuerySearch[github.Repository], error)
GetRepoDetails(owner string, repo string, token string) (github.QueryRepository, error)
}

type InsightsStore interface {
GetPullRequestInsights(ctx context.Context, arg database.GetPullRequestInsightsParams) (database.GetPullRequestInsightsRow, error)
GetSecuritiesInsights(ctx context.Context, arg database.GetSecuritiesInsightsParams) (database.GetSecuritiesInsightsRow, error)
}

var _ InsightsStore = (*database.Queries)(nil)