Skip to content

Commit 3b88146

Browse files
committed
FE code to update UseDefaultWorkflowConfig
1 parent 284933e commit 3b88146

File tree

4 files changed

+59
-16
lines changed

4 files changed

+59
-16
lines changed

app/util/remote_runner.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const DEFAULT_CONTAINER_IMAGE = "docker://gcr.io/flame-public/rbe-ubuntu24-04:la
1010

1111
export async function supportsRemoteRun(repoUrl: string): Promise<boolean> {
1212
const rsp = await rpcService.service.getLinkedGitHubRepos(new github.GetLinkedReposRequest());
13-
return rsp.repoUrls.filter((url) => url === repoUrl).length > 0;
13+
return rsp.repos.some((repo) => repo.repoUrl === repoUrl);
1414
}
1515

1616
export function triggerRemoteRun(

enterprise/app/workflows/github_app_import.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export default class GitHubAppImport extends React.Component<GitHubAppImportProp
164164
.finally(() => this.setState({ linkRequest: null, linkLoading: false }));
165165
}
166166
private getLinkedRepoUrls(): Set<string> {
167-
return new Set(this.state.linkedReposResponse?.repoUrls || []);
167+
return new Set(this.state.linkedReposResponse?.repos?.map((repo) => repo.repoUrl) || []);
168168
}
169169

