Skip to content

Commit

Permalink
evaluate prebuildDefaultBranchOnly in PrebuildManager
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexTugarev committed Sep 14, 2023
1 parent 2209661 commit 632d1bd
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion components/server/src/prebuilds/bitbucket-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class BitbucketApp {
commit: context.revision,
});
const config = await this.prebuildManager.fetchConfig({ span }, user, context);
if (!this.prebuildManager.shouldPrebuild({ config, project })) {
if (!this.prebuildManager.shouldPrebuild({ config, project, context })) {
log.info("Bitbucket push event: No prebuild.", { config, context });
await this.webhookEvents.updateEvent(event.id, {
prebuildStatus: "ignored_unconfigured",
Expand Down
2 changes: 1 addition & 1 deletion components/server/src/prebuilds/bitbucket-server-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class BitbucketServerApp {
commit: context.revision,
});
const config = await this.prebuildManager.fetchConfig({ span }, user, context);
if (!this.prebuildManager.shouldPrebuild({ config, project })) {
if (!this.prebuildManager.shouldPrebuild({ config, project, context })) {
log.info("Bitbucket Server push event: No prebuild.", { config, context });
await this.webhookEvents.updateEvent(event.id, {
prebuildStatus: "ignored_unconfigured",
Expand Down
4 changes: 2 additions & 2 deletions components/server/src/prebuilds/github-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export class GithubApp {
});

const runPrebuild =
this.prebuildManager.shouldPrebuild({ config, project }) &&
this.prebuildManager.shouldPrebuild({ config, project, context }) &&
this.appRules.shouldRunPrebuild(config, branch == repo.default_branch, false, false);
if (!runPrebuild) {
const reason = `Not running prebuild, the user did not enable it for this context or did not configure prebuild task(s)`;
Expand Down Expand Up @@ -538,7 +538,7 @@ export class GithubApp {

const isFork = pr.head.repo.id !== pr.base.repo.id;
const runPrebuild =
this.prebuildManager.shouldPrebuild({ config, project }) &&
this.prebuildManager.shouldPrebuild({ config, project, context }) &&
this.appRules.shouldRunPrebuild(config, false, true, isFork);
if (runPrebuild) {
const commitInfo = await this.getCommitInfo(user, ctx.payload.repository.html_url, pr.head.sha);
Expand Down
2 changes: 1 addition & 1 deletion components/server/src/prebuilds/github-enterprise-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export class GitHubEnterpriseApp {

const config = await this.prebuildManager.fetchConfig({ span }, user, context);
if (
!this.prebuildManager.shouldPrebuild({ config, project }) ||
!this.prebuildManager.shouldPrebuild({ config, project, context }) ||
!this.appRules.shouldRunPrebuild(config, context.ref === context.repository.defaultBranch, false, false)
) {
log.info("GitHub Enterprise push event: No prebuild.", { config, context });
Expand Down
2 changes: 1 addition & 1 deletion components/server/src/prebuilds/gitlab-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class GitLabApp {
});

const config = await this.prebuildManager.fetchConfig({ span }, user, context);
if (!this.prebuildManager.shouldPrebuild({ config, project })) {
if (!this.prebuildManager.shouldPrebuild({ config, project, context })) {
log.info("GitLab push event: No prebuild.", { config, context });
await this.webhookEvents.updateEvent(event.id, {
prebuildStatus: "ignored_unconfigured",
Expand Down
20 changes: 17 additions & 3 deletions components/server/src/prebuilds/prebuild-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ export class PrebuildManager {
}
}

shouldPrebuild(params: { config: WorkspaceConfig; project: Project }): boolean {
const { config, project } = params;
shouldPrebuild(params: { config: WorkspaceConfig; project: Project; context: CommitContext }): boolean {
const { config, project, context } = params;
if (!config || !config._origin || config._origin !== "repo") {
// we demand an explicit gitpod config
return false;
Expand All @@ -353,7 +353,21 @@ export class PrebuildManager {
return false;
}

return Project.isPrebuildsEnabled(project);
const isPrebuildsEnabled = Project.isPrebuildsEnabled(project);
if (!isPrebuildsEnabled) {
return false;
}

if (!project.settings?.prebuildDefaultBranchOnly) {
return true;
}

const defaultBranch = context.repository.defaultBranch;
if (!defaultBranch) {
log.debug("CommitContext is missing the default branch.", { context });
return true;
}
return context.ref === defaultBranch;
}

protected shouldPrebuildIncrementally(cloneUrl: string, project: Project): boolean {
Expand Down

0 comments on commit 632d1bd

Please sign in to comment.