Skip to content

Commit 243269a

Browse files
feat: defaultBranch in github app
Signed-off-by: Siddhant Khare <siddhant@gitpod.io>
1 parent b984390 commit 243269a

File tree

6 files changed

+44
-74
lines changed

6 files changed

+44
-74
lines changed

components/gitpod-protocol/data/gitpod-schema.json

Lines changed: 21 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
"description": "List of exposed ports.",
1010
"items": {
1111
"type": "object",
12-
"required": [
13-
"port"
14-
],
12+
"required": ["port"],
1513
"properties": {
1614
"port": {
1715
"type": ["number", "string"],
@@ -20,20 +18,12 @@
2018
},
2119
"onOpen": {
2220
"type": "string",
23-
"enum": [
24-
"open-browser",
25-
"open-preview",
26-
"notify",
27-
"ignore"
28-
],
21+
"enum": ["open-browser", "open-preview", "notify", "ignore"],
2922
"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."
3023
},
3124
"visibility": {
3225
"type": "string",
33-
"enum": [
34-
"private",
35-
"public"
36-
],
26+
"enum": ["private", "public"],
3727
"default": "private",
3828
"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."
3929
},
@@ -43,11 +33,7 @@
4333
},
4434
"protocol": {
4535
"type": "string",
46-
"enum": [
47-
"http",
48-
"TCP",
49-
"UDP"
50-
],
36+
"enum": ["http", "TCP", "UDP"],
5137
"deprecationMessage": "The 'protocol' property is deprecated.",
5238
"description": "The protocol to be used. (deprecated)"
5339
},
@@ -92,38 +78,23 @@
9278
},
9379
"openIn": {
9480
"type": "string",
95-
"enum": [
96-
"bottom",
97-
"main",
98-
"left",
99-
"right"
100-
],
81+
"enum": ["bottom", "main", "left", "right"],
10182
"description": "The panel/area where to open the terminal. Default is 'bottom' panel."
10283
},
10384
"openMode": {
10485
"type": "string",
105-
"enum": [
106-
"split-left",
107-
"split-right",
108-
"tab-before",
109-
"tab-after"
110-
],
86+
"enum": ["split-left", "split-right", "tab-before", "tab-after"],
11187
"description": "The opening mode. Default is 'tab-after'."
11288
}
11389
},
11490
"additionalProperties": false
11591
}
11692
},
11793
"image": {
118-
"type": [
119-
"object",
120-
"string"
121-
],
94+
"type": ["object", "string"],
12295
"description": "The Docker image to run your workspace in.",
12396
"default": "gitpod/workspace-full",
124-
"required": [
125-
"file"
126-
],
97+
"required": ["file"],
12798
"properties": {
12899
"file": {
129100
"type": "string",
@@ -141,9 +112,7 @@
141112
"description": "List of additional repositories that are part of this project.",
142113
"items": {
143114
"type": "object",
144-
"required": [
145-
"url"
146-
],
115+
"required": ["url"],
147116
"properties": {
148117
"url": {
149118
"type": ["string"],
@@ -170,9 +139,7 @@
170139
"description": "Path to where the IDE's workspace should be opened. Supports vscode's `*.code-workspace` files."
171140
},
172141
"gitConfig": {
173-
"type": [
174-
"object"
175-
],
142+
"type": ["object"],
176143
"description": "Git config values should be provided in pairs. E.g. `core.autocrlf: input`. See https://git-scm.com/docs/git-config#_values.",
177144
"additionalProperties": {
178145
"type": "string"
@@ -183,15 +150,17 @@
183150
"description": "Configures Gitpod's GitHub app",
184151
"properties": {
185152
"prebuilds": {
186-
"type": [
187-
"boolean",
188-
"object"
189-
],
153+
"type": ["boolean", "object"],
190154
"description": "Set to true to enable workspace prebuilds, false to disable them. Defaults to true.",
191155
"properties": {
192156
"master": {
193157
"type": "boolean",
194-
"description": "Enable prebuilds for the default branch (typically master). Defaults to true."
158+
"description": "Enable prebuilds for the default branch (typically master). Defaults to true.",
159+
"deprecationMessage": "Deprecated. Please use `defaultBranch` instead. See https://www.gitpod.io/docs/configure/projects/prebuilds#github-specific-configuration."
160+
},
161+
"defaultBranch": {
162+
"type": "boolean",
163+
"description": "Enable prebuilds for the default branch (typically main). Defaults to true."
195164
},
196165
"branches": {
197166
"type": "boolean",
@@ -210,22 +179,12 @@
210179
"description": "Add a Review in Gitpod badge to pull requests. Defaults to true."
211180
},
212181
"addCheck": {
213-
"type": [
214-
"boolean",
215-
"string"
216-
],
217-
"enum": [
218-
true,
219-
false,
220-
"prevent-merge-on-error"
221-
],
182+
"type": ["boolean", "string"],
183+
"enum": [true, false, "prevent-merge-on-error"],
222184
"description": "Add a commit check to pull requests. Set to 'fail-on-error' if you want broken prebuilds to block merging. Defaults to true."
223185
},
224186
"addLabel": {
225-
"type": [
226-
"boolean",
227-
"string"
228-
],
187+
"type": ["boolean", "string"],
229188
"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."
230189
}
231190
}
@@ -339,11 +298,7 @@
339298
"properties": {
340299
"version": {
341300
"type": "string",
342-
"enum": [
343-
"stable",
344-
"latest",
345-
"both"
346-
],
301+
"enum": ["stable", "latest", "both"],
347302
"description": "Whether only stable, latest or both versions should be warmed up. Default is stable only."
348303
}
349304
}

components/gitpod-protocol/go/gitpod-config-types.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/gitpod-protocol/go/gitpod-service.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1926,7 +1926,8 @@ type GithubAppPrebuildConfig struct {
19261926
AddComment bool `json:"addComment,omitempty"`
19271927
AddLabel interface{} `json:"addLabel,omitempty"`
19281928
Branches bool `json:"branches,omitempty"`
1929-
Master bool `json:"master,omitempty"`
1929+
Master bool `json:"master,omitempty"` // Deprecated: use DefaultBranch instead
1930+
DefaultBranch bool `json:"defaultBranch,omitempty"`
19301931
PullRequests bool `json:"pullRequests,omitempty"`
19311932
PullRequestsFromForks bool `json:"pullRequestsFromForks,omitempty"`
19321933
}

components/gitpod-protocol/src/protocol.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,8 @@ export interface GithubAppConfig {
849849
prebuilds?: GithubAppPrebuildConfig;
850850
}
851851
export interface GithubAppPrebuildConfig {
852-
master?: boolean;
852+
master?: boolean; // Deprecated: use defaultBranch instead
853+
defaultBranch?: boolean;
853854
branches?: boolean;
854855
pullRequests?: boolean;
855856
pullRequestsFromForks?: boolean;

components/server/ee/src/prebuilds/github-app-rules.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ const defaultConfig: GithubAppConfig = {
1616
addComment: false,
1717
addLabel: false,
1818
branches: false,
19-
master: true,
19+
master: false, // Deprecated: use defaultBranch instead
20+
defaultBranch: true,
2021
pullRequests: true,
2122
pullRequestsFromForks: false,
2223
},
@@ -52,7 +53,7 @@ export class GithubAppRules {
5253
return !!prebuildCfg.pullRequests;
5354
}
5455
} else if (isDefaultBranch) {
55-
return !!prebuildCfg.master;
56+
return /* !!prebuildCfg.master || */ !!prebuildCfg.defaultBranch;
5657
} else {
5758
return !!prebuildCfg.branches;
5859
}

components/server/ee/src/prebuilds/github-app.spec.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,15 @@ describe("GitHub app", () => {
3737
tasks: [{ init: "ls" }],
3838
};
3939

40+
// chai.assert.equal(
41+
// rules.shouldRunPrebuild(cfg, true, false, false),
42+
// expectation[0],
43+
// `master prebuild check failed with ${JSON.stringify(pbcfg)}`,
44+
// );
4045
chai.assert.equal(
4146
rules.shouldRunPrebuild(cfg, true, false, false),
4247
expectation[0],
43-
`master prebuild check failed with ${JSON.stringify(pbcfg)}`,
48+
`defaultBranch prebuild check failed with ${JSON.stringify(pbcfg)}`,
4449
);
4550
chai.assert.equal(
4651
rules.shouldRunPrebuild(cfg, false, true, false),
@@ -60,10 +65,14 @@ describe("GitHub app", () => {
6065
};
6166

6267
checkConfig({ branches: true }, [true, true, true, false]);
63-
checkConfig({ master: false }, [false, true, false, false]);
64-
checkConfig({ master: false, branches: true }, [false, true, true, false]);
68+
// checkConfig({ master: false }, [false, true, false, false]);
69+
// checkConfig({ master: false, branches: true }, [false, true, true, false]);
70+
checkConfig({ defaultBranch: false }, [false, true, false, false]);
71+
// checkConfig({ master: false, defaultBranch: false }, [false, true, false, false]);
72+
checkConfig({ defaultBranch: false, branches: true }, [false, true, true, false]);
6573
checkConfig({ pullRequests: false }, [true, false, false, false]);
66-
checkConfig({ pullRequests: false, master: false }, [false, false, false, false]);
74+
// checkConfig({ pullRequests: false, master: false }, [false, false, false, false]);
75+
checkConfig({ pullRequests: false, defaultBranch: false }, [false, false, false, false]);
6776
checkConfig({ pullRequests: true, pullRequestsFromForks: true }, [true, true, false, true]);
6877
checkConfig({ pullRequestsFromForks: true }, [true, true, false, true]);
6978
});

0 commit comments

Comments
 (0)