170170
private onClickInstallApp() {

enterprise/app/workflows/workflows.tsx

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ class ListWorkflowsComponent extends React.Component<ListWorkflowsProps, State>
222222
</div>
223223
<div className="title">Workflows</div>
224224
</div>
225-
{Boolean(this.state.workflowsResponse?.workflow?.length || this.state.reposResponse?.repoUrls?.length) && (
225+
{Boolean(this.state.workflowsResponse?.workflow?.length || this.state.reposResponse?.repos?.length) && (
226226
<div className="buttons create-new-container">
227227
{isAdmin && <Button onClick={this.onClickCreate.bind(this)}>Link a repository</Button>}
228228
<OutlinedLinkButton href="https://docs.buildbuddy.io/docs/workflows-setup" target="_blank">
@@ -233,7 +233,7 @@ class ListWorkflowsComponent extends React.Component<ListWorkflowsProps, State>
233233
</div>
234234
</div>
235235
<div className="content">
236-
{!(this.state.workflowsResponse?.workflow?.length || this.state.reposResponse?.repoUrls?.length) && (
236+
{!(this.state.workflowsResponse?.workflow?.length || this.state.reposResponse?.repos?.length) && (
237237
<div className="no-workflows-container">
238238
<div className="no-workflows-card">
239239
<WorkflowsZeroStateAnimation />
@@ -253,17 +253,18 @@ class ListWorkflowsComponent extends React.Component<ListWorkflowsProps, State>
253253
</div>
254254
</div>
255255
)}
256-
{Boolean(this.state.workflowsResponse?.workflow?.length || this.state.reposResponse?.repoUrls?.length) && (
256+
{Boolean(this.state.workflowsResponse?.workflow?.length || this.state.reposResponse?.repos?.length) && (
257257
<div className="workflows-list">
258258
{/* Render linked repositories */}
259-
{this.state.reposResponse?.repoUrls.map((repoUrl) => (
259+
{this.state.reposResponse?.repos?.map((repo) => (
260260
<>
261261
<RepoItem
262262
user={this.props.user}
263-
repoUrl={repoUrl}
264-
onClickUnlinkItem={() => this.setState({ repoToUnlink: repoUrl })}
265-
onClickInvalidateAllItem={() => this.setState({ repoToInvalidate: repoUrl })}
266-
history={this.renderActionList(repoUrl)}
263+
repoUrl={repo.repoUrl}
264+
useDefaultWorkflowConfig={repo.useDefaultWorkflowConfig}
265+
onClickUnlinkItem={() => this.setState({ repoToUnlink: repo.repoUrl })}
266+
onClickInvalidateAllItem={() => this.setState({ repoToInvalidate: repo.repoUrl })}
267+
history={this.renderActionList(repo.repoUrl)}
267268
/>
268269
</>
269270
))}
@@ -274,6 +275,7 @@ class ListWorkflowsComponent extends React.Component<ListWorkflowsProps, State>
274275
user={this.props.user}
275276
repoUrl={workflow.repoUrl}
276277
webhookUrl={workflow.webhookUrl}
278+
useDefaultWorkflowConfig={true} /* Default for legacy workflows */
277279
onClickUnlinkItem={() => this.setState({ workflowToDelete: workflow })}
278280
onClickInvalidateAllItem={null} /* Not implemented for legacy workflows */
279281
history={null}
@@ -332,6 +334,7 @@ type RepoItemProps = {
332334
user?: User;
333335
repoUrl: string;
334336
webhookUrl?: string;
337+
useDefaultWorkflowConfig: boolean;
335338
onClickUnlinkItem: (url: string) => void;
336339
onClickInvalidateAllItem: ((url: string) => void) | null;
337340
history: React.ReactNode;
@@ -348,6 +351,7 @@ type RepoItemState = {
348351
isWorkflowRunning: boolean;
349352
runWorkflowActionStatuses: workflow.ExecuteWorkflowResponse.ActionStatus[] | null;
350353
startTime: Date | null;
354+
useDefaultWorkflowConfig: boolean;
351355
};
352356

353357
class RepoItem extends React.Component<RepoItemProps, RepoItemState> {
@@ -361,6 +365,7 @@ class RepoItem extends React.Component<RepoItemProps, RepoItemState> {
361365
isWorkflowRunning: false,
362366
runWorkflowActionStatuses: null,
363367
startTime: null,
368+
useDefaultWorkflowConfig: this.props.useDefaultWorkflowConfig,
364369
};
365370

366371
private onClickMenuButton() {
@@ -376,6 +381,31 @@ class RepoItem extends React.Component<RepoItemProps, RepoItemState> {
376381
alert_service.success("Copied webhook URL to clipboard!");
377382
}
378383

384+
private onClickUpdateDefaultConfig(updated: boolean) {
385+
const prev = this.state.useDefaultWorkflowConfig;
386+
this.setState({ useDefaultWorkflowConfig: updated });
387+
388+
const request = new github.UpdateRepoSettingsRequest({
389+
repoUrl: this.props.repoUrl,
390+
useDefaultWorkflowConfig: updated,
391+
});
392+
393+
rpcService.service
394+
.updateGitHubRepoSettings(request)
395+
.then(() => {
396+
alert_service.success(`Successfully updated repository settings`);
397+
})
398+
.catch((e) => {
399+
this.setState({ useDefaultWorkflowConfig: prev });
400+
errorService.handleError(e);
401+
});
402+
}
403+
404+
private onClickUpdateDefaultConfigMenuItem() {
405+
this.setState({ isMenuOpen: false });
406+
this.onClickUpdateDefaultConfig(!this.state.useDefaultWorkflowConfig);
407+
}
408+
379409
private onClickUnlinkMenuItem() {
380410
this.setState({ isMenuOpen: false });
381411
this.props.onClickUnlinkItem(this.props.repoUrl);
@@ -432,6 +462,10 @@ class RepoItem extends React.Component<RepoItemProps, RepoItemState> {
432462
.finally(() => this.setState({ isWorkflowRunning: false }));
433463
}
434464

465+
isDeprecatedWorkflow(): boolean {
466+
return Boolean(this.props.webhookUrl);
467+
}
468+
435469
renderWorkflowResults() {
436470
if (!this.state.runWorkflowActionStatuses) return;
437471
return this.state.runWorkflowActionStatuses.map((actionStatus) => {
@@ -482,6 +516,12 @@ class RepoItem extends React.Component<RepoItemProps, RepoItemState> {
482516
<MenuItem onClick={this.onClickInvalidateAllMenuItem.bind(this)}>Invalidate all workflow VM snapshots</MenuItem>
483517
);
484518
}
519+
if (!this.isDeprecatedWorkflow()) {
520+
const configText = this.state.useDefaultWorkflowConfig
521+
? "Disable default workflow config"
522+
: "Enable default workflow config";
523+
menuItems.push(<MenuItem onClick={this.onClickUpdateDefaultConfigMenuItem.bind(this)}>{configText}</MenuItem>);
524+
}
485525

486526
return (
487527
<div className="workflow-item container">
@@ -493,7 +533,7 @@ class RepoItem extends React.Component<RepoItemProps, RepoItemState> {
493533
<Link href={router.getWorkflowHistoryUrl(normalizeRepoURL(this.props.repoUrl))} className="repo-url">
494534
{formatURL(this.props.repoUrl)}
495535
</Link>
496-
{capabilities.config.githubAppEnabled && this.props.webhookUrl && (
536+
{capabilities.config.githubAppEnabled && this.isDeprecatedWorkflow() && (
497537
<div className="upgrade-notice">
498538
<AlertCircle className="icon orange" /> This repository uses the legacy GitHub OAuth integration.
499539
Unlink and re-link to use the new GitHub App integration.
@@ -505,7 +545,7 @@ class RepoItem extends React.Component<RepoItemProps, RepoItemState> {
505545
<div className="workflow-item-column workflow-buttons-container">
506546
<div className="workflow-item-row">
507547
{/* The Run Workflow button is only supported for workflows configured with the Github App, not legacy workflows */}
508-
{!this.props.webhookUrl && (
548+
{!this.isDeprecatedWorkflow() && (
509549
<div className="workflow-button-container">
510550
<OutlinedButton
511551
className="run-workflow-button"

proto/github.proto

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ message GitRepository {
186186
string repo_url = 1;
187187

188188
// Whether to use the default workflow config if buildbuddy.yaml is missing.
189-
// If enabled, workflows will automatically start running for a git repo when linked,
190-
// even if buildbuddy.yaml is missing from the repo. If disabled, workflows will only run
191-
// when buildbuddy.yaml is present in the repo.
189+
// If enabled, workflows will automatically start running for a git repo when
190+
// linked, even if buildbuddy.yaml is missing from the repo. If disabled,
191+
// workflows will only run when buildbuddy.yaml is present in the repo.
192192
bool use_default_workflow_config = 2;
193193
}
194194

@@ -199,7 +199,6 @@ message GetLinkedReposResponse {
199199

200200
// DEPRECATED: Use repos instead.
201201
repeated string repo_urls = 2 [deprecated = true];
202-
203202
}
204203

205204
// A request to link a repo to the authenticated org.
@@ -237,6 +236,10 @@ message UpdateRepoSettingsRequest {
237236

238237
string repo_url = 2;
239238

239+
// Whether to use the default workflow config if buildbuddy.yaml is missing.
240+
// If enabled, workflows will automatically start running for a git repo when
241+
// linked, even if buildbuddy.yaml is missing from the repo. If disabled,
242+
// workflows will only run when buildbuddy.yaml is present in the repo.
240243
bool use_default_workflow_config = 3;
241244
}
242245

0 commit comments

Comments
 (0)