Skip to content

Commit c46b616

Browse files
committed
Default git metadata without diffs
1 parent 38a6c52 commit c46b616

5 files changed

Lines changed: 62 additions & 10 deletions

File tree

js/src/gitutil.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
} from "./generated_types";
55
import { debugLogger } from "./debug-logger";
66
import { simpleGit } from "simple-git";
7+
import { defaultGitMetadataSettings } from "../util/git_fields";
78

89
const COMMON_BASE_BRANCHES = ["main", "master", "develop"];
910

@@ -149,17 +150,18 @@ function truncateToByteLimit(s: string, byteLimit: number = 65536): string {
149150
}
150151

151152
export async function getRepoInfo(settings?: GitMetadataSettings) {
152-
if (settings && settings.collect === "none") {
153+
const resolvedSettings = settings ?? defaultGitMetadataSettings();
154+
if (resolvedSettings.collect === "none") {
153155
return undefined;
154156
}
155157

156158
const repo = await repoInfo();
157-
if (!repo || !settings || settings.collect === "all") {
159+
if (!repo || resolvedSettings.collect === "all") {
158160
return repo;
159161
}
160162

161163
let sanitized: RepoInfo = {};
162-
settings.fields?.forEach((field) => {
164+
resolvedSettings.fields?.forEach((field) => {
163165
sanitized = { ...sanitized, [field]: repo[field] };
164166
});
165167

js/src/logger.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
IdField,
3232
IS_MERGE_FIELD,
3333
LogFeedbackFullArgs,
34+
defaultGitMetadataSettings,
3435
mergeDicts,
3536
mergeGitMetadataSettings,
3637
mergeRowBatch,
@@ -3535,7 +3536,7 @@ type InitializedExperiment<IsOpen extends boolean | undefined> =
35353536
* @param options.apiKey The API key to use. If the parameter is not specified, will try to use the `BRAINTRUST_API_KEY` environment variable. If no API key is specified, will prompt the user to login.
35363537
* @param options.orgName (Optional) The name of a specific organization to connect to. This is useful if you belong to multiple.
35373538
* @param options.metadata (Optional) A dictionary with additional data about the test example, model outputs, or just about anything else that's relevant, that you can use to help find and analyze examples later. For example, you could log the `prompt`, example's `id`, or anything else that would be useful to slice/dice later. The values in `metadata` can be any JSON-serializable type, but its keys must be strings.
3538-
* @param options.gitMetadataSettings (Optional) Settings for collecting git metadata. By default, will collect all git metadata fields allowed in org-level settings.
3539+
* @param options.gitMetadataSettings (Optional) Settings for collecting git metadata. By default, will collect git metadata fields allowed in org-level settings, excluding diff content unless the org opts in.
35393540
* @param setCurrent If true (the default), set the global current-experiment to the newly-created one.
35403541
* @param options.open If the experiment already exists, open it in read-only mode. Throws an error if the experiment does not already exist.
35413542
* @param options.projectId The id of the project to create the experiment in. This takes precedence over `project` if specified.
@@ -3689,9 +3690,7 @@ export function init<IsOpen extends boolean = false>(
36893690
return repoInfo;
36903691
}
36913692
let mergedGitMetadataSettings = {
3692-
...(state.gitMetadataSettings || {
3693-
collect: "all",
3694-
}),
3693+
...(state.gitMetadataSettings || defaultGitMetadataSettings()),
36953694
};
36963695
if (gitMetadataSettings) {
36973696
mergedGitMetadataSettings = mergeGitMetadataSettings(
@@ -5699,7 +5698,8 @@ function _saveOrgInfo(
56995698
state.orgName = org.name;
57005699
state.apiUrl = iso.getEnv("BRAINTRUST_API_URL") ?? org.api_url;
57015700
state.proxyUrl = iso.getEnv("BRAINTRUST_PROXY_URL") ?? org.proxy_url;
5702-
state.gitMetadataSettings = org.git_metadata || undefined;
5701+
state.gitMetadataSettings =
5702+
org.git_metadata || defaultGitMetadataSettings();
57035703
break;
57045704
}
57055705
}

js/util/git_fields.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { describe, expect, test } from "vitest";
2+
import { defaultGitMetadataSettings } from "./git_fields";
3+
4+
describe("defaultGitMetadataSettings", () => {
5+
test("excludes git diff by default", () => {
6+
expect(defaultGitMetadataSettings()).toEqual({
7+
collect: "some",
8+
fields: [
9+
"commit",
10+
"branch",
11+
"tag",
12+
"dirty",
13+
"author_name",
14+
"author_email",
15+
"commit_message",
16+
"commit_time",
17+
],
18+
});
19+
});
20+
21+
test("returns a fresh fields array", () => {
22+
const settings = defaultGitMetadataSettings();
23+
settings.fields?.push("git_diff");
24+
25+
expect(defaultGitMetadataSettings().fields).not.toContain("git_diff");
26+
});
27+
});

js/util/git_fields.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
1-
import { GitMetadataSettingsType as GitMetadataSettings } from "./generated_types";
1+
import { type GitMetadataSettingsType as GitMetadataSettings } from "./generated_types";
2+
3+
export const DEFAULT_GIT_METADATA_FIELDS: NonNullable<
4+
GitMetadataSettings["fields"]
5+
> = [
6+
"commit",
7+
"branch",
8+
"tag",
9+
"dirty",
10+
"author_name",
11+
"author_email",
12+
"commit_message",
13+
"commit_time",
14+
];
15+
16+
export function defaultGitMetadataSettings(): GitMetadataSettings {
17+
return {
18+
collect: "some",
19+
fields: [...DEFAULT_GIT_METADATA_FIELDS],
20+
};
21+
}
222

323
export function mergeGitMetadataSettings(
424
s1: GitMetadataSettings,

js/util/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ export {
136136
spanTypeAttributeValues,
137137
} from "./span_types";
138138

139-
export { mergeGitMetadataSettings } from "./git_fields";
139+
export {
140+
defaultGitMetadataSettings,
141+
mergeGitMetadataSettings,
142+
} from "./git_fields";
140143

141144
export { loadPrettyXact, prettifyXact } from "./xact-ids";
142145

0 commit comments

Comments
 (0)