Skip to content

Commit cfe795c

Browse files
Prebuild trigger checks (#20228)
* Add `GetConfigurationWebhookActivityStatus` to proto * codegen * `GetConfigurationWebhookActivityStatus` impl * give it a UI * Revert trigger strategy on webhook event * debug: enable webhooks again * fix UI * maybe fix build? * Automatically convert to activity-based prebuilds * 🤷‍♂️ * don't limit to a week when converting to activity-based * Change copy Co-authored-by: Gero Posmyk-Leinemann <[email protected]> * Less cyclic deps * removing warning and add informative trigger strategy field * fix sizing of prebuild trigger strategy info * Revert "debug: enable webhooks again" This reverts commit 1c47067. --------- Co-authored-by: Gero Posmyk-Leinemann <[email protected]>
1 parent 5acdabc commit cfe795c

23 files changed

+2874
-154
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: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,17 @@ export const ConfigurationDetailPrebuilds: FC<Props> = ({ configuration }) => {
5858
<>
5959
<ConfigurationSettingsField>
6060
<Heading3>Prebuilds</Heading3>
61-
<Subheading className="max-w-lg">Prebuilds reduce wait time for new workspaces.</Subheading>
61+
<Subheading className="max-w-lg">
62+
Prebuilds reduce wait time for new workspaces.{" "}
63+
<a
64+
href="https://www.gitpod.io/docs/configure/repositories/prebuilds"
65+
target="_blank"
66+
rel="noreferrer"
67+
className="gp-link"
68+
>
69+
Learn more
70+
</a>
71+
</Subheading>
6272

6373
<SwitchInputField
6474
className="mt-6"

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>

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import { FC, FormEvent, useCallback, useMemo, useState } from "react";
1313
import { ConfigurationSettingsField } from "../ConfigurationSettingsField";
1414
import { Heading3, Subheading } from "@podkit/typography/Headings";
15+
import { Text } from "@podkit/typography/Text";
1516
import { InputField } from "../../../components/forms/InputField";
1617
import { PartialConfiguration, useConfigurationMutation } from "../../../data/configurations/configuration-queries";
1718
import { useToast } from "../../../components/toasts/Toasts";
@@ -28,6 +29,8 @@ import { trackEvent } from "../../../Analytics";
2829
import dayjs from "dayjs";
2930
import { SwitchInputField } from "@podkit/switch/Switch";
3031
import { useFeatureFlag } from "../../../data/featureflag-query";
32+
import { TextMuted } from "@podkit/typography/TextMuted";
33+
import { InfoIcon } from "lucide-react";
3134

3235
const DEFAULT_PREBUILD_COMMIT_INTERVAL = 20;
3336

@@ -224,6 +227,22 @@ export const PrebuildSettingsForm: FC<Props> = ({ configuration }) => {
224227
</InputField>
225228
)}
226229

230+
<div className="mt-4">
231+
<Text className="font-semibold text-md text-pk-content-secondary">Prebuild trigger strategy</Text>
232+
<TextMuted className="text-sm mt-1 flex flex-row gap-1 items-center">
233+
{configuration.prebuildSettings?.triggerStrategy === PrebuildTriggerStrategy.ACTIVITY_BASED
234+
? "Activity-based"
235+
: "Webhook-based"}
236+
<a
237+
href="https://www.gitpod.io/docs/configure/repositories/prebuilds#triggers"
238+
target="_blank"
239+
rel="noreferrer"
240+
>
241+
<InfoIcon size={14} />
242+
</a>
243+
</TextMuted>
244+
</div>
245+
227246
<Heading3 className="mt-8">Machine type</Heading3>
228247
<Subheading>Choose the workspace machine type for your prebuilds.</Subheading>
229248

components/public-api/gitpod/v1/configuration.proto

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ service ConfigurationService {
6969

7070
// Deletes a configuration.
7171
rpc DeleteConfiguration(DeleteConfigurationRequest) returns (DeleteConfigurationResponse) {}
72+
73+
// GetConfigurationWebhookActivityStatus returns the observed status of installed prebuild webhooks on the configuration
74+
rpc GetConfigurationWebhookActivityStatus(GetConfigurationWebhookActivityStatusRequest) returns (GetConfigurationWebhookActivityStatusResponse) {}
7275
}
7376

7477
message CreateConfigurationRequest {
@@ -147,3 +150,20 @@ message DeleteConfigurationRequest {
147150
}
148151

149152
message DeleteConfigurationResponse {}
153+
154+
message GetConfigurationWebhookActivityStatusRequest {
155+
string configuration_id = 1;
156+
}
157+
158+
message GetConfigurationWebhookActivityStatusResponse {
159+
message WebhookEvent {
160+
string commit = 1;
161+
google.protobuf.Timestamp creation_time = 2;
162+
}
163+
164+
// is_webhook_active determines whether the webhook is active or not for the configuration.
165+
bool is_webhook_active = 1;
166+
167+
// latest_webhook_event is the latest event that was observed by the webhook. Only set if is_webhook_active is true.
168+
WebhookEvent latest_webhook_event = 2;
169+
}

0 commit comments

Comments
 (0)