Skip to content

feat: defaultBranch in github app #15934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
87 changes: 21 additions & 66 deletions components/gitpod-protocol/data/gitpod-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
"description": "List of exposed ports.",
"items": {
"type": "object",
"required": [
"port"
],
"required": ["port"],
"properties": {
"port": {
"type": ["number", "string"],
Expand All @@ -20,20 +18,12 @@
},
"onOpen": {
"type": "string",
"enum": [
"open-browser",
"open-preview",
"notify",
"ignore"
],
"enum": ["open-browser", "open-preview", "notify", "ignore"],
"description": "What to do when a service on this port was detected. 'notify' (default) will show a notification asking the user what to do. 'open-browser' will open a new browser tab. 'open-preview' will open in the preview on the right of the IDE. 'ignore' will do nothing."
},
"visibility": {
"type": "string",
"enum": [
"private",
"public"
],
"enum": ["private", "public"],
"default": "private",
"description": "Whether the port visibility should be private or public. 'private' (default) will only allow users with workspace access to access the port. 'public' will allow everyone with the port URL to access the port."
},
Expand All @@ -43,11 +33,7 @@
},
"protocol": {
"type": "string",
"enum": [
"http",
"TCP",
"UDP"
],
"enum": ["http", "TCP", "UDP"],
"deprecationMessage": "The 'protocol' property is deprecated.",
"description": "The protocol to be used. (deprecated)"
},
Expand Down Expand Up @@ -92,38 +78,23 @@
},
"openIn": {
"type": "string",
"enum": [
"bottom",
"main",
"left",
"right"
],
"enum": ["bottom", "main", "left", "right"],
"description": "The panel/area where to open the terminal. Default is 'bottom' panel."
},
"openMode": {
"type": "string",
"enum": [
"split-left",
"split-right",
"tab-before",
"tab-after"
],
"enum": ["split-left", "split-right", "tab-before", "tab-after"],
"description": "The opening mode. Default is 'tab-after'."
}
},
"additionalProperties": false
}
},
"image": {
"type": [
"object",
"string"
],
"type": ["object", "string"],
"description": "The Docker image to run your workspace in.",
"default": "gitpod/workspace-full",
"required": [
"file"
],
"required": ["file"],
"properties": {
"file": {
"type": "string",
Expand All @@ -141,9 +112,7 @@
"description": "List of additional repositories that are part of this project.",
"items": {
"type": "object",
"required": [
"url"
],
"required": ["url"],
"properties": {
"url": {
"type": ["string"],
Expand All @@ -170,9 +139,7 @@
"description": "Path to where the IDE's workspace should be opened. Supports vscode's `*.code-workspace` files."
},
"gitConfig": {
"type": [
"object"
],
"type": ["object"],
"description": "Git config values should be provided in pairs. E.g. `core.autocrlf: input`. See https://git-scm.com/docs/git-config#_values.",
"additionalProperties": {
"type": "string"
Expand All @@ -183,15 +150,17 @@
"description": "Configures Gitpod's GitHub app",
"properties": {
"prebuilds": {
"type": [
"boolean",
"object"
],
"type": ["boolean", "object"],
"description": "Set to true to enable workspace prebuilds, false to disable them. Defaults to true.",
"properties": {
"master": {
"type": "boolean",
"description": "Enable prebuilds for the default branch (typically master). Defaults to true."
"description": "Enable prebuilds for the default branch (typically master). Defaults to true.",
"deprecationMessage": "Deprecated. Please use `defaultBranch` instead. See https://www.gitpod.io/docs/configure/projects/prebuilds#github-specific-configuration."
},
"defaultBranch": {
"type": "boolean",
"description": "Enable prebuilds for the default branch (typically main). Defaults to true."
},
"branches": {
"type": "boolean",
Expand All @@ -210,22 +179,12 @@
"description": "Add a Review in Gitpod badge to pull requests. Defaults to true."
},
"addCheck": {
"type": [
"boolean",
"string"
],
"enum": [
true,
false,
"prevent-merge-on-error"
],
"type": ["boolean", "string"],
"enum": [true, false, "prevent-merge-on-error"],
"description": "Add a commit check to pull requests. Set to 'fail-on-error' if you want broken prebuilds to block merging. Defaults to true."
},
"addLabel": {
"type": [
"boolean",
"string"
],
"type": ["boolean", "string"],
"description": "Add a label to a PR when it's prebuilt. Set to true to use the default label (prebuilt-in-gitpod) or set to a string to use a different label name. This is a beta feature and may be unreliable. Defaults to false."
}
}
Expand Down Expand Up @@ -339,11 +298,7 @@
"properties": {
"version": {
"type": "string",
"enum": [
"stable",
"latest",
"both"
],
"enum": ["stable", "latest", "both"],
"description": "Whether only stable, latest or both versions should be warmed up. Default is stable only."
}
}
Expand Down
3 changes: 3 additions & 0 deletions components/gitpod-protocol/go/gitpod-config-types.go

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

3 changes: 2 additions & 1 deletion components/gitpod-protocol/go/gitpod-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1926,7 +1926,8 @@ type GithubAppPrebuildConfig struct {
AddComment bool `json:"addComment,omitempty"`
AddLabel interface{} `json:"addLabel,omitempty"`
Branches bool `json:"branches,omitempty"`
Master bool `json:"master,omitempty"`
Master bool `json:"master,omitempty"` // Deprecated: use DefaultBranch instead
DefaultBranch bool `json:"defaultBranch,omitempty"`
PullRequests bool `json:"pullRequests,omitempty"`
PullRequestsFromForks bool `json:"pullRequestsFromForks,omitempty"`
}
Expand Down
3 changes: 2 additions & 1 deletion components/gitpod-protocol/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,8 @@ export interface GithubAppConfig {
prebuilds?: GithubAppPrebuildConfig;
}
export interface GithubAppPrebuildConfig {
master?: boolean;
master?: boolean; // Deprecated: use defaultBranch instead
defaultBranch?: boolean;
branches?: boolean;
pullRequests?: boolean;
pullRequestsFromForks?: boolean;
Expand Down
5 changes: 3 additions & 2 deletions components/server/ee/src/prebuilds/github-app-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const defaultConfig: GithubAppConfig = {
addComment: false,
addLabel: false,
branches: false,
master: true,
master: false, // Deprecated: use defaultBranch instead
defaultBranch: true,
pullRequests: true,
pullRequestsFromForks: false,
},
Expand Down Expand Up @@ -52,7 +53,7 @@ export class GithubAppRules {
return !!prebuildCfg.pullRequests;
}
} else if (isDefaultBranch) {
return !!prebuildCfg.master;
return /* !!prebuildCfg.master || */ !!prebuildCfg.defaultBranch;
} else {
return !!prebuildCfg.branches;
}
Expand Down
17 changes: 13 additions & 4 deletions components/server/ee/src/prebuilds/github-app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ describe("GitHub app", () => {
tasks: [{ init: "ls" }],
};

// chai.assert.equal(
// rules.shouldRunPrebuild(cfg, true, false, false),
// expectation[0],
// `master prebuild check failed with ${JSON.stringify(pbcfg)}`,
// );
chai.assert.equal(
rules.shouldRunPrebuild(cfg, true, false, false),
expectation[0],
`master prebuild check failed with ${JSON.stringify(pbcfg)}`,
`defaultBranch prebuild check failed with ${JSON.stringify(pbcfg)}`,
);
chai.assert.equal(
rules.shouldRunPrebuild(cfg, false, true, false),
Expand All @@ -60,10 +65,14 @@ describe("GitHub app", () => {
};

checkConfig({ branches: true }, [true, true, true, false]);
checkConfig({ master: false }, [false, true, false, false]);
checkConfig({ master: false, branches: true }, [false, true, true, false]);
// checkConfig({ master: false }, [false, true, false, false]);
// checkConfig({ master: false, branches: true }, [false, true, true, false]);
checkConfig({ defaultBranch: false }, [false, true, false, false]);
// checkConfig({ master: false, defaultBranch: false }, [false, true, false, false]);
checkConfig({ defaultBranch: false, branches: true }, [false, true, true, false]);
checkConfig({ pullRequests: false }, [true, false, false, false]);
checkConfig({ pullRequests: false, master: false }, [false, false, false, false]);
// checkConfig({ pullRequests: false, master: false }, [false, false, false, false]);
checkConfig({ pullRequests: false, defaultBranch: false }, [false, false, false, false]);
checkConfig({ pullRequests: true, pullRequestsFromForks: true }, [true, true, false, true]);
checkConfig({ pullRequestsFromForks: true }, [true, true, false, true]);
});
Expand Down