Skip to content

Commit 955387e

Browse files
myftijaTrigger.dev RepoOps
authored andcommitted
feat(webapp): add ignored branches to the Git settings
Add "Ignored branches" to the Git settings on the Integrations page: globs matched against the whole branch name, one per line (for example `dependabot/**`). A pull request from a matching branch doesn't get a preview deployment. It's empty by default and shares the ignored-path limits (`GITHUB_IGNORED_PATHS_LIMIT`, `GITHUB_IGNORED_PATH_MAX_LENGTH`). Mono-RevId: a72664af0313746d57f96b3ac9bff2427cb48451
1 parent 880d46b commit 955387e

13 files changed

Lines changed: 418 additions & 129 deletions
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
area: webapp
3+
type: feature
4+
---
5+
6+
Add "Ignored branches" to the Git settings: pull requests from branches matching these patterns no longer get a preview deployment. Patterns are globs matched against the whole branch name, like `dependabot/**`.

‎apps/webapp/app/components/deployments/GitHubDeploymentOnboarding.test.ts‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ it("wires the real connected-repository form into the existing save endpoint", (
172172
connectedGitHubRepo: {
173173
branchTracking: { prod: { branch: "main" }, staging: { branch: "staging" } },
174174
previewDeploymentsEnabled: true,
175-
buildFilters: { ignorePaths: ["docs/**"] },
175+
buildFilters: { ignorePaths: ["docs/**"], ignoreBranches: ["dependabot/**"] },
176176
createdAt: new Date("2026-09-15T00:00:00Z"),
177177
repository: {
178178
id: "repo",
@@ -201,6 +201,7 @@ it("wires the real connected-repository form into the existing save endpoint", (
201201
expect(html).toContain('value="update-git-settings"');
202202
expect(html).toContain('value="/orgs/org/projects/project/env/prod/deployments"');
203203
expect(html).not.toContain('name="ignorePaths"');
204+
expect(html).not.toContain('name="ignoreBranches"');
204205
expect(html).not.toContain("Disconnect");
205206
expect(html).not.toContain("Upgrade");
206207
expect((html.match(/ disabled=""/g) ?? []).length).toBeGreaterThanOrEqual(autosave ? 3 : 4);
@@ -264,7 +265,7 @@ function settingsForm(
264265
environmentSlug: "prod",
265266
billingPath: "/billing",
266267
redirectUrl: "/orgs/org/projects/project/env/prod/deployments",
267-
ignorePathLimits: { maxPaths: 100, maxLength: 256 },
268+
ignorePatternLimits: { maxPatterns: 100, maxLength: 256 },
268269
...props,
269270
})
270271
);
@@ -290,7 +291,7 @@ it("keeps the legacy connected-repository form on its original layout and explic
290291
});
291292

292293
it("lists stored ignored paths after the branch fields and submits them one per line", () => {
293-
const html = settingsForm({}, { ignorePaths: ["docs/**", "*.md"] });
294+
const html = settingsForm({}, { ignorePaths: ["docs/**", "*.md"], ignoreBranches: [] });
294295
expect(html).toContain('type="hidden" name="ignorePaths" value="docs/**\n*.md"');
295296
expect(html.indexOf('name="ignorePaths"')).toBeGreaterThan(
296297
html.indexOf('name="previewDeploymentsEnabled"')
@@ -299,6 +300,17 @@ it("lists stored ignored paths after the branch fields and submits them one per
299300
expect(settingsForm()).toContain('type="hidden" name="ignorePaths" value=""');
300301
});
301302

303+
it("lists stored ignored branches above the ignored paths and submits them one per line", () => {
304+
// Catches: the settings form not submitting the branches field, so saving can't change it.
305+
const html = settingsForm(
306+
{},
307+
{ ignorePaths: [], ignoreBranches: ["noPreview*", "noPreview/**"] }
308+
);
309+
expect(html).toContain('type="hidden" name="ignoreBranches" value="noPreview*\nnoPreview/**"');
310+
expect(html.indexOf('name="ignoreBranches"')).toBeLessThan(html.indexOf('name="ignorePaths"'));
311+
expect(settingsForm()).toContain('type="hidden" name="ignoreBranches" value=""');
312+
});
313+
302314
it("says ignored paths don't apply only while a Vercel integration is connected", () => {
303315
const notice = "apply while the Vercel integration is connected";
304316
expect(settingsForm({ vercelIntegrationConnected: true })).toContain(notice);

apps/webapp/app/components/deployments/IgnoredPathsEditor.dom.test.ts renamed to apps/webapp/app/components/deployments/IgnoredPatternsEditor.dom.test.ts

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { act } from "react-dom/test-utils";
77
import { afterEach, describe, expect, it, vi } from "vitest";
88
import { OperatingSystemContextProvider } from "../primitives/OperatingSystemProvider";
99
import { ShortcutsProvider } from "../primitives/ShortcutsProvider";
10-
import { IgnoredPathsEditor } from "./IgnoredPathsEditor";
10+
import type { IgnoreKind, IgnorePatternLimits } from "~/v3/github";
11+
import { IgnoredPatternsEditor } from "./IgnoredPatternsEditor";
1112

1213
globalThis.ResizeObserver ??= class {
1314
observe() {}
@@ -18,7 +19,13 @@ globalThis.ResizeObserver ??= class {
1819
let container: HTMLDivElement;
1920
let root: Root;
2021

21-
function mount(defaultPatterns: string[] = [], limits = { maxPaths: 100, maxLength: 256 }) {
22+
function mount(
23+
defaultPatterns: string[] = [],
24+
{
25+
kind = "paths",
26+
limits = { maxPatterns: 100, maxLength: 256 },
27+
}: { kind?: IgnoreKind; limits?: IgnorePatternLimits } = {}
28+
) {
2229
const onChange = vi.fn();
2330
container = document.createElement("div");
2431
document.body.append(container);
@@ -31,8 +38,9 @@ function mount(defaultPatterns: string[] = [], limits = { maxPaths: 100, maxLeng
3138
createElement(
3239
ShortcutsProvider,
3340
null,
34-
createElement(IgnoredPathsEditor, {
35-
name: "ignorePaths",
41+
createElement(IgnoredPatternsEditor, {
42+
kind,
43+
name: "patterns",
3644
defaultPatterns,
3745
limits,
3846
onChange,
@@ -61,15 +69,15 @@ function edit(text: string) {
6169
}
6270

6371
function submitted() {
64-
return container.querySelector<HTMLInputElement>('input[name="ignorePaths"]')!.value;
72+
return container.querySelector<HTMLInputElement>('input[name="patterns"]')!.value;
6573
}
6674

6775
function button(label: string) {
6876
return container.querySelector<HTMLButtonElement>(`button[aria-label="${label}"]`);
6977
}
7078

7179
function tester() {
72-
return container.querySelector<HTMLInputElement>('input[aria-label="Path to test"]');
80+
return container.querySelector<HTMLInputElement>('input[aria-label$=" to test"]');
7381
}
7482

7583
function type(value: string) {
@@ -98,7 +106,7 @@ function errors() {
98106
return [...container.querySelectorAll("li")].map((item) => item.textContent);
99107
}
100108

101-
describe("IgnoredPathsEditor", () => {
109+
describe("IgnoredPatternsEditor", () => {
102110
it("folds more than three saved paths and expands into the editor", () => {
103111
const paths = "docs/**\napps/website/**\n**/*.md\n.github/**\nexamples/**";
104112
mount(paths.split("\n"));
@@ -146,7 +154,7 @@ describe("IgnoredPathsEditor", () => {
146154
});
147155

148156
it("applies the configured path count and length limits", () => {
149-
const onChange = mount(["docs/**", "*.md"], { maxPaths: 2, maxLength: 10 });
157+
const onChange = mount(["docs/**", "*.md"], { limits: { maxPatterns: 2, maxLength: 10 } });
150158

151159
edit("docs/**\n*.md\nexamples/**/*.ts");
152160

@@ -158,6 +166,7 @@ describe("IgnoredPathsEditor", () => {
158166
mount(["docs/**", "apps/website/**", "**/*.md", ".github/**"]);
159167
act(() => button("Test a path")!.click());
160168
expect(document.activeElement).toBe(tester());
169+
expect(tester()!.getAttribute("aria-label")).toBe("Path to test");
161170
expect(button("Expand")).not.toBeNull();
162171

163172
type("apps/website/src/index.tsx");
@@ -202,4 +211,25 @@ describe("IgnoredPathsEditor", () => {
202211
edit("!src/**");
203212
expect(button("Close the path tester")).not.toBeNull();
204213
});
214+
215+
describe("for branches", () => {
216+
it("matches the whole branch name against each pattern", () => {
217+
// Catches: the tester matching part of a branch name, so it disagrees with the skip on GitHub.
218+
mount(["noPreview*", "noPreview/**", "dependabot/**"], { kind: "branches" });
219+
act(() => button("Test a branch")!.click());
220+
expect(tester()!.getAttribute("aria-label")).toBe("Branch to test");
221+
222+
type("noPreview-login");
223+
expect(verdict()).toEqual(["Ignored", "by noPreview*"]);
224+
225+
type("noPreview/login/form");
226+
expect(verdict()).toEqual(["Ignored", "by noPreview/**"]);
227+
228+
type("feature/noPreview-login");
229+
expect(verdict()).toEqual(["Deploys", "no branch matches"]);
230+
231+
press("Escape");
232+
expect(document.activeElement).toBe(button("Test a branch"));
233+
});
234+
});
205235
});

apps/webapp/app/components/deployments/IgnoredPathsEditor.tsx renamed to apps/webapp/app/components/deployments/IgnoredPatternsEditor.tsx

Lines changed: 62 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ import {
2323
import { TextEditor } from "~/components/code/TextEditor";
2424
import { Button } from "~/components/primitives/Buttons";
2525
import { cn } from "~/utils/cn";
26-
import { ignorePathError, type IgnorePathLimits } from "~/v3/github";
26+
import {
27+
ignorePatternError,
28+
tooManyIgnorePatterns,
29+
type IgnoreKind,
30+
type IgnorePatternLimits,
31+
} from "~/v3/github";
2732

2833
const FOLDED_LINES = 3;
2934
const MAX_VISIBLE_LINES = 15;
@@ -38,9 +43,31 @@ class MatchedLineMarker extends GutterMarker {
3843
const matchedLineMarker = new MatchedLineMarker();
3944
const matchedLine = Decoration.line({ class: MATCH_CLASS });
4045

46+
const copy = {
47+
paths: {
48+
label: "Ignored paths",
49+
placeholder: "docs/**",
50+
empty: "No paths yet, so every push to a tracked branch deploys.",
51+
testLabel: "Path to test",
52+
testPlaceholder: "apps/web/src/index.ts",
53+
test: "Test a path",
54+
closeTester: "Close the path tester",
55+
noMatch: "no path matches",
56+
},
57+
branches: {
58+
label: "Ignored branches",
59+
placeholder: "dependabot/**",
60+
empty: "No branches yet, so every pull request gets a preview.",
61+
testLabel: "Branch to test",
62+
testPlaceholder: "dependabot/npm_and_yarn/react-19.0.0",
63+
test: "Test a branch",
64+
closeTester: "Close the branch tester",
65+
noMatch: "no branch matches",
66+
},
67+
} satisfies Record<IgnoreKind, unknown>;
68+
4169
const editorExtensions = [
4270
lintGutter(),
43-
placeholder("docs/**"),
4471
EditorView.theme({
4572
"&.cm-focused": { outline: "none" },
4673
".cm-line": { transition: "background-color 150ms ease-out" },
@@ -54,26 +81,26 @@ const editorExtensions = [
5481
type Line = { pattern: string; start: number; error?: string; valid: boolean };
5582
type Heights = { content: number; folded: number; max: number };
5683

57-
function analyze(text: string, { maxPaths, maxLength }: IgnorePathLimits) {
84+
function analyze(kind: IgnoreKind, text: string, { maxPatterns, maxLength }: IgnorePatternLimits) {
5885
let start = 0;
5986
const lines: Line[] = text.split("\n").map((line) => {
6087
const pattern = line.trim();
61-
const error = pattern ? ignorePathError(pattern, maxLength) : undefined;
88+
const error = pattern ? ignorePatternError(kind, pattern, maxLength) : undefined;
6289
const parsed = { pattern, start, error, valid: pattern !== "" && !error };
6390
start += line.length + 1;
6491
return parsed;
6592
});
6693
const patterns = lines.flatMap(({ pattern }) => (pattern ? [pattern] : []));
6794
const errors = [
6895
...lines.flatMap(({ error }, index) => (error ? [`Line ${index + 1}: ${error}`] : [])),
69-
...(patterns.length > maxPaths ? [`Add at most ${maxPaths} paths.`] : []),
96+
...(patterns.length > maxPatterns ? [tooManyIgnorePatterns(kind, maxPatterns)] : []),
7097
];
7198
return { lines, patterns, errors };
7299
}
73100

74-
function lintPaths(limits: IgnorePathLimits) {
101+
function lintPatterns(kind: IgnoreKind, limits: IgnorePatternLimits) {
75102
return (view: EditorView): Diagnostic[] =>
76-
analyze(view.state.doc.toString(), limits).lines.flatMap(({ error }, index) => {
103+
analyze(kind, view.state.doc.toString(), limits).lines.flatMap(({ error }, index) => {
77104
if (!error) return [];
78105
const line = view.state.doc.line(index + 1);
79106
return [{ from: line.from, to: line.to, severity: "error", message: error }];
@@ -112,15 +139,17 @@ function plural(count: number, word: string) {
112139
return `${count} ${word}${count === 1 ? "" : "s"}`;
113140
}
114141

115-
export function IgnoredPathsEditor({
142+
export function IgnoredPatternsEditor({
143+
kind,
116144
name,
117145
defaultPatterns,
118146
limits,
119147
onChange,
120148
}: {
149+
kind: IgnoreKind;
121150
name: string;
122151
defaultPatterns: string[];
123-
limits: IgnorePathLimits;
152+
limits: IgnorePatternLimits;
124153
onChange?: (patterns: string[], valid: boolean) => void;
125154
}) {
126155
// TextEditor replaces the document whenever defaultValue changes.
@@ -130,21 +159,22 @@ export function IgnoredPathsEditor({
130159
const [heights, setHeights] = useState<Heights>();
131160
const [animating, setAnimating] = useState(false);
132161
const [testing, setTesting] = useState(false);
133-
const [testPath, setTestPath] = useState("");
162+
const [testInput, setTestInput] = useState("");
134163
const viewRef = useRef<EditorView>();
135164
const scrollRef = useRef<HTMLDivElement>(null);
136165
const testButtonRef = useRef<HTMLButtonElement>(null);
137166
const errorsId = useId();
138167

139-
const { maxPaths, maxLength } = limits;
168+
const { maxPatterns, maxLength } = limits;
169+
const labels = copy[kind];
140170
const { lines, patterns, errors } = useMemo(
141-
() => analyze(text, { maxPaths, maxLength }),
142-
[text, maxPaths, maxLength]
171+
() => analyze(kind, text, { maxPatterns, maxLength }),
172+
[kind, text, maxPatterns, maxLength]
143173
);
144-
const path = testPath.trim();
174+
const tested = testInput.trim();
145175
const matchedIndex =
146-
testing && path
147-
? lines.findIndex(({ pattern, valid }) => valid && picomatch(pattern, { dot: true })(path))
176+
testing && tested
177+
? lines.findIndex(({ pattern, valid }) => valid && picomatch(pattern, { dot: true })(tested))
148178
: -1;
149179
const canTest = lines.some(({ valid }) => valid);
150180
const canFold = lines.length > FOLDED_LINES;
@@ -169,9 +199,10 @@ export function IgnoredPathsEditor({
169199
const extensions = useMemo(
170200
() => [
171201
...editorExtensions,
172-
linter(lintPaths({ maxPaths, maxLength }), { delay: 100 }),
202+
placeholder(labels.placeholder),
203+
linter(lintPatterns(kind, { maxPatterns, maxLength }), { delay: 100 }),
173204
EditorView.contentAttributes.of({
174-
"aria-label": "Ignored paths",
205+
"aria-label": labels.label,
175206
"aria-invalid": String(invalid),
176207
...(invalid ? { "aria-describedby": errorsId } : {}),
177208
}),
@@ -182,16 +213,16 @@ export function IgnoredPathsEditor({
182213
]
183214
: []),
184215
],
185-
[maxPaths, maxLength, invalid, errorsId, matchedStart]
216+
[kind, labels, maxPatterns, maxLength, invalid, errorsId, matchedStart]
186217
);
187218

188219
const edit = useCallback(
189220
(next: string) => {
190221
setText(next);
191-
const { patterns, errors } = analyze(next, limits);
222+
const { patterns, errors } = analyze(kind, next, limits);
192223
onChange?.(patterns, errors.length === 0);
193224
},
194-
[limits, onChange]
225+
[kind, limits, onChange]
195226
);
196227

197228
const onUpdate = useCallback((update: ViewUpdate) => {
@@ -222,7 +253,7 @@ export function IgnoredPathsEditor({
222253

223254
const closeTester = () => {
224255
setTesting(false);
225-
setTestPath("");
256+
setTestInput("");
226257
testButtonRef.current?.focus();
227258
};
228259

@@ -284,18 +315,18 @@ export function IgnoredPathsEditor({
284315
<div className="flex min-w-0 flex-1 items-center gap-2 duration-200 animate-in fade-in slide-in-from-right-2">
285316
<input
286317
autoFocus
287-
aria-label="Path to test"
288-
value={testPath}
289-
onChange={(event) => setTestPath(event.target.value)}
318+
aria-label={labels.testLabel}
319+
value={testInput}
320+
onChange={(event) => setTestInput(event.target.value)}
290321
onKeyDown={onTesterKeyDown}
291-
placeholder="apps/web/src/index.ts"
322+
placeholder={labels.testPlaceholder}
292323
className="h-6 min-w-0 flex-1 border-none bg-transparent p-0 font-mono text-xs text-text-bright outline-none placeholder:text-text-dimmed focus:ring-0"
293324
/>
294325
<span
295326
role="status"
296327
className="flex min-w-0 max-w-[60%] items-center gap-1.5 text-text-dimmed"
297328
>
298-
{path && (
329+
{tested && (
299330
<>
300331
<VerdictBadge key={verdict} verdict={verdict} />
301332
<span className="min-w-0 truncate">
@@ -307,7 +338,7 @@ export function IgnoredPathsEditor({
307338
</span>
308339
</>
309340
) : (
310-
"no path matches"
341+
labels.noMatch
311342
)}
312343
</span>
313344
</>
@@ -317,9 +348,7 @@ export function IgnoredPathsEditor({
317348
) : errors.length > 0 ? (
318349
<span className="truncate text-error">{plural(errors.length, "error")}</span>
319350
) : patterns.length === 0 ? (
320-
<span className="truncate text-text-dimmed">
321-
No paths yet, so every push to a tracked branch deploys.
322-
</span>
351+
<span className="truncate text-text-dimmed">{labels.empty}</span>
323352
) : null}
324353
</div>
325354
{(testing || canTest) && (
@@ -330,8 +359,8 @@ export function IgnoredPathsEditor({
330359
LeadingIcon={FlaskConicalIcon}
331360
leadingIconClassName="text-indigo-400 transition-transform duration-200 group-hover/button:-rotate-12 light:text-indigo-600"
332361
className={cn(testing && "bg-indigo-500/15")}
333-
tooltip={testing ? "Close the path tester" : "Test a path"}
334-
aria-label={testing ? "Close the path tester" : "Test a path"}
362+
tooltip={testing ? labels.closeTester : labels.test}
363+
aria-label={testing ? labels.closeTester : labels.test}
335364
onClick={() => (testing ? closeTester() : setTesting(true))}
336365
/>
337366
)}

0 commit comments

Comments
 (0)