Skip to content

Commit 6254927

Browse files
committed
give it a UI
1 parent e417576 commit 6254927

File tree

3 files changed

+66
-6
lines changed

3 files changed

+66
-6
lines changed

components/dashboard/src/data/prebuilds/prebuild-queries.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
*/
66

77
import { useMutation, useQuery } from "@tanstack/react-query";
8-
import { prebuildClient, stream } from "../../service/public-api";
8+
import { configurationClient, prebuildClient, stream } from "../../service/public-api";
99
import { Prebuild, PrebuildPhase_Phase } from "@gitpod/public-api/lib/gitpod/v1/prebuild_pb";
1010
import { ApplicationError, ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
11+
import { PlainMessage, toPlainMessage } from "@bufbuild/protobuf";
12+
import { GetConfigurationWebhookActivityStatusResponse } from "@gitpod/public-api/lib/gitpod/v1/configuration_pb";
1113

1214
export function usePrebuildQuery(prebuildId: string) {
1315
return useQuery<Prebuild, Error>(
@@ -75,3 +77,18 @@ export function useTriggerPrebuildMutation(configurationId?: string, gitRef?: st
7577
},
7678
});
7779
}
80+
81+
export function useWebhookActivityStatusQuery(configurationId: string) {
82+
return useQuery<PlainMessage<GetConfigurationWebhookActivityStatusResponse>, Error>(
83+
["webhookActivityStatus", configurationId],
84+
async () => {
85+
const resp = await configurationClient.getConfigurationWebhookActivityStatus({ configurationId });
86+
return toPlainMessage(resp);
87+
},
88+
{
89+
retry: false,
90+
staleTime: 1000 * 60, // 1 minute
91+
cacheTime: 1000 * 60 * 15, // 15 minutes
92+
},
93+
);
94+
}

components/dashboard/src/repositories/detail/ConfigurationDetailPrebuilds.tsx

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
import { FC, useCallback, useState } from "react";
8-
import { Configuration } from "@gitpod/public-api/lib/gitpod/v1/configuration_pb";
8+
import { Configuration, PrebuildTriggerStrategy } from "@gitpod/public-api/lib/gitpod/v1/configuration_pb";
99
import { ConfigurationSettingsField } from "./ConfigurationSettingsField";
1010
import { Heading3, Subheading } from "@podkit/typography/Headings";
1111
import { SwitchInputField } from "@podkit/switch/Switch";
@@ -15,6 +15,9 @@ import { LoadingState } from "@podkit/loading/LoadingState";
1515
import { EnablePrebuildsError } from "./prebuilds/EnablePrebuildsError";
1616
import { TextMuted } from "@podkit/typography/TextMuted";
1717
import { Link } from "react-router-dom";
18+
import { useWebhookActivityStatusQuery } from "../../data/prebuilds/prebuild-queries";
19+
import Alert from "../../components/Alert";
20+
import { useToast } from "../../components/toasts/Toasts";
1821

1922
type Props = {
2023
configuration: Configuration;
@@ -59,6 +62,10 @@ export const ConfigurationDetailPrebuilds: FC<Props> = ({ configuration }) => {
5962
<ConfigurationSettingsField>
6063
<Heading3>Prebuilds</Heading3>
6164
<Subheading className="max-w-lg">Prebuilds reduce wait time for new workspaces.</Subheading>
65+
{configuration.prebuildSettings?.enabled &&
66+
configuration.prebuildSettings.triggerStrategy !== PrebuildTriggerStrategy.ACTIVITY_BASED && (
67+
<WebhookTriggerMessage configurationId={configuration.id} />
68+
)}
6269

6370
<SwitchInputField
6471
className="mt-6"
@@ -95,3 +102,39 @@ export const ConfigurationDetailPrebuilds: FC<Props> = ({ configuration }) => {
95102
</>
96103
);
97104
};
105+
106+
export const WebhookTriggerMessage = ({ configurationId }: { configurationId: string }) => {
107+
const integrationStatus = useWebhookActivityStatusQuery(configurationId);
108+
const { toast } = useToast();
109+
110+
if (integrationStatus.isError) {
111+
toast("Failed to load webhook activity status");
112+
return null;
113+
}
114+
if (!integrationStatus?.data?.isWebhookActive) {
115+
return null;
116+
}
117+
118+
return (
119+
<Alert type="warning">
120+
<div className="flex flex-row gap-2 items-center">
121+
<span>
122+
We have gotten webhook activity from your repository recently, indicating you have webhooks
123+
installed on your repo. To optimize prebuilds usage, you might want to consider enabling Activity
124+
based prebuilds by removing our webhook. If you remove them, it might take a new commit for this
125+
message to disappear, although activity based prebuilds will start working right away.
126+
</span>
127+
<div>
128+
<a
129+
href="https://www.gitpod.io/changelog/activity-based-prebuilds"
130+
className="gp-link"
131+
target="_blank"
132+
rel="noreferrer"
133+
>
134+
Learn more about Activity based prebuilds
135+
</a>
136+
</div>
137+
</div>
138+
</Alert>
139+
);
140+
};

components/dashboard/src/repositories/detail/prebuilds/EnablePrebuildsError.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const EnablePrebuildsError: FC<Props> = ({ error, onReconnect }) => {
2222
// We need to authorize with the provider to acquire the correct scopes to install webhooks
2323
if (error instanceof ApplicationError && error.code === ErrorCodes.NOT_AUTHENTICATED) {
2424
return (
25-
<RepositoryUnauthroizedErrorMessage
25+
<RepositoryUnauthorizedErrorMessage
2626
error={error.data as RepositoryUnauthorizedError}
2727
onReconnect={onReconnect}
2828
/>
@@ -63,11 +63,11 @@ const GenericErrorMessage: FC<GenericErrorMessageProps> = ({ message }) => {
6363
);
6464
};
6565

66-
type RepositoryUnauthroizedErrorMessageProps = {
66+
type RepositoryUnauthorizedErrorMessageProps = {
6767
error: RepositoryUnauthorizedError;
6868
onReconnect: () => void;
6969
};
70-
const RepositoryUnauthroizedErrorMessage: FC<RepositoryUnauthroizedErrorMessageProps> = ({ error, onReconnect }) => {
70+
const RepositoryUnauthorizedErrorMessage: FC<RepositoryUnauthorizedErrorMessageProps> = ({ error, onReconnect }) => {
7171
const { toast } = useToast();
7272

7373
const authorizeWithProvider = useCallback(async () => {
@@ -106,7 +106,7 @@ const RepositoryUnauthroizedErrorMessage: FC<RepositoryUnauthroizedErrorMessageP
106106
</span>
107107
) : (
108108
<span>
109-
Unable to enable prebuilds. This could be because you don’t have admin/write premissions for
109+
Unable to enable prebuilds. This could be because you don’t have admin/write permissions for
110110
this repo or it could be an invalid token. Please try to reconnect. If the problem persists, you
111111
can contact support.
112112
</span>

0 commit comments

Comments
 (0)