Merged
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
82 changes: 82 additions & 0 deletions .env.development
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@

# Prisma
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/postgres"

# Zoekt
ZOEKT_WEBSERVER_URL="http://localhost:6070"
# SHARD_MAX_MATCH_COUNT=10000
# TOTAL_MAX_MATCH_COUNT=100000
# The command to use for generating ctags.
CTAGS_COMMAND=ctags
# logging, strict
SRC_TENANT_ENFORCEMENT_MODE=strict

# Auth.JS
# You can generate a new secret with:
# openssl rand -base64 33
# @see: https://authjs.dev/getting-started/deployment#auth_secret
AUTH_SECRET="secret"
AUTH_URL="http://localhost:3000"
# AUTH_CREDENTIALS_LOGIN_ENABLED=true
# AUTH_GITHUB_CLIENT_ID=""
# AUTH_GITHUB_CLIENT_SECRET=""
# AUTH_GOOGLE_CLIENT_ID=""
# AUTH_GOOGLE_CLIENT_SECRET=""

# Email
# EMAIL_FROM="" # The from address for transactional emails.
# SMTP_CONNECTION_URL="" # The SMTP connection URL for transactional emails.

# PostHog
# POSTHOG_PAPIK=""
# NEXT_PUBLIC_POSTHOG_PAPIK=""

# Sentry
# SENTRY_BACKEND_DSN=""
# NEXT_PUBLIC_SENTRY_WEBAPP_DSN=""
# SENTRY_ENVIRONMENT="dev"
# NEXT_PUBLIC_SENTRY_ENVIRONMENT="dev"
# SENTRY_AUTH_TOKEN=

# Logtail
# LOGTAIL_TOKEN=""
# LOGTAIL_HOST=""

# Redis
REDIS_URL="redis://localhost:6379"

# Stripe
# STRIPE_SECRET_KEY: z.string().optional(),
# STRIPE_PRODUCT_ID: z.string().optional(),
# STRIPE_WEBHOOK_SECRET: z.string().optional(),

# Misc

# Set during docker build of application
# Used to disable env var validation at build time
# DOCKER_BUILD=1

# Generated using:
# openssl rand -base64 24
SOURCEBOT_ENCRYPTION_KEY="secret"

SOURCEBOT_LOG_LEVEL="debug" # valid values: info, debug, warn, error
SOURCEBOT_TELEMETRY_DISABLED=true # Disables telemetry collection

# Code-host fallback tokens
# FALLBACK_GITHUB_TOKEN=""
# FALLBACK_GITLAB_TOKEN=""
# FALLBACK_GITEA_TOKEN=""

# Controls the number of concurrent indexing jobs that can run at once
# INDEX_CONCURRENCY_MULTIPLE=

# Controls the polling interval for the web app
# NEXT_PUBLIC_POLLING_INTERVAL_MS=

# Controls the version of the web app
# NEXT_PUBLIC_SOURCEBOT_VERSION=

# CONFIG_MAX_REPOS_NO_TOKEN=
# SOURCEBOT_ROOT_DOMAIN=
# NODE_ENV=
15 changes: 11 additions & 4 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,13 +6,20 @@
"scripts": {
"build": "yarn workspaces run build",
"test": "yarn workspaces run test",
"dev": "yarn workspace @sourcebot/db prisma:migrate:dev && cross-env npm-run-all --print-label --parallel dev:zoekt dev:backend dev:web",
"dev:zoekt": "export PATH=\"$PWD/bin:$PATH\" && export SRC_TENANT_ENFORCEMENT_MODE=strict && zoekt-webserver -index .sourcebot/index -rpc",
"dev:backend": "yarn workspace @sourcebot/backend dev:watch",
"dev:web": "yarn workspace @sourcebot/web dev"

"dev": "yarn dev:prisma:migrate && npm-run-all --print-label --parallel dev:zoekt dev:backend dev:web",
"with-env": "cross-env PATH=\"$PWD/bin:$PATH\" dotenv -e .env.development -c --",
"dev:zoekt": "yarn with-env zoekt-webserver -index .sourcebot/index -rpc",
"dev:backend": "yarn with-env yarn workspace @sourcebot/backend dev:watch",
"dev:web": "yarn with-env yarn workspace @sourcebot/web dev",

"dev:prisma:migrate": "yarn with-env yarn workspace @sourcebot/db prisma:migrate:dev",
"dev:prisma:studio": "yarn with-env yarn workspace @sourcebot/db prisma:studio",
"dev:prisma:migrate:reset": "yarn with-env yarn workspace @sourcebot/db prisma:migrate:reset"
},
"devDependencies": {
"cross-env": "^7.0.3",
"dotenv-cli": "^8.0.0",
"npm-run-all": "^4.1.5"
}
}
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@
"type": "module",
"scripts": {
"dev:watch": "tsc-watch --preserveWatchOutput --onSuccess \"yarn dev --cacheDir ../../.sourcebot\"",
"dev": "export PATH=\"$PWD/../../bin:$PATH\" && export CTAGS_COMMAND=ctags && node ./dist/index.js",
"dev": "node ./dist/index.js",
"build": "tsc",
"test": "vitest --config ./vitest.config.ts"
},
Expand Down
9 changes: 6 additions & 3 deletions packages/backend/src/env.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,9 @@ import { createEnv } from "@t3-oss/env-core";
import { z } from "zod";
import dotenv from 'dotenv';

// Booleans are specified as 'true' or 'false' strings.
const booleanSchema = z.enum(["true", "false"]);

dotenv.config({
path: './.env',
});
Expand All@@ -15,18 +18,17 @@ export const env = createEnv({
server: {
SOURCEBOT_ENCRYPTION_KEY: z.string(),
SOURCEBOT_LOG_LEVEL: z.enum(["info", "debug", "warn", "error"]).default("info"),
SOURCEBOT_TELEMETRY_DISABLED: z.enum(["true", "false"]).default("false"),
SOURCEBOT_TELEMETRY_DISABLED: booleanSchema.default("false"),
SOURCEBOT_INSTALL_ID: z.string().default("unknown"),
SOURCEBOT_VERSION: z.string().default("unknown"),

POSTHOG_PAPIK: z.string().optional(),
POSTHOG_HOST: z.string().url().default('https://us.i.posthog.com'),

FALLBACK_GITHUB_TOKEN: z.string().optional(),
FALLBACK_GITLAB_TOKEN: z.string().optional(),
FALLBACK_GITEA_TOKEN: z.string().optional(),

REDIS_URL: z.string().url().optional().default("redis://localhost:6379"),
REDIS_URL: z.string().url(),

SENTRY_BACKEND_DSN: z.string().optional(),
SENTRY_ENVIRONMENT: z.string().optional(),
Expand All@@ -35,6 +37,7 @@ export const env = createEnv({
LOGTAIL_HOST: z.string().url().optional(),

INDEX_CONCURRENCY_MULTIPLE: z.number().optional(),
DATABASE_URL: z.string().url(),
},
runtimeEnv: process.env,
emptyStringAsUndefined: true,
Expand Down
27 changes: 27 additions & 0 deletions packages/backend/src/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,33 @@ import { AppContext } from "./types.js";
import { main } from "./main.js"
import { PrismaClient } from "@sourcebot/db";

// Register handler for normal exit
process.on('exit', (code) => {
console.log(`Process is exiting with code: ${code}`);
});

// Register handlers for abnormal terminations
process.on('SIGINT', () => {
console.log('Process interrupted (SIGINT)');
process.exit(130);
});

process.on('SIGTERM', () => {
console.log('Process terminated (SIGTERM)');
process.exit(143);
});

// Register handlers for uncaught exceptions and unhandled rejections
process.on('uncaughtException', (err) => {
console.log(`Uncaught exception: ${err.message}`);
process.exit(1);
});

process.on('unhandledRejection', (reason, promise) => {
console.log(`Unhandled rejection at: ${promise}, reason: ${reason}`);
process.exit(1);
});


const parser = new ArgumentParser({
description: "Sourcebot backend tool",
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/posthog.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,13 +8,13 @@ if (env.POSTHOG_PAPIK) {
posthog = new PostHog(
env.POSTHOG_PAPIK,
{
host: env.POSTHOG_HOST,
host: "https://us.i.posthog.com",
}
);
}

export function captureEvent<E extends PosthogEvent>(event: E, properties: PosthogEventMap[E]) {
if (env.SOURCEBOT_TELEMETRY_DISABLED) {
if (env.SOURCEBOT_TELEMETRY_DISABLED === 'true') {
return;
}

Expand Down
3 changes: 2 additions & 1 deletion packages/crypto/package.json
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
{
"name": "@sourcebot/crypto",
"main": "dist/index.js",
"version": "0.1.0",
"main": "dist/index.js",
"private": true,
"scripts": {
"build": "tsc",
"postinstall": "yarn build"
Expand Down
1 change: 0 additions & 1 deletion packages/web/src/app/posthogProvider.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,6 @@ export function PostHogProvider({ children, disabled }: PostHogProviderProps) {
posthog.init(env.NEXT_PUBLIC_POSTHOG_PAPIK, {
// @see next.config.mjs for path rewrites to the "/ingest" route.
api_host: "/ingest",
ui_host: env.NEXT_PUBLIC_POSTHOG_UI_HOST,
person_profiles: 'identified_only',
capture_pageview: false, // @nocheckin Disable automatic pageview capture if we're not in public demo mode
autocapture: false, // Disable automatic event capture
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/auth.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -76,7 +76,7 @@ export const getProviders = () => {
}));
}

if (env.AUTH_CREDENTIALS_LOGIN_ENABLED) {
if (env.AUTH_CREDENTIALS_LOGIN_ENABLED === 'true') {
providers.push(Credentials({
credentials: {
email: {},
Expand Down
11 changes: 6 additions & 5 deletions packages/web/src/env.mjs
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
import { createEnv } from "@t3-oss/env-nextjs";
import { z } from "zod";

// Booleans are specified as 'true' or 'false' strings.
const booleanSchema = z.enum(["true", "false"]);

export const env = createEnv({
server: {
// Zoekt
ZOEKT_WEBSERVER_URL: z.string().url().default('http://localhost:6070'),
ZOEKT_WEBSERVER_URL: z.string().url(),
SHARD_MAX_MATCH_COUNT: z.number().default(10000),
TOTAL_MAX_MATCH_COUNT: z.number().default(100000),

Expand All@@ -15,7 +18,7 @@ export const env = createEnv({
AUTH_GOOGLE_CLIENT_ID: z.string().optional(),
AUTH_GOOGLE_CLIENT_SECRET: z.string().optional(),
AUTH_URL: z.string().url(),
AUTH_CREDENTIALS_LOGIN_ENABLED: z.boolean().default(true),
AUTH_CREDENTIALS_LOGIN_ENABLED: booleanSchema.default('true'),

// Email
SMTP_CONNECTION_URL: z.string().url().optional(),
Expand All@@ -30,15 +33,14 @@ export const env = createEnv({
CONFIG_MAX_REPOS_NO_TOKEN: z.number().default(500),
SOURCEBOT_ROOT_DOMAIN: z.string().default("localhost:3000"),
NODE_ENV: z.enum(["development", "test", "production"]),
SOURCEBOT_TELEMETRY_DISABLED: z.enum(["true", "false"]).default("false"),
SOURCEBOT_TELEMETRY_DISABLED: booleanSchema.default('false'),
DATABASE_URL: z.string().url(),
},
// @NOTE: Make sure you destructure all client variables in the
// `experimental__runtimeEnv` block below.
client: {
// PostHog
NEXT_PUBLIC_POSTHOG_PAPIK: z.string().optional(),
NEXT_PUBLIC_POSTHOG_UI_HOST: z.string().url().default('https://us.posthog.com'),

// Misc
NEXT_PUBLIC_SOURCEBOT_VERSION: z.string().default('unknown'),
Expand All@@ -47,7 +49,6 @@ export const env = createEnv({
// For Next.js >= 13.4.4, you only need to destructure client variables:
experimental__runtimeEnv: {
NEXT_PUBLIC_POSTHOG_PAPIK: process.env.NEXT_PUBLIC_POSTHOG_PAPIK,
NEXT_PUBLIC_POSTHOG_UI_HOST: process.env.NEXT_PUBLIC_POSTHOG_UI_HOST,
NEXT_PUBLIC_SOURCEBOT_VERSION: process.env.NEXT_PUBLIC_SOURCEBOT_VERSION,
NEXT_PUBLIC_POLLING_INTERVAL_MS: process.env.NEXT_PUBLIC_POLLING_INTERVAL_MS,
},
Expand Down
19 changes: 17 additions & 2 deletions yarn.lock
Original file line numberDiff line numberDiff line change
Expand Up@@ -5096,7 +5096,7 @@ cross-spawn@^6.0.5:
shebang-command "^1.2.0"
which "^1.2.9"

cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.2, cross-spawn@^7.0.3, cross-spawn@^7.0.6:
version "7.0.6"
resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz"
integrity sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==
Expand DownExpand Up@@ -5382,7 +5382,22 @@ domutils@^3.0.1:
domelementtype "^2.3.0"
domhandler "^5.0.3"

dotenv@^16.3.1:
dotenv-cli@^8.0.0:
version "8.0.0"
resolved "https://registry.npmjs.org/dotenv-cli/-/dotenv-cli-8.0.0.tgz#cea1519f5a06c7372a1428fca4605fcf3d50e1cf"
integrity sha512-aLqYbK7xKOiTMIRf1lDPbI+Y+Ip/wo5k3eyp6ePysVaSqbyxjyK3dK35BTxG+rmd7djf5q2UPs4noPNH+cj0Qw==
dependencies:
cross-spawn "^7.0.6"
dotenv "^16.3.0"
dotenv-expand "^10.0.0"
minimist "^1.2.6"

dotenv-expand@^10.0.0:
version "10.0.0"
resolved "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-10.0.0.tgz#12605d00fb0af6d0a592e6558585784032e4ef37"
integrity sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==

dotenv@^16.3.0, dotenv@^16.3.1:
version "16.4.7"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.7.tgz#0e20c5b82950140aa99be360a8a5f52335f53c26"
integrity sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all \u003cpre\u003e\u003ccode\u003e blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks"); } } catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); } })(); (function(){ try { var __m = "github.com"; var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
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
82 changes: 82 additions & 0 deletions .env.development
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@

# Prisma
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/postgres"

# Zoekt
ZOEKT_WEBSERVER_URL="http://localhost:6070"
# SHARD_MAX_MATCH_COUNT=10000
# TOTAL_MAX_MATCH_COUNT=100000
# The command to use for generating ctags.
CTAGS_COMMAND=ctags
# logging, strict
SRC_TENANT_ENFORCEMENT_MODE=strict

# Auth.JS
# You can generate a new secret with:
# openssl rand -base64 33
# @see: https://authjs.dev/getting-started/deployment#auth_secret
AUTH_SECRET="secret"
AUTH_URL="http://localhost:3000"
# AUTH_CREDENTIALS_LOGIN_ENABLED=true
# AUTH_GITHUB_CLIENT_ID=""
# AUTH_GITHUB_CLIENT_SECRET=""
# AUTH_GOOGLE_CLIENT_ID=""
# AUTH_GOOGLE_CLIENT_SECRET=""

# Email
# EMAIL_FROM="" # The from address for transactional emails.
# SMTP_CONNECTION_URL="" # The SMTP connection URL for transactional emails.

# PostHog
# POSTHOG_PAPIK=""
# NEXT_PUBLIC_POSTHOG_PAPIK=""

# Sentry
# SENTRY_BACKEND_DSN=""
# NEXT_PUBLIC_SENTRY_WEBAPP_DSN=""
# SENTRY_ENVIRONMENT="dev"
# NEXT_PUBLIC_SENTRY_ENVIRONMENT="dev"
# SENTRY_AUTH_TOKEN=

# Logtail
# LOGTAIL_TOKEN=""
# LOGTAIL_HOST=""

# Redis
REDIS_URL="redis://localhost:6379"

# Stripe
# STRIPE_SECRET_KEY: z.string().optional(),
# STRIPE_PRODUCT_ID: z.string().optional(),
# STRIPE_WEBHOOK_SECRET: z.string().optional(),

# Misc

# Set during docker build of application
# Used to disable env var validation at build time
# DOCKER_BUILD=1

# Generated using:
# openssl rand -base64 24
SOURCEBOT_ENCRYPTION_KEY="secret"

SOURCEBOT_LOG_LEVEL="debug" # valid values: info, debug, warn, error
SOURCEBOT_TELEMETRY_DISABLED=true # Disables telemetry collection

# Code-host fallback tokens
# FALLBACK_GITHUB_TOKEN=""
# FALLBACK_GITLAB_TOKEN=""
# FALLBACK_GITEA_TOKEN=""

# Controls the number of concurrent indexing jobs that can run at once
# INDEX_CONCURRENCY_MULTIPLE=

# Controls the polling interval for the web app
# NEXT_PUBLIC_POLLING_INTERVAL_MS=

# Controls the version of the web app
# NEXT_PUBLIC_SOURCEBOT_VERSION=

# CONFIG_MAX_REPOS_NO_TOKEN=
# SOURCEBOT_ROOT_DOMAIN=
# NODE_ENV=
15 changes: 11 additions & 4 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,13 +6,20 @@
"scripts": {
"build": "yarn workspaces run build",
"test": "yarn workspaces run test",
"dev": "yarn workspace @sourcebot/db prisma:migrate:dev && cross-env npm-run-all --print-label --parallel dev:zoekt dev:backend dev:web",
"dev:zoekt": "export PATH=\"$PWD/bin:$PATH\" && export SRC_TENANT_ENFORCEMENT_MODE=strict && zoekt-webserver -index .sourcebot/index -rpc",
"dev:backend": "yarn workspace @sourcebot/backend dev:watch",
"dev:web": "yarn workspace @sourcebot/web dev"

"dev": "yarn dev:prisma:migrate && npm-run-all --print-label --parallel dev:zoekt dev:backend dev:web",
"with-env": "cross-env PATH=\"$PWD/bin:$PATH\" dotenv -e .env.development -c --",
"dev:zoekt": "yarn with-env zoekt-webserver -index .sourcebot/index -rpc",
"dev:backend": "yarn with-env yarn workspace @sourcebot/backend dev:watch",
"dev:web": "yarn with-env yarn workspace @sourcebot/web dev",

"dev:prisma:migrate": "yarn with-env yarn workspace @sourcebot/db prisma:migrate:dev",
"dev:prisma:studio": "yarn with-env yarn workspace @sourcebot/db prisma:studio",
"dev:prisma:migrate:reset": "yarn with-env yarn workspace @sourcebot/db prisma:migrate:reset"
},
"devDependencies": {
"cross-env": "^7.0.3",
"dotenv-cli": "^8.0.0",
"npm-run-all": "^4.1.5"
}
}
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@
"type": "module",
"scripts": {
"dev:watch": "tsc-watch --preserveWatchOutput --onSuccess \"yarn dev --cacheDir ../../.sourcebot\"",
"dev": "export PATH=\"$PWD/../../bin:$PATH\" && export CTAGS_COMMAND=ctags && node ./dist/index.js",
"dev": "node ./dist/index.js",
"build": "tsc",
"test": "vitest --config ./vitest.config.ts"
},
Expand Down
9 changes: 6 additions & 3 deletions packages/backend/src/env.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,9 @@ import { createEnv } from "@t3-oss/env-core";
import { z } from "zod";
import dotenv from 'dotenv';

// Booleans are specified as 'true' or 'false' strings.
const booleanSchema = z.enum(["true", "false"]);

dotenv.config({
path: './.env',
});
Expand All@@ -15,18 +18,17 @@ export const env = createEnv({
server: {
SOURCEBOT_ENCRYPTION_KEY: z.string(),
SOURCEBOT_LOG_LEVEL: z.enum(["info", "debug", "warn", "error"]).default("info"),
SOURCEBOT_TELEMETRY_DISABLED: z.enum(["true", "false"]).default("false"),
SOURCEBOT_TELEMETRY_DISABLED: booleanSchema.default("false"),
SOURCEBOT_INSTALL_ID: z.string().default("unknown"),
SOURCEBOT_VERSION: z.string().default("unknown"),

POSTHOG_PAPIK: z.string().optional(),
POSTHOG_HOST: z.string().url().default('https://us.i.posthog.com'),

FALLBACK_GITHUB_TOKEN: z.string().optional(),
FALLBACK_GITLAB_TOKEN: z.string().optional(),
FALLBACK_GITEA_TOKEN: z.string().optional(),

REDIS_URL: z.string().url().optional().default("redis://localhost:6379"),
REDIS_URL: z.string().url(),

SENTRY_BACKEND_DSN: z.string().optional(),
SENTRY_ENVIRONMENT: z.string().optional(),
Expand All@@ -35,6 +37,7 @@ export const env = createEnv({
LOGTAIL_HOST: z.string().url().optional(),

INDEX_CONCURRENCY_MULTIPLE: z.number().optional(),
DATABASE_URL: z.string().url(),
},
runtimeEnv: process.env,
emptyStringAsUndefined: true,
Expand Down
27 changes: 27 additions & 0 deletions packages/backend/src/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,33 @@ import { AppContext } from "./types.js";
import { main } from "./main.js"
import { PrismaClient } from "@sourcebot/db";

// Register handler for normal exit
process.on('exit', (code) => {
console.log(`Process is exiting with code: ${code}`);
});

// Register handlers for abnormal terminations
process.on('SIGINT', () => {
console.log('Process interrupted (SIGINT)');
process.exit(130);
});

process.on('SIGTERM', () => {
console.log('Process terminated (SIGTERM)');
process.exit(143);
});

// Register handlers for uncaught exceptions and unhandled rejections
process.on('uncaughtException', (err) => {
console.log(`Uncaught exception: ${err.message}`);
process.exit(1);
});

process.on('unhandledRejection', (reason, promise) => {
console.log(`Unhandled rejection at: ${promise}, reason: ${reason}`);
process.exit(1);
});


const parser = new ArgumentParser({
description: "Sourcebot backend tool",
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/posthog.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,13 +8,13 @@ if (env.POSTHOG_PAPIK) {
posthog = new PostHog(
env.POSTHOG_PAPIK,
{
host: env.POSTHOG_HOST,
host: "https://us.i.posthog.com",
}
);
}

export function captureEvent<E extends PosthogEvent>(event: E, properties: PosthogEventMap[E]) {
if (env.SOURCEBOT_TELEMETRY_DISABLED) {
if (env.SOURCEBOT_TELEMETRY_DISABLED === 'true') {
return;
}

Expand Down
3 changes: 2 additions & 1 deletion packages/crypto/package.json
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
{
"name": "@sourcebot/crypto",
"main": "dist/index.js",
"version": "0.1.0",
"main": "dist/index.js",
"private": true,
"scripts": {
"build": "tsc",
"postinstall": "yarn build"
Expand Down
1 change: 0 additions & 1 deletion packages/web/src/app/posthogProvider.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,6 @@ export function PostHogProvider({ children, disabled }: PostHogProviderProps) {
posthog.init(env.NEXT_PUBLIC_POSTHOG_PAPIK, {
// @see next.config.mjs for path rewrites to the "/ingest" route.
api_host: "/ingest",
ui_host: env.NEXT_PUBLIC_POSTHOG_UI_HOST,
person_profiles: 'identified_only',
capture_pageview: false, // @nocheckin Disable automatic pageview capture if we're not in public demo mode
autocapture: false, // Disable automatic event capture
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/auth.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -76,7 +76,7 @@ export const getProviders = () => {
}));
}

if (env.AUTH_CREDENTIALS_LOGIN_ENABLED) {
if (env.AUTH_CREDENTIALS_LOGIN_ENABLED === 'true') {
providers.push(Credentials({
credentials: {
email: {},
Expand Down
11 changes: 6 additions & 5 deletions packages/web/src/env.mjs
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
import { createEnv } from "@t3-oss/env-nextjs";
import { z } from "zod";

// Booleans are specified as 'true' or 'false' strings.
const booleanSchema = z.enum(["true", "false"]);

export const env = createEnv({
server: {
// Zoekt
ZOEKT_WEBSERVER_URL: z.string().url().default('http://localhost:6070'),
ZOEKT_WEBSERVER_URL: z.string().url(),
SHARD_MAX_MATCH_COUNT: z.number().default(10000),
TOTAL_MAX_MATCH_COUNT: z.number().default(100000),

Expand All@@ -15,7 +18,7 @@ export const env = createEnv({
AUTH_GOOGLE_CLIENT_ID: z.string().optional(),
AUTH_GOOGLE_CLIENT_SECRET: z.string().optional(),
AUTH_URL: z.string().url(),
AUTH_CREDENTIALS_LOGIN_ENABLED: z.boolean().default(true),
AUTH_CREDENTIALS_LOGIN_ENABLED: booleanSchema.default('true'),

// Email
SMTP_CONNECTION_URL: z.string().url().optional(),
Expand All@@ -30,15 +33,14 @@ export const env = createEnv({
CONFIG_MAX_REPOS_NO_TOKEN: z.number().default(500),
SOURCEBOT_ROOT_DOMAIN: z.string().default("localhost:3000"),
NODE_ENV: z.enum(["development", "test", "production"]),
SOURCEBOT_TELEMETRY_DISABLED: z.enum(["true", "false"]).default("false"),
SOURCEBOT_TELEMETRY_DISABLED: booleanSchema.default('false'),
DATABASE_URL: z.string().url(),
},
// @NOTE: Make sure you destructure all client variables in the
// `experimental__runtimeEnv` block below.
client: {
// PostHog
NEXT_PUBLIC_POSTHOG_PAPIK: z.string().optional(),
NEXT_PUBLIC_POSTHOG_UI_HOST: z.string().url().default('https://us.posthog.com'),

// Misc
NEXT_PUBLIC_SOURCEBOT_VERSION: z.string().default('unknown'),
Expand All@@ -47,7 +49,6 @@ export const env = createEnv({
// For Next.js >= 13.4.4, you only need to destructure client variables:
experimental__runtimeEnv: {
NEXT_PUBLIC_POSTHOG_PAPIK: process.env.NEXT_PUBLIC_POSTHOG_PAPIK,
NEXT_PUBLIC_POSTHOG_UI_HOST: process.env.NEXT_PUBLIC_POSTHOG_UI_HOST,
NEXT_PUBLIC_SOURCEBOT_VERSION: process.env.NEXT_PUBLIC_SOURCEBOT_VERSION,
NEXT_PUBLIC_POLLING_INTERVAL_MS: process.env.NEXT_PUBLIC_POLLING_INTERVAL_MS,
},
Expand Down
19 changes: 17 additions & 2 deletions yarn.lock
Original file line numberDiff line numberDiff line change
Expand Up@@ -5096,7 +5096,7 @@ cross-spawn@^6.0.5:
shebang-command "^1.2.0"
which "^1.2.9"

cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.2, cross-spawn@^7.0.3, cross-spawn@^7.0.6:
version "7.0.6"
resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz"
integrity sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==
Expand DownExpand Up@@ -5382,7 +5382,22 @@ domutils@^3.0.1:
domelementtype "^2.3.0"
domhandler "^5.0.3"

dotenv@^16.3.1:
dotenv-cli@^8.0.0:
version "8.0.0"
resolved "https://registry.npmjs.org/dotenv-cli/-/dotenv-cli-8.0.0.tgz#cea1519f5a06c7372a1428fca4605fcf3d50e1cf"
integrity sha512-aLqYbK7xKOiTMIRf1lDPbI+Y+Ip/wo5k3eyp6ePysVaSqbyxjyK3dK35BTxG+rmd7djf5q2UPs4noPNH+cj0Qw==
dependencies:
cross-spawn "^7.0.6"
dotenv "^16.3.0"
dotenv-expand "^10.0.0"
minimist "^1.2.6"

dotenv-expand@^10.0.0:
version "10.0.0"
resolved "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-10.0.0.tgz#12605d00fb0af6d0a592e6558585784032e4ef37"
integrity sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==

dotenv@^16.3.0, dotenv@^16.3.1:
version "16.4.7"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.7.tgz#0e20c5b82950140aa99be360a8a5f52335f53c26"
integrity sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
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
82 changes: 82 additions & 0 deletions .env.development
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@

# Prisma
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/postgres"

# Zoekt
ZOEKT_WEBSERVER_URL="http://localhost:6070"
# SHARD_MAX_MATCH_COUNT=10000
# TOTAL_MAX_MATCH_COUNT=100000
# The command to use for generating ctags.
CTAGS_COMMAND=ctags
# logging, strict
SRC_TENANT_ENFORCEMENT_MODE=strict

# Auth.JS
# You can generate a new secret with:
# openssl rand -base64 33
# @see: https://authjs.dev/getting-started/deployment#auth_secret
AUTH_SECRET="secret"
AUTH_URL="http://localhost:3000"
# AUTH_CREDENTIALS_LOGIN_ENABLED=true
# AUTH_GITHUB_CLIENT_ID=""
# AUTH_GITHUB_CLIENT_SECRET=""
# AUTH_GOOGLE_CLIENT_ID=""
# AUTH_GOOGLE_CLIENT_SECRET=""

# Email
# EMAIL_FROM="" # The from address for transactional emails.
# SMTP_CONNECTION_URL="" # The SMTP connection URL for transactional emails.

# PostHog
# POSTHOG_PAPIK=""
# NEXT_PUBLIC_POSTHOG_PAPIK=""

# Sentry
# SENTRY_BACKEND_DSN=""
# NEXT_PUBLIC_SENTRY_WEBAPP_DSN=""
# SENTRY_ENVIRONMENT="dev"
# NEXT_PUBLIC_SENTRY_ENVIRONMENT="dev"
# SENTRY_AUTH_TOKEN=

# Logtail
# LOGTAIL_TOKEN=""
# LOGTAIL_HOST=""

# Redis
REDIS_URL="redis://localhost:6379"

# Stripe
# STRIPE_SECRET_KEY: z.string().optional(),
# STRIPE_PRODUCT_ID: z.string().optional(),
# STRIPE_WEBHOOK_SECRET: z.string().optional(),

# Misc

# Set during docker build of application
# Used to disable env var validation at build time
# DOCKER_BUILD=1

# Generated using:
# openssl rand -base64 24
SOURCEBOT_ENCRYPTION_KEY="secret"

SOURCEBOT_LOG_LEVEL="debug" # valid values: info, debug, warn, error
SOURCEBOT_TELEMETRY_DISABLED=true # Disables telemetry collection

# Code-host fallback tokens
# FALLBACK_GITHUB_TOKEN=""
# FALLBACK_GITLAB_TOKEN=""
# FALLBACK_GITEA_TOKEN=""

# Controls the number of concurrent indexing jobs that can run at once
# INDEX_CONCURRENCY_MULTIPLE=

# Controls the polling interval for the web app
# NEXT_PUBLIC_POLLING_INTERVAL_MS=

# Controls the version of the web app
# NEXT_PUBLIC_SOURCEBOT_VERSION=

# CONFIG_MAX_REPOS_NO_TOKEN=
# SOURCEBOT_ROOT_DOMAIN=
# NODE_ENV=
15 changes: 11 additions & 4 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,13 +6,20 @@
"scripts": {
"build": "yarn workspaces run build",
"test": "yarn workspaces run test",
"dev": "yarn workspace @sourcebot/db prisma:migrate:dev && cross-env npm-run-all --print-label --parallel dev:zoekt dev:backend dev:web",
"dev:zoekt": "export PATH=\"$PWD/bin:$PATH\" && export SRC_TENANT_ENFORCEMENT_MODE=strict && zoekt-webserver -index .sourcebot/index -rpc",
"dev:backend": "yarn workspace @sourcebot/backend dev:watch",
"dev:web": "yarn workspace @sourcebot/web dev"

"dev": "yarn dev:prisma:migrate && npm-run-all --print-label --parallel dev:zoekt dev:backend dev:web",
"with-env": "cross-env PATH=\"$PWD/bin:$PATH\" dotenv -e .env.development -c --",
"dev:zoekt": "yarn with-env zoekt-webserver -index .sourcebot/index -rpc",
"dev:backend": "yarn with-env yarn workspace @sourcebot/backend dev:watch",
"dev:web": "yarn with-env yarn workspace @sourcebot/web dev",

"dev:prisma:migrate": "yarn with-env yarn workspace @sourcebot/db prisma:migrate:dev",
"dev:prisma:studio": "yarn with-env yarn workspace @sourcebot/db prisma:studio",
"dev:prisma:migrate:reset": "yarn with-env yarn workspace @sourcebot/db prisma:migrate:reset"
},
"devDependencies": {
"cross-env": "^7.0.3",
"dotenv-cli": "^8.0.0",
"npm-run-all": "^4.1.5"
}
}
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@
"type": "module",
"scripts": {
"dev:watch": "tsc-watch --preserveWatchOutput --onSuccess \"yarn dev --cacheDir ../../.sourcebot\"",
"dev": "export PATH=\"$PWD/../../bin:$PATH\" && export CTAGS_COMMAND=ctags && node ./dist/index.js",
"dev": "node ./dist/index.js",
"build": "tsc",
"test": "vitest --config ./vitest.config.ts"
},
Expand Down
9 changes: 6 additions & 3 deletions packages/backend/src/env.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,9 @@ import { createEnv } from "@t3-oss/env-core";
import { z } from "zod";
import dotenv from 'dotenv';

// Booleans are specified as 'true' or 'false' strings.
const booleanSchema = z.enum(["true", "false"]);

dotenv.config({
path: './.env',
});
Expand All@@ -15,18 +18,17 @@ export const env = createEnv({
server: {
SOURCEBOT_ENCRYPTION_KEY: z.string(),
SOURCEBOT_LOG_LEVEL: z.enum(["info", "debug", "warn", "error"]).default("info"),
SOURCEBOT_TELEMETRY_DISABLED: z.enum(["true", "false"]).default("false"),
SOURCEBOT_TELEMETRY_DISABLED: booleanSchema.default("false"),
SOURCEBOT_INSTALL_ID: z.string().default("unknown"),
SOURCEBOT_VERSION: z.string().default("unknown"),

POSTHOG_PAPIK: z.string().optional(),
POSTHOG_HOST: z.string().url().default('https://us.i.posthog.com'),

FALLBACK_GITHUB_TOKEN: z.string().optional(),
FALLBACK_GITLAB_TOKEN: z.string().optional(),
FALLBACK_GITEA_TOKEN: z.string().optional(),

REDIS_URL: z.string().url().optional().default("redis://localhost:6379"),
REDIS_URL: z.string().url(),

SENTRY_BACKEND_DSN: z.string().optional(),
SENTRY_ENVIRONMENT: z.string().optional(),
Expand All@@ -35,6 +37,7 @@ export const env = createEnv({
LOGTAIL_HOST: z.string().url().optional(),

INDEX_CONCURRENCY_MULTIPLE: z.number().optional(),
DATABASE_URL: z.string().url(),
},
runtimeEnv: process.env,
emptyStringAsUndefined: true,
Expand Down
27 changes: 27 additions & 0 deletions packages/backend/src/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,33 @@ import { AppContext } from "./types.js";
import { main } from "./main.js"
import { PrismaClient } from "@sourcebot/db";

// Register handler for normal exit
process.on('exit', (code) => {
console.log(`Process is exiting with code: ${code}`);
});

// Register handlers for abnormal terminations
process.on('SIGINT', () => {
console.log('Process interrupted (SIGINT)');
process.exit(130);
});

process.on('SIGTERM', () => {
console.log('Process terminated (SIGTERM)');
process.exit(143);
});

// Register handlers for uncaught exceptions and unhandled rejections
process.on('uncaughtException', (err) => {
console.log(`Uncaught exception: ${err.message}`);
process.exit(1);
});

process.on('unhandledRejection', (reason, promise) => {
console.log(`Unhandled rejection at: ${promise}, reason: ${reason}`);
process.exit(1);
});


const parser = new ArgumentParser({
description: "Sourcebot backend tool",
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/posthog.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,13 +8,13 @@ if (env.POSTHOG_PAPIK) {
posthog = new PostHog(
env.POSTHOG_PAPIK,
{
host: env.POSTHOG_HOST,
host: "https://us.i.posthog.com",
}
);
}

export function captureEvent<E extends PosthogEvent>(event: E, properties: PosthogEventMap[E]) {
if (env.SOURCEBOT_TELEMETRY_DISABLED) {
if (env.SOURCEBOT_TELEMETRY_DISABLED === 'true') {
return;
}

Expand Down
3 changes: 2 additions & 1 deletion packages/crypto/package.json
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
{
"name": "@sourcebot/crypto",
"main": "dist/index.js",
"version": "0.1.0",
"main": "dist/index.js",
"private": true,
"scripts": {
"build": "tsc",
"postinstall": "yarn build"
Expand Down
1 change: 0 additions & 1 deletion packages/web/src/app/posthogProvider.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,6 @@ export function PostHogProvider({ children, disabled }: PostHogProviderProps) {
posthog.init(env.NEXT_PUBLIC_POSTHOG_PAPIK, {
// @see next.config.mjs for path rewrites to the "/ingest" route.
api_host: "/ingest",
ui_host: env.NEXT_PUBLIC_POSTHOG_UI_HOST,
person_profiles: 'identified_only',
capture_pageview: false, // @nocheckin Disable automatic pageview capture if we're not in public demo mode
autocapture: false, // Disable automatic event capture
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/auth.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -76,7 +76,7 @@ export const getProviders = () => {
}));
}

if (env.AUTH_CREDENTIALS_LOGIN_ENABLED) {
if (env.AUTH_CREDENTIALS_LOGIN_ENABLED === 'true') {
providers.push(Credentials({
credentials: {
email: {},
Expand Down
11 changes: 6 additions & 5 deletions packages/web/src/env.mjs
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
import { createEnv } from "@t3-oss/env-nextjs";
import { z } from "zod";

// Booleans are specified as 'true' or 'false' strings.
const booleanSchema = z.enum(["true", "false"]);

export const env = createEnv({
server: {
// Zoekt
ZOEKT_WEBSERVER_URL: z.string().url().default('http://localhost:6070'),
ZOEKT_WEBSERVER_URL: z.string().url(),
SHARD_MAX_MATCH_COUNT: z.number().default(10000),
TOTAL_MAX_MATCH_COUNT: z.number().default(100000),

Expand All@@ -15,7 +18,7 @@ export const env = createEnv({
AUTH_GOOGLE_CLIENT_ID: z.string().optional(),
AUTH_GOOGLE_CLIENT_SECRET: z.string().optional(),
AUTH_URL: z.string().url(),
AUTH_CREDENTIALS_LOGIN_ENABLED: z.boolean().default(true),
AUTH_CREDENTIALS_LOGIN_ENABLED: booleanSchema.default('true'),

// Email
SMTP_CONNECTION_URL: z.string().url().optional(),
Expand All@@ -30,15 +33,14 @@ export const env = createEnv({
CONFIG_MAX_REPOS_NO_TOKEN: z.number().default(500),
SOURCEBOT_ROOT_DOMAIN: z.string().default("localhost:3000"),
NODE_ENV: z.enum(["development", "test", "production"]),
SOURCEBOT_TELEMETRY_DISABLED: z.enum(["true", "false"]).default("false"),
SOURCEBOT_TELEMETRY_DISABLED: booleanSchema.default('false'),
DATABASE_URL: z.string().url(),
},
// @NOTE: Make sure you destructure all client variables in the
// `experimental__runtimeEnv` block below.
client: {
// PostHog
NEXT_PUBLIC_POSTHOG_PAPIK: z.string().optional(),
NEXT_PUBLIC_POSTHOG_UI_HOST: z.string().url().default('https://us.posthog.com'),

// Misc
NEXT_PUBLIC_SOURCEBOT_VERSION: z.string().default('unknown'),
Expand All@@ -47,7 +49,6 @@ export const env = createEnv({
// For Next.js >= 13.4.4, you only need to destructure client variables:
experimental__runtimeEnv: {
NEXT_PUBLIC_POSTHOG_PAPIK: process.env.NEXT_PUBLIC_POSTHOG_PAPIK,
NEXT_PUBLIC_POSTHOG_UI_HOST: process.env.NEXT_PUBLIC_POSTHOG_UI_HOST,
NEXT_PUBLIC_SOURCEBOT_VERSION: process.env.NEXT_PUBLIC_SOURCEBOT_VERSION,
NEXT_PUBLIC_POLLING_INTERVAL_MS: process.env.NEXT_PUBLIC_POLLING_INTERVAL_MS,
},
Expand Down
19 changes: 17 additions & 2 deletions yarn.lock
Original file line numberDiff line numberDiff line change
Expand Up@@ -5096,7 +5096,7 @@ cross-spawn@^6.0.5:
shebang-command "^1.2.0"
which "^1.2.9"

cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.2, cross-spawn@^7.0.3, cross-spawn@^7.0.6:
version "7.0.6"
resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz"
integrity sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==
Expand DownExpand Up@@ -5382,7 +5382,22 @@ domutils@^3.0.1:
domelementtype "^2.3.0"
domhandler "^5.0.3"

dotenv@^16.3.1:
dotenv-cli@^8.0.0:
version "8.0.0"
resolved "https://registry.npmjs.org/dotenv-cli/-/dotenv-cli-8.0.0.tgz#cea1519f5a06c7372a1428fca4605fcf3d50e1cf"
integrity sha512-aLqYbK7xKOiTMIRf1lDPbI+Y+Ip/wo5k3eyp6ePysVaSqbyxjyK3dK35BTxG+rmd7djf5q2UPs4noPNH+cj0Qw==
dependencies:
cross-spawn "^7.0.6"
dotenv "^16.3.0"
dotenv-expand "^10.0.0"
minimist "^1.2.6"

dotenv-expand@^10.0.0:
version "10.0.0"
resolved "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-10.0.0.tgz#12605d00fb0af6d0a592e6558585784032e4ef37"
integrity sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==

dotenv@^16.3.0, dotenv@^16.3.1:
version "16.4.7"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.7.tgz#0e20c5b82950140aa99be360a8a5f52335f53c26"
integrity sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length \u003e 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
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
82 changes: 82 additions & 0 deletions .env.development
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@

# Prisma
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/postgres"

# Zoekt
ZOEKT_WEBSERVER_URL="http://localhost:6070"
# SHARD_MAX_MATCH_COUNT=10000
# TOTAL_MAX_MATCH_COUNT=100000
# The command to use for generating ctags.
CTAGS_COMMAND=ctags
# logging, strict
SRC_TENANT_ENFORCEMENT_MODE=strict

# Auth.JS
# You can generate a new secret with:
# openssl rand -base64 33
# @see: https://authjs.dev/getting-started/deployment#auth_secret
AUTH_SECRET="secret"
AUTH_URL="http://localhost:3000"
# AUTH_CREDENTIALS_LOGIN_ENABLED=true
# AUTH_GITHUB_CLIENT_ID=""
# AUTH_GITHUB_CLIENT_SECRET=""
# AUTH_GOOGLE_CLIENT_ID=""
# AUTH_GOOGLE_CLIENT_SECRET=""

# Email
# EMAIL_FROM="" # The from address for transactional emails.
# SMTP_CONNECTION_URL="" # The SMTP connection URL for transactional emails.

# PostHog
# POSTHOG_PAPIK=""
# NEXT_PUBLIC_POSTHOG_PAPIK=""

# Sentry
# SENTRY_BACKEND_DSN=""
# NEXT_PUBLIC_SENTRY_WEBAPP_DSN=""
# SENTRY_ENVIRONMENT="dev"
# NEXT_PUBLIC_SENTRY_ENVIRONMENT="dev"
# SENTRY_AUTH_TOKEN=

# Logtail
# LOGTAIL_TOKEN=""
# LOGTAIL_HOST=""

# Redis
REDIS_URL="redis://localhost:6379"

# Stripe
# STRIPE_SECRET_KEY: z.string().optional(),
# STRIPE_PRODUCT_ID: z.string().optional(),
# STRIPE_WEBHOOK_SECRET: z.string().optional(),

# Misc

# Set during docker build of application
# Used to disable env var validation at build time
# DOCKER_BUILD=1

# Generated using:
# openssl rand -base64 24
SOURCEBOT_ENCRYPTION_KEY="secret"

SOURCEBOT_LOG_LEVEL="debug" # valid values: info, debug, warn, error
SOURCEBOT_TELEMETRY_DISABLED=true # Disables telemetry collection

# Code-host fallback tokens
# FALLBACK_GITHUB_TOKEN=""
# FALLBACK_GITLAB_TOKEN=""
# FALLBACK_GITEA_TOKEN=""

# Controls the number of concurrent indexing jobs that can run at once
# INDEX_CONCURRENCY_MULTIPLE=

# Controls the polling interval for the web app
# NEXT_PUBLIC_POLLING_INTERVAL_MS=

# Controls the version of the web app
# NEXT_PUBLIC_SOURCEBOT_VERSION=

# CONFIG_MAX_REPOS_NO_TOKEN=
# SOURCEBOT_ROOT_DOMAIN=
# NODE_ENV=
15 changes: 11 additions & 4 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,13 +6,20 @@
"scripts": {
"build": "yarn workspaces run build",
"test": "yarn workspaces run test",
"dev": "yarn workspace @sourcebot/db prisma:migrate:dev && cross-env npm-run-all --print-label --parallel dev:zoekt dev:backend dev:web",
"dev:zoekt": "export PATH=\"$PWD/bin:$PATH\" && export SRC_TENANT_ENFORCEMENT_MODE=strict && zoekt-webserver -index .sourcebot/index -rpc",
"dev:backend": "yarn workspace @sourcebot/backend dev:watch",
"dev:web": "yarn workspace @sourcebot/web dev"

"dev": "yarn dev:prisma:migrate && npm-run-all --print-label --parallel dev:zoekt dev:backend dev:web",
"with-env": "cross-env PATH=\"$PWD/bin:$PATH\" dotenv -e .env.development -c --",
"dev:zoekt": "yarn with-env zoekt-webserver -index .sourcebot/index -rpc",
"dev:backend": "yarn with-env yarn workspace @sourcebot/backend dev:watch",
"dev:web": "yarn with-env yarn workspace @sourcebot/web dev",

"dev:prisma:migrate": "yarn with-env yarn workspace @sourcebot/db prisma:migrate:dev",
"dev:prisma:studio": "yarn with-env yarn workspace @sourcebot/db prisma:studio",
"dev:prisma:migrate:reset": "yarn with-env yarn workspace @sourcebot/db prisma:migrate:reset"
},
"devDependencies": {
"cross-env": "^7.0.3",
"dotenv-cli": "^8.0.0",
"npm-run-all": "^4.1.5"
}
}
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@
"type": "module",
"scripts": {
"dev:watch": "tsc-watch --preserveWatchOutput --onSuccess \"yarn dev --cacheDir ../../.sourcebot\"",
"dev": "export PATH=\"$PWD/../../bin:$PATH\" && export CTAGS_COMMAND=ctags && node ./dist/index.js",
"dev": "node ./dist/index.js",
"build": "tsc",
"test": "vitest --config ./vitest.config.ts"
},
Expand Down
9 changes: 6 additions & 3 deletions packages/backend/src/env.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,9 @@ import { createEnv } from "@t3-oss/env-core";
import { z } from "zod";
import dotenv from 'dotenv';

// Booleans are specified as 'true' or 'false' strings.
const booleanSchema = z.enum(["true", "false"]);

dotenv.config({
path: './.env',
});
Expand All@@ -15,18 +18,17 @@ export const env = createEnv({
server: {
SOURCEBOT_ENCRYPTION_KEY: z.string(),
SOURCEBOT_LOG_LEVEL: z.enum(["info", "debug", "warn", "error"]).default("info"),
SOURCEBOT_TELEMETRY_DISABLED: z.enum(["true", "false"]).default("false"),
SOURCEBOT_TELEMETRY_DISABLED: booleanSchema.default("false"),
SOURCEBOT_INSTALL_ID: z.string().default("unknown"),
SOURCEBOT_VERSION: z.string().default("unknown"),

POSTHOG_PAPIK: z.string().optional(),
POSTHOG_HOST: z.string().url().default('https://us.i.posthog.com'),

FALLBACK_GITHUB_TOKEN: z.string().optional(),
FALLBACK_GITLAB_TOKEN: z.string().optional(),
FALLBACK_GITEA_TOKEN: z.string().optional(),

REDIS_URL: z.string().url().optional().default("redis://localhost:6379"),
REDIS_URL: z.string().url(),

SENTRY_BACKEND_DSN: z.string().optional(),
SENTRY_ENVIRONMENT: z.string().optional(),
Expand All@@ -35,6 +37,7 @@ export const env = createEnv({
LOGTAIL_HOST: z.string().url().optional(),

INDEX_CONCURRENCY_MULTIPLE: z.number().optional(),
DATABASE_URL: z.string().url(),
},
runtimeEnv: process.env,
emptyStringAsUndefined: true,
Expand Down
27 changes: 27 additions & 0 deletions packages/backend/src/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,33 @@ import { AppContext } from "./types.js";
import { main } from "./main.js"
import { PrismaClient } from "@sourcebot/db";

// Register handler for normal exit
process.on('exit', (code) => {
console.log(`Process is exiting with code: ${code}`);
});

// Register handlers for abnormal terminations
process.on('SIGINT', () => {
console.log('Process interrupted (SIGINT)');
process.exit(130);
});

process.on('SIGTERM', () => {
console.log('Process terminated (SIGTERM)');
process.exit(143);
});

// Register handlers for uncaught exceptions and unhandled rejections
process.on('uncaughtException', (err) => {
console.log(`Uncaught exception: ${err.message}`);
process.exit(1);
});

process.on('unhandledRejection', (reason, promise) => {
console.log(`Unhandled rejection at: ${promise}, reason: ${reason}`);
process.exit(1);
});


const parser = new ArgumentParser({
description: "Sourcebot backend tool",
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/posthog.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,13 +8,13 @@ if (env.POSTHOG_PAPIK) {
posthog = new PostHog(
env.POSTHOG_PAPIK,
{
host: env.POSTHOG_HOST,
host: "https://us.i.posthog.com",
}
);
}

export function captureEvent<E extends PosthogEvent>(event: E, properties: PosthogEventMap[E]) {
if (env.SOURCEBOT_TELEMETRY_DISABLED) {
if (env.SOURCEBOT_TELEMETRY_DISABLED === 'true') {
return;
}

Expand Down
3 changes: 2 additions & 1 deletion packages/crypto/package.json
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
{
"name": "@sourcebot/crypto",
"main": "dist/index.js",
"version": "0.1.0",
"main": "dist/index.js",
"private": true,
"scripts": {
"build": "tsc",
"postinstall": "yarn build"
Expand Down
1 change: 0 additions & 1 deletion packages/web/src/app/posthogProvider.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,6 @@ export function PostHogProvider({ children, disabled }: PostHogProviderProps) {
posthog.init(env.NEXT_PUBLIC_POSTHOG_PAPIK, {
// @see next.config.mjs for path rewrites to the "/ingest" route.
api_host: "/ingest",
ui_host: env.NEXT_PUBLIC_POSTHOG_UI_HOST,
person_profiles: 'identified_only',
capture_pageview: false, // @nocheckin Disable automatic pageview capture if we're not in public demo mode
autocapture: false, // Disable automatic event capture
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/auth.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -76,7 +76,7 @@ export const getProviders = () => {
}));
}

if (env.AUTH_CREDENTIALS_LOGIN_ENABLED) {
if (env.AUTH_CREDENTIALS_LOGIN_ENABLED === 'true') {
providers.push(Credentials({
credentials: {
email: {},
Expand Down
11 changes: 6 additions & 5 deletions packages/web/src/env.mjs
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
import { createEnv } from "@t3-oss/env-nextjs";
import { z } from "zod";

// Booleans are specified as 'true' or 'false' strings.
const booleanSchema = z.enum(["true", "false"]);

export const env = createEnv({
server: {
// Zoekt
ZOEKT_WEBSERVER_URL: z.string().url().default('http://localhost:6070'),
ZOEKT_WEBSERVER_URL: z.string().url(),
SHARD_MAX_MATCH_COUNT: z.number().default(10000),
TOTAL_MAX_MATCH_COUNT: z.number().default(100000),

Expand All@@ -15,7 +18,7 @@ export const env = createEnv({
AUTH_GOOGLE_CLIENT_ID: z.string().optional(),
AUTH_GOOGLE_CLIENT_SECRET: z.string().optional(),
AUTH_URL: z.string().url(),
AUTH_CREDENTIALS_LOGIN_ENABLED: z.boolean().default(true),
AUTH_CREDENTIALS_LOGIN_ENABLED: booleanSchema.default('true'),

// Email
SMTP_CONNECTION_URL: z.string().url().optional(),
Expand All@@ -30,15 +33,14 @@ export const env = createEnv({
CONFIG_MAX_REPOS_NO_TOKEN: z.number().default(500),
SOURCEBOT_ROOT_DOMAIN: z.string().default("localhost:3000"),
NODE_ENV: z.enum(["development", "test", "production"]),
SOURCEBOT_TELEMETRY_DISABLED: z.enum(["true", "false"]).default("false"),
SOURCEBOT_TELEMETRY_DISABLED: booleanSchema.default('false'),
DATABASE_URL: z.string().url(),
},
// @NOTE: Make sure you destructure all client variables in the
// `experimental__runtimeEnv` block below.
client: {
// PostHog
NEXT_PUBLIC_POSTHOG_PAPIK: z.string().optional(),
NEXT_PUBLIC_POSTHOG_UI_HOST: z.string().url().default('https://us.posthog.com'),

// Misc
NEXT_PUBLIC_SOURCEBOT_VERSION: z.string().default('unknown'),
Expand All@@ -47,7 +49,6 @@ export const env = createEnv({
// For Next.js >= 13.4.4, you only need to destructure client variables:
experimental__runtimeEnv: {
NEXT_PUBLIC_POSTHOG_PAPIK: process.env.NEXT_PUBLIC_POSTHOG_PAPIK,
NEXT_PUBLIC_POSTHOG_UI_HOST: process.env.NEXT_PUBLIC_POSTHOG_UI_HOST,
NEXT_PUBLIC_SOURCEBOT_VERSION: process.env.NEXT_PUBLIC_SOURCEBOT_VERSION,
NEXT_PUBLIC_POLLING_INTERVAL_MS: process.env.NEXT_PUBLIC_POLLING_INTERVAL_MS,
},
Expand Down
19 changes: 17 additions & 2 deletions yarn.lock
Original file line numberDiff line numberDiff line change
Expand Up@@ -5096,7 +5096,7 @@ cross-spawn@^6.0.5:
shebang-command "^1.2.0"
which "^1.2.9"

cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.2, cross-spawn@^7.0.3, cross-spawn@^7.0.6:
version "7.0.6"
resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz"
integrity sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==
Expand DownExpand Up@@ -5382,7 +5382,22 @@ domutils@^3.0.1:
domelementtype "^2.3.0"
domhandler "^5.0.3"

dotenv@^16.3.1:
dotenv-cli@^8.0.0:
version "8.0.0"
resolved "https://registry.npmjs.org/dotenv-cli/-/dotenv-cli-8.0.0.tgz#cea1519f5a06c7372a1428fca4605fcf3d50e1cf"
integrity sha512-aLqYbK7xKOiTMIRf1lDPbI+Y+Ip/wo5k3eyp6ePysVaSqbyxjyK3dK35BTxG+rmd7djf5q2UPs4noPNH+cj0Qw==
dependencies:
cross-spawn "^7.0.6"
dotenv "^16.3.0"
dotenv-expand "^10.0.0"
minimist "^1.2.6"

dotenv-expand@^10.0.0:
version "10.0.0"
resolved "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-10.0.0.tgz#12605d00fb0af6d0a592e6558585784032e4ef37"
integrity sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==

dotenv@^16.3.0, dotenv@^16.3.1:
version "16.4.7"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.7.tgz#0e20c5b82950140aa99be360a8a5f52335f53c26"
integrity sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
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
82 changes: 82 additions & 0 deletions .env.development
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@

# Prisma
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/postgres"

# Zoekt
ZOEKT_WEBSERVER_URL="http://localhost:6070"
# SHARD_MAX_MATCH_COUNT=10000
# TOTAL_MAX_MATCH_COUNT=100000
# The command to use for generating ctags.
CTAGS_COMMAND=ctags
# logging, strict
SRC_TENANT_ENFORCEMENT_MODE=strict

# Auth.JS
# You can generate a new secret with:
# openssl rand -base64 33
# @see: https://authjs.dev/getting-started/deployment#auth_secret
AUTH_SECRET="secret"
AUTH_URL="http://localhost:3000"
# AUTH_CREDENTIALS_LOGIN_ENABLED=true
# AUTH_GITHUB_CLIENT_ID=""
# AUTH_GITHUB_CLIENT_SECRET=""
# AUTH_GOOGLE_CLIENT_ID=""
# AUTH_GOOGLE_CLIENT_SECRET=""

# Email
# EMAIL_FROM="" # The from address for transactional emails.
# SMTP_CONNECTION_URL="" # The SMTP connection URL for transactional emails.

# PostHog
# POSTHOG_PAPIK=""
# NEXT_PUBLIC_POSTHOG_PAPIK=""

# Sentry
# SENTRY_BACKEND_DSN=""
# NEXT_PUBLIC_SENTRY_WEBAPP_DSN=""
# SENTRY_ENVIRONMENT="dev"
# NEXT_PUBLIC_SENTRY_ENVIRONMENT="dev"
# SENTRY_AUTH_TOKEN=

# Logtail
# LOGTAIL_TOKEN=""
# LOGTAIL_HOST=""

# Redis
REDIS_URL="redis://localhost:6379"

# Stripe
# STRIPE_SECRET_KEY: z.string().optional(),
# STRIPE_PRODUCT_ID: z.string().optional(),
# STRIPE_WEBHOOK_SECRET: z.string().optional(),

# Misc

# Set during docker build of application
# Used to disable env var validation at build time
# DOCKER_BUILD=1

# Generated using:
# openssl rand -base64 24
SOURCEBOT_ENCRYPTION_KEY="secret"

SOURCEBOT_LOG_LEVEL="debug" # valid values: info, debug, warn, error
SOURCEBOT_TELEMETRY_DISABLED=true # Disables telemetry collection

# Code-host fallback tokens
# FALLBACK_GITHUB_TOKEN=""
# FALLBACK_GITLAB_TOKEN=""
# FALLBACK_GITEA_TOKEN=""

# Controls the number of concurrent indexing jobs that can run at once
# INDEX_CONCURRENCY_MULTIPLE=

# Controls the polling interval for the web app
# NEXT_PUBLIC_POLLING_INTERVAL_MS=

# Controls the version of the web app
# NEXT_PUBLIC_SOURCEBOT_VERSION=

# CONFIG_MAX_REPOS_NO_TOKEN=
# SOURCEBOT_ROOT_DOMAIN=
# NODE_ENV=
15 changes: 11 additions & 4 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,13 +6,20 @@
"scripts": {
"build": "yarn workspaces run build",
"test": "yarn workspaces run test",
"dev": "yarn workspace @sourcebot/db prisma:migrate:dev && cross-env npm-run-all --print-label --parallel dev:zoekt dev:backend dev:web",
"dev:zoekt": "export PATH=\"$PWD/bin:$PATH\" && export SRC_TENANT_ENFORCEMENT_MODE=strict && zoekt-webserver -index .sourcebot/index -rpc",
"dev:backend": "yarn workspace @sourcebot/backend dev:watch",
"dev:web": "yarn workspace @sourcebot/web dev"

"dev": "yarn dev:prisma:migrate && npm-run-all --print-label --parallel dev:zoekt dev:backend dev:web",
"with-env": "cross-env PATH=\"$PWD/bin:$PATH\" dotenv -e .env.development -c --",
"dev:zoekt": "yarn with-env zoekt-webserver -index .sourcebot/index -rpc",
"dev:backend": "yarn with-env yarn workspace @sourcebot/backend dev:watch",
"dev:web": "yarn with-env yarn workspace @sourcebot/web dev",

"dev:prisma:migrate": "yarn with-env yarn workspace @sourcebot/db prisma:migrate:dev",
"dev:prisma:studio": "yarn with-env yarn workspace @sourcebot/db prisma:studio",
"dev:prisma:migrate:reset": "yarn with-env yarn workspace @sourcebot/db prisma:migrate:reset"
},
"devDependencies": {
"cross-env": "^7.0.3",
"dotenv-cli": "^8.0.0",
"npm-run-all": "^4.1.5"
}
}
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@
"type": "module",
"scripts": {
"dev:watch": "tsc-watch --preserveWatchOutput --onSuccess \"yarn dev --cacheDir ../../.sourcebot\"",
"dev": "export PATH=\"$PWD/../../bin:$PATH\" && export CTAGS_COMMAND=ctags && node ./dist/index.js",
"dev": "node ./dist/index.js",
"build": "tsc",
"test": "vitest --config ./vitest.config.ts"
},
Expand Down
9 changes: 6 additions & 3 deletions packages/backend/src/env.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,9 @@ import { createEnv } from "@t3-oss/env-core";
import { z } from "zod";
import dotenv from 'dotenv';

// Booleans are specified as 'true' or 'false' strings.
const booleanSchema = z.enum(["true", "false"]);

dotenv.config({
path: './.env',
});
Expand All@@ -15,18 +18,17 @@ export const env = createEnv({
server: {
SOURCEBOT_ENCRYPTION_KEY: z.string(),
SOURCEBOT_LOG_LEVEL: z.enum(["info", "debug", "warn", "error"]).default("info"),
SOURCEBOT_TELEMETRY_DISABLED: z.enum(["true", "false"]).default("false"),
SOURCEBOT_TELEMETRY_DISABLED: booleanSchema.default("false"),
SOURCEBOT_INSTALL_ID: z.string().default("unknown"),
SOURCEBOT_VERSION: z.string().default("unknown"),

POSTHOG_PAPIK: z.string().optional(),
POSTHOG_HOST: z.string().url().default('https://us.i.posthog.com'),

FALLBACK_GITHUB_TOKEN: z.string().optional(),
FALLBACK_GITLAB_TOKEN: z.string().optional(),
FALLBACK_GITEA_TOKEN: z.string().optional(),

REDIS_URL: z.string().url().optional().default("redis://localhost:6379"),
REDIS_URL: z.string().url(),

SENTRY_BACKEND_DSN: z.string().optional(),
SENTRY_ENVIRONMENT: z.string().optional(),
Expand All@@ -35,6 +37,7 @@ export const env = createEnv({
LOGTAIL_HOST: z.string().url().optional(),

INDEX_CONCURRENCY_MULTIPLE: z.number().optional(),
DATABASE_URL: z.string().url(),
},
runtimeEnv: process.env,
emptyStringAsUndefined: true,
Expand Down
27 changes: 27 additions & 0 deletions packages/backend/src/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,33 @@ import { AppContext } from "./types.js";
import { main } from "./main.js"
import { PrismaClient } from "@sourcebot/db";

// Register handler for normal exit
process.on('exit', (code) => {
console.log(`Process is exiting with code: ${code}`);
});

// Register handlers for abnormal terminations
process.on('SIGINT', () => {
console.log('Process interrupted (SIGINT)');
process.exit(130);
});

process.on('SIGTERM', () => {
console.log('Process terminated (SIGTERM)');
process.exit(143);
});

// Register handlers for uncaught exceptions and unhandled rejections
process.on('uncaughtException', (err) => {
console.log(`Uncaught exception: ${err.message}`);
process.exit(1);
});

process.on('unhandledRejection', (reason, promise) => {
console.log(`Unhandled rejection at: ${promise}, reason: ${reason}`);
process.exit(1);
});


const parser = new ArgumentParser({
description: "Sourcebot backend tool",
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/posthog.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,13 +8,13 @@ if (env.POSTHOG_PAPIK) {
posthog = new PostHog(
env.POSTHOG_PAPIK,
{
host: env.POSTHOG_HOST,
host: "https://us.i.posthog.com",
}
);
}

export function captureEvent<E extends PosthogEvent>(event: E, properties: PosthogEventMap[E]) {
if (env.SOURCEBOT_TELEMETRY_DISABLED) {
if (env.SOURCEBOT_TELEMETRY_DISABLED === 'true') {
return;
}

Expand Down
3 changes: 2 additions & 1 deletion packages/crypto/package.json
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
{
"name": "@sourcebot/crypto",
"main": "dist/index.js",
"version": "0.1.0",
"main": "dist/index.js",
"private": true,
"scripts": {
"build": "tsc",
"postinstall": "yarn build"
Expand Down
1 change: 0 additions & 1 deletion packages/web/src/app/posthogProvider.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,6 @@ export function PostHogProvider({ children, disabled }: PostHogProviderProps) {
posthog.init(env.NEXT_PUBLIC_POSTHOG_PAPIK, {
// @see next.config.mjs for path rewrites to the "/ingest" route.
api_host: "/ingest",
ui_host: env.NEXT_PUBLIC_POSTHOG_UI_HOST,
person_profiles: 'identified_only',
capture_pageview: false, // @nocheckin Disable automatic pageview capture if we're not in public demo mode
autocapture: false, // Disable automatic event capture
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/auth.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -76,7 +76,7 @@ export const getProviders = () => {
}));
}

if (env.AUTH_CREDENTIALS_LOGIN_ENABLED) {
if (env.AUTH_CREDENTIALS_LOGIN_ENABLED === 'true') {
providers.push(Credentials({
credentials: {
email: {},
Expand Down
11 changes: 6 additions & 5 deletions packages/web/src/env.mjs
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
import { createEnv } from "@t3-oss/env-nextjs";
import { z } from "zod";

// Booleans are specified as 'true' or 'false' strings.
const booleanSchema = z.enum(["true", "false"]);

export const env = createEnv({
server: {
// Zoekt
ZOEKT_WEBSERVER_URL: z.string().url().default('http://localhost:6070'),
ZOEKT_WEBSERVER_URL: z.string().url(),
SHARD_MAX_MATCH_COUNT: z.number().default(10000),
TOTAL_MAX_MATCH_COUNT: z.number().default(100000),

Expand All@@ -15,7 +18,7 @@ export const env = createEnv({
AUTH_GOOGLE_CLIENT_ID: z.string().optional(),
AUTH_GOOGLE_CLIENT_SECRET: z.string().optional(),
AUTH_URL: z.string().url(),
AUTH_CREDENTIALS_LOGIN_ENABLED: z.boolean().default(true),
AUTH_CREDENTIALS_LOGIN_ENABLED: booleanSchema.default('true'),

// Email
SMTP_CONNECTION_URL: z.string().url().optional(),
Expand All@@ -30,15 +33,14 @@ export const env = createEnv({
CONFIG_MAX_REPOS_NO_TOKEN: z.number().default(500),
SOURCEBOT_ROOT_DOMAIN: z.string().default("localhost:3000"),
NODE_ENV: z.enum(["development", "test", "production"]),
SOURCEBOT_TELEMETRY_DISABLED: z.enum(["true", "false"]).default("false"),
SOURCEBOT_TELEMETRY_DISABLED: booleanSchema.default('false'),
DATABASE_URL: z.string().url(),
},
// @NOTE: Make sure you destructure all client variables in the
// `experimental__runtimeEnv` block below.
client: {
// PostHog
NEXT_PUBLIC_POSTHOG_PAPIK: z.string().optional(),
NEXT_PUBLIC_POSTHOG_UI_HOST: z.string().url().default('https://us.posthog.com'),

// Misc
NEXT_PUBLIC_SOURCEBOT_VERSION: z.string().default('unknown'),
Expand All@@ -47,7 +49,6 @@ export const env = createEnv({
// For Next.js >= 13.4.4, you only need to destructure client variables:
experimental__runtimeEnv: {
NEXT_PUBLIC_POSTHOG_PAPIK: process.env.NEXT_PUBLIC_POSTHOG_PAPIK,
NEXT_PUBLIC_POSTHOG_UI_HOST: process.env.NEXT_PUBLIC_POSTHOG_UI_HOST,
NEXT_PUBLIC_SOURCEBOT_VERSION: process.env.NEXT_PUBLIC_SOURCEBOT_VERSION,
NEXT_PUBLIC_POLLING_INTERVAL_MS: process.env.NEXT_PUBLIC_POLLING_INTERVAL_MS,
},
Expand Down
19 changes: 17 additions & 2 deletions yarn.lock
Original file line numberDiff line numberDiff line change
Expand Up@@ -5096,7 +5096,7 @@ cross-spawn@^6.0.5:
shebang-command "^1.2.0"
which "^1.2.9"

cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.2, cross-spawn@^7.0.3, cross-spawn@^7.0.6:
version "7.0.6"
resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz"
integrity sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==
Expand DownExpand Up@@ -5382,7 +5382,22 @@ domutils@^3.0.1:
domelementtype "^2.3.0"
domhandler "^5.0.3"

dotenv@^16.3.1:
dotenv-cli@^8.0.0:
version "8.0.0"
resolved "https://registry.npmjs.org/dotenv-cli/-/dotenv-cli-8.0.0.tgz#cea1519f5a06c7372a1428fca4605fcf3d50e1cf"
integrity sha512-aLqYbK7xKOiTMIRf1lDPbI+Y+Ip/wo5k3eyp6ePysVaSqbyxjyK3dK35BTxG+rmd7djf5q2UPs4noPNH+cj0Qw==
dependencies:
cross-spawn "^7.0.6"
dotenv "^16.3.0"
dotenv-expand "^10.0.0"
minimist "^1.2.6"

dotenv-expand@^10.0.0:
version "10.0.0"
resolved "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-10.0.0.tgz#12605d00fb0af6d0a592e6558585784032e4ef37"
integrity sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==

dotenv@^16.3.0, dotenv@^16.3.1:
version "16.4.7"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.7.tgz#0e20c5b82950140aa99be360a8a5f52335f53c26"
integrity sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
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
82 changes: 82 additions & 0 deletions .env.development
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@

# Prisma
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/postgres"

# Zoekt
ZOEKT_WEBSERVER_URL="http://localhost:6070"
# SHARD_MAX_MATCH_COUNT=10000
# TOTAL_MAX_MATCH_COUNT=100000
# The command to use for generating ctags.
CTAGS_COMMAND=ctags
# logging, strict
SRC_TENANT_ENFORCEMENT_MODE=strict

# Auth.JS
# You can generate a new secret with:
# openssl rand -base64 33
# @see: https://authjs.dev/getting-started/deployment#auth_secret
AUTH_SECRET="secret"
AUTH_URL="http://localhost:3000"
# AUTH_CREDENTIALS_LOGIN_ENABLED=true
# AUTH_GITHUB_CLIENT_ID=""
# AUTH_GITHUB_CLIENT_SECRET=""
# AUTH_GOOGLE_CLIENT_ID=""
# AUTH_GOOGLE_CLIENT_SECRET=""

# Email
# EMAIL_FROM="" # The from address for transactional emails.
# SMTP_CONNECTION_URL="" # The SMTP connection URL for transactional emails.

# PostHog
# POSTHOG_PAPIK=""
# NEXT_PUBLIC_POSTHOG_PAPIK=""

# Sentry
# SENTRY_BACKEND_DSN=""
# NEXT_PUBLIC_SENTRY_WEBAPP_DSN=""
# SENTRY_ENVIRONMENT="dev"
# NEXT_PUBLIC_SENTRY_ENVIRONMENT="dev"
# SENTRY_AUTH_TOKEN=

# Logtail
# LOGTAIL_TOKEN=""
# LOGTAIL_HOST=""

# Redis
REDIS_URL="redis://localhost:6379"

# Stripe
# STRIPE_SECRET_KEY: z.string().optional(),
# STRIPE_PRODUCT_ID: z.string().optional(),
# STRIPE_WEBHOOK_SECRET: z.string().optional(),

# Misc

# Set during docker build of application
# Used to disable env var validation at build time
# DOCKER_BUILD=1

# Generated using:
# openssl rand -base64 24
SOURCEBOT_ENCRYPTION_KEY="secret"

SOURCEBOT_LOG_LEVEL="debug" # valid values: info, debug, warn, error
SOURCEBOT_TELEMETRY_DISABLED=true # Disables telemetry collection

# Code-host fallback tokens
# FALLBACK_GITHUB_TOKEN=""
# FALLBACK_GITLAB_TOKEN=""
# FALLBACK_GITEA_TOKEN=""

# Controls the number of concurrent indexing jobs that can run at once
# INDEX_CONCURRENCY_MULTIPLE=

# Controls the polling interval for the web app
# NEXT_PUBLIC_POLLING_INTERVAL_MS=

# Controls the version of the web app
# NEXT_PUBLIC_SOURCEBOT_VERSION=

# CONFIG_MAX_REPOS_NO_TOKEN=
# SOURCEBOT_ROOT_DOMAIN=
# NODE_ENV=
15 changes: 11 additions & 4 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,13 +6,20 @@
"scripts": {
"build": "yarn workspaces run build",
"test": "yarn workspaces run test",
"dev": "yarn workspace @sourcebot/db prisma:migrate:dev && cross-env npm-run-all --print-label --parallel dev:zoekt dev:backend dev:web",
"dev:zoekt": "export PATH=\"$PWD/bin:$PATH\" && export SRC_TENANT_ENFORCEMENT_MODE=strict && zoekt-webserver -index .sourcebot/index -rpc",
"dev:backend": "yarn workspace @sourcebot/backend dev:watch",
"dev:web": "yarn workspace @sourcebot/web dev"

"dev": "yarn dev:prisma:migrate && npm-run-all --print-label --parallel dev:zoekt dev:backend dev:web",
"with-env": "cross-env PATH=\"$PWD/bin:$PATH\" dotenv -e .env.development -c --",
"dev:zoekt": "yarn with-env zoekt-webserver -index .sourcebot/index -rpc",
"dev:backend": "yarn with-env yarn workspace @sourcebot/backend dev:watch",
"dev:web": "yarn with-env yarn workspace @sourcebot/web dev",

"dev:prisma:migrate": "yarn with-env yarn workspace @sourcebot/db prisma:migrate:dev",
"dev:prisma:studio": "yarn with-env yarn workspace @sourcebot/db prisma:studio",
"dev:prisma:migrate:reset": "yarn with-env yarn workspace @sourcebot/db prisma:migrate:reset"
},
"devDependencies": {
"cross-env": "^7.0.3",
"dotenv-cli": "^8.0.0",
"npm-run-all": "^4.1.5"
}
}
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@
"type": "module",
"scripts": {
"dev:watch": "tsc-watch --preserveWatchOutput --onSuccess \"yarn dev --cacheDir ../../.sourcebot\"",
"dev": "export PATH=\"$PWD/../../bin:$PATH\" && export CTAGS_COMMAND=ctags && node ./dist/index.js",
"dev": "node ./dist/index.js",
"build": "tsc",
"test": "vitest --config ./vitest.config.ts"
},
Expand Down
9 changes: 6 additions & 3 deletions packages/backend/src/env.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,9 @@ import { createEnv } from "@t3-oss/env-core";
import { z } from "zod";
import dotenv from 'dotenv';

// Booleans are specified as 'true' or 'false' strings.
const booleanSchema = z.enum(["true", "false"]);

dotenv.config({
path: './.env',
});
Expand All@@ -15,18 +18,17 @@ export const env = createEnv({
server: {
SOURCEBOT_ENCRYPTION_KEY: z.string(),
SOURCEBOT_LOG_LEVEL: z.enum(["info", "debug", "warn", "error"]).default("info"),
SOURCEBOT_TELEMETRY_DISABLED: z.enum(["true", "false"]).default("false"),
SOURCEBOT_TELEMETRY_DISABLED: booleanSchema.default("false"),
SOURCEBOT_INSTALL_ID: z.string().default("unknown"),
SOURCEBOT_VERSION: z.string().default("unknown"),

POSTHOG_PAPIK: z.string().optional(),
POSTHOG_HOST: z.string().url().default('https://us.i.posthog.com'),

FALLBACK_GITHUB_TOKEN: z.string().optional(),
FALLBACK_GITLAB_TOKEN: z.string().optional(),
FALLBACK_GITEA_TOKEN: z.string().optional(),

REDIS_URL: z.string().url().optional().default("redis://localhost:6379"),
REDIS_URL: z.string().url(),

SENTRY_BACKEND_DSN: z.string().optional(),
SENTRY_ENVIRONMENT: z.string().optional(),
Expand All@@ -35,6 +37,7 @@ export const env = createEnv({
LOGTAIL_HOST: z.string().url().optional(),

INDEX_CONCURRENCY_MULTIPLE: z.number().optional(),
DATABASE_URL: z.string().url(),
},
runtimeEnv: process.env,
emptyStringAsUndefined: true,
Expand Down
27 changes: 27 additions & 0 deletions packages/backend/src/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,33 @@ import { AppContext } from "./types.js";
import { main } from "./main.js"
import { PrismaClient } from "@sourcebot/db";

// Register handler for normal exit
process.on('exit', (code) => {
console.log(`Process is exiting with code: ${code}`);
});

// Register handlers for abnormal terminations
process.on('SIGINT', () => {
console.log('Process interrupted (SIGINT)');
process.exit(130);
});

process.on('SIGTERM', () => {
console.log('Process terminated (SIGTERM)');
process.exit(143);
});

// Register handlers for uncaught exceptions and unhandled rejections
process.on('uncaughtException', (err) => {
console.log(`Uncaught exception: ${err.message}`);
process.exit(1);
});

process.on('unhandledRejection', (reason, promise) => {
console.log(`Unhandled rejection at: ${promise}, reason: ${reason}`);
process.exit(1);
});


const parser = new ArgumentParser({
description: "Sourcebot backend tool",
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/posthog.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,13 +8,13 @@ if (env.POSTHOG_PAPIK) {
posthog = new PostHog(
env.POSTHOG_PAPIK,
{
host: env.POSTHOG_HOST,
host: "https://us.i.posthog.com",
}
);
}

export function captureEvent<E extends PosthogEvent>(event: E, properties: PosthogEventMap[E]) {
if (env.SOURCEBOT_TELEMETRY_DISABLED) {
if (env.SOURCEBOT_TELEMETRY_DISABLED === 'true') {
return;
}

Expand Down
3 changes: 2 additions & 1 deletion packages/crypto/package.json
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
{
"name": "@sourcebot/crypto",
"main": "dist/index.js",
"version": "0.1.0",
"main": "dist/index.js",
"private": true,
"scripts": {
"build": "tsc",
"postinstall": "yarn build"
Expand Down
1 change: 0 additions & 1 deletion packages/web/src/app/posthogProvider.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,6 @@ export function PostHogProvider({ children, disabled }: PostHogProviderProps) {
posthog.init(env.NEXT_PUBLIC_POSTHOG_PAPIK, {
// @see next.config.mjs for path rewrites to the "/ingest" route.
api_host: "/ingest",
ui_host: env.NEXT_PUBLIC_POSTHOG_UI_HOST,
person_profiles: 'identified_only',
capture_pageview: false, // @nocheckin Disable automatic pageview capture if we're not in public demo mode
autocapture: false, // Disable automatic event capture
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/auth.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -76,7 +76,7 @@ export const getProviders = () => {
}));
}

if (env.AUTH_CREDENTIALS_LOGIN_ENABLED) {
if (env.AUTH_CREDENTIALS_LOGIN_ENABLED === 'true') {
providers.push(Credentials({
credentials: {
email: {},
Expand Down
11 changes: 6 additions & 5 deletions packages/web/src/env.mjs
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
import { createEnv } from "@t3-oss/env-nextjs";
import { z } from "zod";

// Booleans are specified as 'true' or 'false' strings.
const booleanSchema = z.enum(["true", "false"]);

export const env = createEnv({
server: {
// Zoekt
ZOEKT_WEBSERVER_URL: z.string().url().default('http://localhost:6070'),
ZOEKT_WEBSERVER_URL: z.string().url(),
SHARD_MAX_MATCH_COUNT: z.number().default(10000),
TOTAL_MAX_MATCH_COUNT: z.number().default(100000),

Expand All@@ -15,7 +18,7 @@ export const env = createEnv({
AUTH_GOOGLE_CLIENT_ID: z.string().optional(),
AUTH_GOOGLE_CLIENT_SECRET: z.string().optional(),
AUTH_URL: z.string().url(),
AUTH_CREDENTIALS_LOGIN_ENABLED: z.boolean().default(true),
AUTH_CREDENTIALS_LOGIN_ENABLED: booleanSchema.default('true'),

// Email
SMTP_CONNECTION_URL: z.string().url().optional(),
Expand All@@ -30,15 +33,14 @@ export const env = createEnv({
CONFIG_MAX_REPOS_NO_TOKEN: z.number().default(500),
SOURCEBOT_ROOT_DOMAIN: z.string().default("localhost:3000"),
NODE_ENV: z.enum(["development", "test", "production"]),
SOURCEBOT_TELEMETRY_DISABLED: z.enum(["true", "false"]).default("false"),
SOURCEBOT_TELEMETRY_DISABLED: booleanSchema.default('false'),
DATABASE_URL: z.string().url(),
},
// @NOTE: Make sure you destructure all client variables in the
// `experimental__runtimeEnv` block below.
client: {
// PostHog
NEXT_PUBLIC_POSTHOG_PAPIK: z.string().optional(),
NEXT_PUBLIC_POSTHOG_UI_HOST: z.string().url().default('https://us.posthog.com'),

// Misc
NEXT_PUBLIC_SOURCEBOT_VERSION: z.string().default('unknown'),
Expand All@@ -47,7 +49,6 @@ export const env = createEnv({
// For Next.js >= 13.4.4, you only need to destructure client variables:
experimental__runtimeEnv: {
NEXT_PUBLIC_POSTHOG_PAPIK: process.env.NEXT_PUBLIC_POSTHOG_PAPIK,
NEXT_PUBLIC_POSTHOG_UI_HOST: process.env.NEXT_PUBLIC_POSTHOG_UI_HOST,
NEXT_PUBLIC_SOURCEBOT_VERSION: process.env.NEXT_PUBLIC_SOURCEBOT_VERSION,
NEXT_PUBLIC_POLLING_INTERVAL_MS: process.env.NEXT_PUBLIC_POLLING_INTERVAL_MS,
},
Expand Down
19 changes: 17 additions & 2 deletions yarn.lock
Original file line numberDiff line numberDiff line change
Expand Up@@ -5096,7 +5096,7 @@ cross-spawn@^6.0.5:
shebang-command "^1.2.0"
which "^1.2.9"

cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.2, cross-spawn@^7.0.3, cross-spawn@^7.0.6:
version "7.0.6"
resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz"
integrity sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==
Expand DownExpand Up@@ -5382,7 +5382,22 @@ domutils@^3.0.1:
domelementtype "^2.3.0"
domhandler "^5.0.3"

dotenv@^16.3.1:
dotenv-cli@^8.0.0:
version "8.0.0"
resolved "https://registry.npmjs.org/dotenv-cli/-/dotenv-cli-8.0.0.tgz#cea1519f5a06c7372a1428fca4605fcf3d50e1cf"
integrity sha512-aLqYbK7xKOiTMIRf1lDPbI+Y+Ip/wo5k3eyp6ePysVaSqbyxjyK3dK35BTxG+rmd7djf5q2UPs4noPNH+cj0Qw==
dependencies:
cross-spawn "^7.0.6"
dotenv "^16.3.0"
dotenv-expand "^10.0.0"
minimist "^1.2.6"

dotenv-expand@^10.0.0:
version "10.0.0"
resolved "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-10.0.0.tgz#12605d00fb0af6d0a592e6558585784032e4ef37"
integrity sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==

dotenv@^16.3.0, dotenv@^16.3.1:
version "16.4.7"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.7.tgz#0e20c5b82950140aa99be360a8a5f52335f53c26"
integrity sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
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
82 changes: 82 additions & 0 deletions .env.development
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@

# Prisma
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/postgres"

# Zoekt
ZOEKT_WEBSERVER_URL="http://localhost:6070"
# SHARD_MAX_MATCH_COUNT=10000
# TOTAL_MAX_MATCH_COUNT=100000
# The command to use for generating ctags.
CTAGS_COMMAND=ctags
# logging, strict
SRC_TENANT_ENFORCEMENT_MODE=strict

# Auth.JS
# You can generate a new secret with:
# openssl rand -base64 33
# @see: https://authjs.dev/getting-started/deployment#auth_secret
AUTH_SECRET="secret"
AUTH_URL="http://localhost:3000"
# AUTH_CREDENTIALS_LOGIN_ENABLED=true
# AUTH_GITHUB_CLIENT_ID=""
# AUTH_GITHUB_CLIENT_SECRET=""
# AUTH_GOOGLE_CLIENT_ID=""
# AUTH_GOOGLE_CLIENT_SECRET=""

# Email
# EMAIL_FROM="" # The from address for transactional emails.
# SMTP_CONNECTION_URL="" # The SMTP connection URL for transactional emails.

# PostHog
# POSTHOG_PAPIK=""
# NEXT_PUBLIC_POSTHOG_PAPIK=""

# Sentry
# SENTRY_BACKEND_DSN=""
# NEXT_PUBLIC_SENTRY_WEBAPP_DSN=""
# SENTRY_ENVIRONMENT="dev"
# NEXT_PUBLIC_SENTRY_ENVIRONMENT="dev"
# SENTRY_AUTH_TOKEN=

# Logtail
# LOGTAIL_TOKEN=""
# LOGTAIL_HOST=""

# Redis
REDIS_URL="redis://localhost:6379"

# Stripe
# STRIPE_SECRET_KEY: z.string().optional(),
# STRIPE_PRODUCT_ID: z.string().optional(),
# STRIPE_WEBHOOK_SECRET: z.string().optional(),

# Misc

# Set during docker build of application
# Used to disable env var validation at build time
# DOCKER_BUILD=1

# Generated using:
# openssl rand -base64 24
SOURCEBOT_ENCRYPTION_KEY="secret"

SOURCEBOT_LOG_LEVEL="debug" # valid values: info, debug, warn, error
SOURCEBOT_TELEMETRY_DISABLED=true # Disables telemetry collection

# Code-host fallback tokens
# FALLBACK_GITHUB_TOKEN=""
# FALLBACK_GITLAB_TOKEN=""
# FALLBACK_GITEA_TOKEN=""

# Controls the number of concurrent indexing jobs that can run at once
# INDEX_CONCURRENCY_MULTIPLE=

# Controls the polling interval for the web app
# NEXT_PUBLIC_POLLING_INTERVAL_MS=

# Controls the version of the web app
# NEXT_PUBLIC_SOURCEBOT_VERSION=

# CONFIG_MAX_REPOS_NO_TOKEN=
# SOURCEBOT_ROOT_DOMAIN=
# NODE_ENV=
15 changes: 11 additions & 4 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,13 +6,20 @@
"scripts": {
"build": "yarn workspaces run build",
"test": "yarn workspaces run test",
"dev": "yarn workspace @sourcebot/db prisma:migrate:dev && cross-env npm-run-all --print-label --parallel dev:zoekt dev:backend dev:web",
"dev:zoekt": "export PATH=\"$PWD/bin:$PATH\" && export SRC_TENANT_ENFORCEMENT_MODE=strict && zoekt-webserver -index .sourcebot/index -rpc",
"dev:backend": "yarn workspace @sourcebot/backend dev:watch",
"dev:web": "yarn workspace @sourcebot/web dev"

"dev": "yarn dev:prisma:migrate && npm-run-all --print-label --parallel dev:zoekt dev:backend dev:web",
"with-env": "cross-env PATH=\"$PWD/bin:$PATH\" dotenv -e .env.development -c --",
"dev:zoekt": "yarn with-env zoekt-webserver -index .sourcebot/index -rpc",
"dev:backend": "yarn with-env yarn workspace @sourcebot/backend dev:watch",
"dev:web": "yarn with-env yarn workspace @sourcebot/web dev",

"dev:prisma:migrate": "yarn with-env yarn workspace @sourcebot/db prisma:migrate:dev",
"dev:prisma:studio": "yarn with-env yarn workspace @sourcebot/db prisma:studio",
"dev:prisma:migrate:reset": "yarn with-env yarn workspace @sourcebot/db prisma:migrate:reset"
},
"devDependencies": {
"cross-env": "^7.0.3",
"dotenv-cli": "^8.0.0",
"npm-run-all": "^4.1.5"
}
}
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@
"type": "module",
"scripts": {
"dev:watch": "tsc-watch --preserveWatchOutput --onSuccess \"yarn dev --cacheDir ../../.sourcebot\"",
"dev": "export PATH=\"$PWD/../../bin:$PATH\" && export CTAGS_COMMAND=ctags && node ./dist/index.js",
"dev": "node ./dist/index.js",
"build": "tsc",
"test": "vitest --config ./vitest.config.ts"
},
Expand Down
9 changes: 6 additions & 3 deletions packages/backend/src/env.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,9 @@ import { createEnv } from "@t3-oss/env-core";
import { z } from "zod";
import dotenv from 'dotenv';

// Booleans are specified as 'true' or 'false' strings.
const booleanSchema = z.enum(["true", "false"]);

dotenv.config({
path: './.env',
});
Expand All@@ -15,18 +18,17 @@ export const env = createEnv({
server: {
SOURCEBOT_ENCRYPTION_KEY: z.string(),
SOURCEBOT_LOG_LEVEL: z.enum(["info", "debug", "warn", "error"]).default("info"),
SOURCEBOT_TELEMETRY_DISABLED: z.enum(["true", "false"]).default("false"),
SOURCEBOT_TELEMETRY_DISABLED: booleanSchema.default("false"),
SOURCEBOT_INSTALL_ID: z.string().default("unknown"),
SOURCEBOT_VERSION: z.string().default("unknown"),

POSTHOG_PAPIK: z.string().optional(),
POSTHOG_HOST: z.string().url().default('https://us.i.posthog.com'),

FALLBACK_GITHUB_TOKEN: z.string().optional(),
FALLBACK_GITLAB_TOKEN: z.string().optional(),
FALLBACK_GITEA_TOKEN: z.string().optional(),

REDIS_URL: z.string().url().optional().default("redis://localhost:6379"),
REDIS_URL: z.string().url(),

SENTRY_BACKEND_DSN: z.string().optional(),
SENTRY_ENVIRONMENT: z.string().optional(),
Expand All@@ -35,6 +37,7 @@ export const env = createEnv({
LOGTAIL_HOST: z.string().url().optional(),

INDEX_CONCURRENCY_MULTIPLE: z.number().optional(),
DATABASE_URL: z.string().url(),
},
runtimeEnv: process.env,
emptyStringAsUndefined: true,
Expand Down
27 changes: 27 additions & 0 deletions packages/backend/src/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,33 @@ import { AppContext } from "./types.js";
import { main } from "./main.js"
import { PrismaClient } from "@sourcebot/db";

// Register handler for normal exit
process.on('exit', (code) => {
console.log(`Process is exiting with code: ${code}`);
});

// Register handlers for abnormal terminations
process.on('SIGINT', () => {
console.log('Process interrupted (SIGINT)');
process.exit(130);
});

process.on('SIGTERM', () => {
console.log('Process terminated (SIGTERM)');
process.exit(143);
});

// Register handlers for uncaught exceptions and unhandled rejections
process.on('uncaughtException', (err) => {
console.log(`Uncaught exception: ${err.message}`);
process.exit(1);
});

process.on('unhandledRejection', (reason, promise) => {
console.log(`Unhandled rejection at: ${promise}, reason: ${reason}`);
process.exit(1);
});


const parser = new ArgumentParser({
description: "Sourcebot backend tool",
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/posthog.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,13 +8,13 @@ if (env.POSTHOG_PAPIK) {
posthog = new PostHog(
env.POSTHOG_PAPIK,
{
host: env.POSTHOG_HOST,
host: "https://us.i.posthog.com",
}
);
}

export function captureEvent<E extends PosthogEvent>(event: E, properties: PosthogEventMap[E]) {
if (env.SOURCEBOT_TELEMETRY_DISABLED) {
if (env.SOURCEBOT_TELEMETRY_DISABLED === 'true') {
return;
}

Expand Down
3 changes: 2 additions & 1 deletion packages/crypto/package.json
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
{
"name": "@sourcebot/crypto",
"main": "dist/index.js",
"version": "0.1.0",
"main": "dist/index.js",
"private": true,
"scripts": {
"build": "tsc",
"postinstall": "yarn build"
Expand Down
1 change: 0 additions & 1 deletion packages/web/src/app/posthogProvider.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,6 @@ export function PostHogProvider({ children, disabled }: PostHogProviderProps) {
posthog.init(env.NEXT_PUBLIC_POSTHOG_PAPIK, {
// @see next.config.mjs for path rewrites to the "/ingest" route.
api_host: "/ingest",
ui_host: env.NEXT_PUBLIC_POSTHOG_UI_HOST,
person_profiles: 'identified_only',
capture_pageview: false, // @nocheckin Disable automatic pageview capture if we're not in public demo mode
autocapture: false, // Disable automatic event capture
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/auth.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -76,7 +76,7 @@ export const getProviders = () => {
}));
}

if (env.AUTH_CREDENTIALS_LOGIN_ENABLED) {
if (env.AUTH_CREDENTIALS_LOGIN_ENABLED === 'true') {
providers.push(Credentials({
credentials: {
email: {},
Expand Down
11 changes: 6 additions & 5 deletions packages/web/src/env.mjs
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
import { createEnv } from "@t3-oss/env-nextjs";
import { z } from "zod";

// Booleans are specified as 'true' or 'false' strings.
const booleanSchema = z.enum(["true", "false"]);

export const env = createEnv({
server: {
// Zoekt
ZOEKT_WEBSERVER_URL: z.string().url().default('http://localhost:6070'),
ZOEKT_WEBSERVER_URL: z.string().url(),
SHARD_MAX_MATCH_COUNT: z.number().default(10000),
TOTAL_MAX_MATCH_COUNT: z.number().default(100000),

Expand All@@ -15,7 +18,7 @@ export const env = createEnv({
AUTH_GOOGLE_CLIENT_ID: z.string().optional(),
AUTH_GOOGLE_CLIENT_SECRET: z.string().optional(),
AUTH_URL: z.string().url(),
AUTH_CREDENTIALS_LOGIN_ENABLED: z.boolean().default(true),
AUTH_CREDENTIALS_LOGIN_ENABLED: booleanSchema.default('true'),

// Email
SMTP_CONNECTION_URL: z.string().url().optional(),
Expand All@@ -30,15 +33,14 @@ export const env = createEnv({
CONFIG_MAX_REPOS_NO_TOKEN: z.number().default(500),
SOURCEBOT_ROOT_DOMAIN: z.string().default("localhost:3000"),
NODE_ENV: z.enum(["development", "test", "production"]),
SOURCEBOT_TELEMETRY_DISABLED: z.enum(["true", "false"]).default("false"),
SOURCEBOT_TELEMETRY_DISABLED: booleanSchema.default('false'),
DATABASE_URL: z.string().url(),
},
// @NOTE: Make sure you destructure all client variables in the
// `experimental__runtimeEnv` block below.
client: {
// PostHog
NEXT_PUBLIC_POSTHOG_PAPIK: z.string().optional(),
NEXT_PUBLIC_POSTHOG_UI_HOST: z.string().url().default('https://us.posthog.com'),

// Misc
NEXT_PUBLIC_SOURCEBOT_VERSION: z.string().default('unknown'),
Expand All@@ -47,7 +49,6 @@ export const env = createEnv({
// For Next.js >= 13.4.4, you only need to destructure client variables:
experimental__runtimeEnv: {
NEXT_PUBLIC_POSTHOG_PAPIK: process.env.NEXT_PUBLIC_POSTHOG_PAPIK,
NEXT_PUBLIC_POSTHOG_UI_HOST: process.env.NEXT_PUBLIC_POSTHOG_UI_HOST,
NEXT_PUBLIC_SOURCEBOT_VERSION: process.env.NEXT_PUBLIC_SOURCEBOT_VERSION,
NEXT_PUBLIC_POLLING_INTERVAL_MS: process.env.NEXT_PUBLIC_POLLING_INTERVAL_MS,
},
Expand Down
19 changes: 17 additions & 2 deletions yarn.lock
Original file line numberDiff line numberDiff line change
Expand Up@@ -5096,7 +5096,7 @@ cross-spawn@^6.0.5:
shebang-command "^1.2.0"
which "^1.2.9"

cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.2, cross-spawn@^7.0.3, cross-spawn@^7.0.6:
version "7.0.6"
resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz"
integrity sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==
Expand DownExpand Up@@ -5382,7 +5382,22 @@ domutils@^3.0.1:
domelementtype "^2.3.0"
domhandler "^5.0.3"

dotenv@^16.3.1:
dotenv-cli@^8.0.0:
version "8.0.0"
resolved "https://registry.npmjs.org/dotenv-cli/-/dotenv-cli-8.0.0.tgz#cea1519f5a06c7372a1428fca4605fcf3d50e1cf"
integrity sha512-aLqYbK7xKOiTMIRf1lDPbI+Y+Ip/wo5k3eyp6ePysVaSqbyxjyK3dK35BTxG+rmd7djf5q2UPs4noPNH+cj0Qw==
dependencies:
cross-spawn "^7.0.6"
dotenv "^16.3.0"
dotenv-expand "^10.0.0"
minimist "^1.2.6"

dotenv-expand@^10.0.0:
version "10.0.0"
resolved "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-10.0.0.tgz#12605d00fb0af6d0a592e6558585784032e4ef37"
integrity sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==

dotenv@^16.3.0, dotenv@^16.3.1:
version "16.4.7"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.7.tgz#0e20c5b82950140aa99be360a8a5f52335f53c26"
integrity sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
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
82 changes: 82 additions & 0 deletions .env.development
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@

# Prisma
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/postgres"

# Zoekt
ZOEKT_WEBSERVER_URL="http://localhost:6070"
# SHARD_MAX_MATCH_COUNT=10000
# TOTAL_MAX_MATCH_COUNT=100000
# The command to use for generating ctags.
CTAGS_COMMAND=ctags
# logging, strict
SRC_TENANT_ENFORCEMENT_MODE=strict

# Auth.JS
# You can generate a new secret with:
# openssl rand -base64 33
# @see: https://authjs.dev/getting-started/deployment#auth_secret
AUTH_SECRET="secret"
AUTH_URL="http://localhost:3000"
# AUTH_CREDENTIALS_LOGIN_ENABLED=true
# AUTH_GITHUB_CLIENT_ID=""
# AUTH_GITHUB_CLIENT_SECRET=""
# AUTH_GOOGLE_CLIENT_ID=""
# AUTH_GOOGLE_CLIENT_SECRET=""

# Email
# EMAIL_FROM="" # The from address for transactional emails.
# SMTP_CONNECTION_URL="" # The SMTP connection URL for transactional emails.

# PostHog
# POSTHOG_PAPIK=""
# NEXT_PUBLIC_POSTHOG_PAPIK=""

# Sentry
# SENTRY_BACKEND_DSN=""
# NEXT_PUBLIC_SENTRY_WEBAPP_DSN=""
# SENTRY_ENVIRONMENT="dev"
# NEXT_PUBLIC_SENTRY_ENVIRONMENT="dev"
# SENTRY_AUTH_TOKEN=

# Logtail
# LOGTAIL_TOKEN=""
# LOGTAIL_HOST=""

# Redis
REDIS_URL="redis://localhost:6379"

# Stripe
# STRIPE_SECRET_KEY: z.string().optional(),
# STRIPE_PRODUCT_ID: z.string().optional(),
# STRIPE_WEBHOOK_SECRET: z.string().optional(),

# Misc

# Set during docker build of application
# Used to disable env var validation at build time
# DOCKER_BUILD=1

# Generated using:
# openssl rand -base64 24
SOURCEBOT_ENCRYPTION_KEY="secret"

SOURCEBOT_LOG_LEVEL="debug" # valid values: info, debug, warn, error
SOURCEBOT_TELEMETRY_DISABLED=true # Disables telemetry collection

# Code-host fallback tokens
# FALLBACK_GITHUB_TOKEN=""
# FALLBACK_GITLAB_TOKEN=""
# FALLBACK_GITEA_TOKEN=""

# Controls the number of concurrent indexing jobs that can run at once
# INDEX_CONCURRENCY_MULTIPLE=

# Controls the polling interval for the web app
# NEXT_PUBLIC_POLLING_INTERVAL_MS=

# Controls the version of the web app
# NEXT_PUBLIC_SOURCEBOT_VERSION=

# CONFIG_MAX_REPOS_NO_TOKEN=
# SOURCEBOT_ROOT_DOMAIN=
# NODE_ENV=
15 changes: 11 additions & 4 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,13 +6,20 @@
"scripts": {
"build": "yarn workspaces run build",
"test": "yarn workspaces run test",
"dev": "yarn workspace @sourcebot/db prisma:migrate:dev && cross-env npm-run-all --print-label --parallel dev:zoekt dev:backend dev:web",
"dev:zoekt": "export PATH=\"$PWD/bin:$PATH\" && export SRC_TENANT_ENFORCEMENT_MODE=strict && zoekt-webserver -index .sourcebot/index -rpc",
"dev:backend": "yarn workspace @sourcebot/backend dev:watch",
"dev:web": "yarn workspace @sourcebot/web dev"

"dev": "yarn dev:prisma:migrate && npm-run-all --print-label --parallel dev:zoekt dev:backend dev:web",
"with-env": "cross-env PATH=\"$PWD/bin:$PATH\" dotenv -e .env.development -c --",
"dev:zoekt": "yarn with-env zoekt-webserver -index .sourcebot/index -rpc",
"dev:backend": "yarn with-env yarn workspace @sourcebot/backend dev:watch",
"dev:web": "yarn with-env yarn workspace @sourcebot/web dev",

"dev:prisma:migrate": "yarn with-env yarn workspace @sourcebot/db prisma:migrate:dev",
"dev:prisma:studio": "yarn with-env yarn workspace @sourcebot/db prisma:studio",
"dev:prisma:migrate:reset": "yarn with-env yarn workspace @sourcebot/db prisma:migrate:reset"
},
"devDependencies": {
"cross-env": "^7.0.3",
"dotenv-cli": "^8.0.0",
"npm-run-all": "^4.1.5"
}
}
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@
"type": "module",
"scripts": {
"dev:watch": "tsc-watch --preserveWatchOutput --onSuccess \"yarn dev --cacheDir ../../.sourcebot\"",
"dev": "export PATH=\"$PWD/../../bin:$PATH\" && export CTAGS_COMMAND=ctags && node ./dist/index.js",
"dev": "node ./dist/index.js",
"build": "tsc",
"test": "vitest --config ./vitest.config.ts"
},
Expand Down
9 changes: 6 additions & 3 deletions packages/backend/src/env.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,9 @@ import { createEnv } from "@t3-oss/env-core";
import { z } from "zod";
import dotenv from 'dotenv';

// Booleans are specified as 'true' or 'false' strings.
const booleanSchema = z.enum(["true", "false"]);

dotenv.config({
path: './.env',
});
Expand All@@ -15,18 +18,17 @@ export const env = createEnv({
server: {
SOURCEBOT_ENCRYPTION_KEY: z.string(),
SOURCEBOT_LOG_LEVEL: z.enum(["info", "debug", "warn", "error"]).default("info"),
SOURCEBOT_TELEMETRY_DISABLED: z.enum(["true", "false"]).default("false"),
SOURCEBOT_TELEMETRY_DISABLED: booleanSchema.default("false"),
SOURCEBOT_INSTALL_ID: z.string().default("unknown"),
SOURCEBOT_VERSION: z.string().default("unknown"),

POSTHOG_PAPIK: z.string().optional(),
POSTHOG_HOST: z.string().url().default('https://us.i.posthog.com'),

FALLBACK_GITHUB_TOKEN: z.string().optional(),
FALLBACK_GITLAB_TOKEN: z.string().optional(),
FALLBACK_GITEA_TOKEN: z.string().optional(),

REDIS_URL: z.string().url().optional().default("redis://localhost:6379"),
REDIS_URL: z.string().url(),

SENTRY_BACKEND_DSN: z.string().optional(),
SENTRY_ENVIRONMENT: z.string().optional(),
Expand All@@ -35,6 +37,7 @@ export const env = createEnv({
LOGTAIL_HOST: z.string().url().optional(),

INDEX_CONCURRENCY_MULTIPLE: z.number().optional(),
DATABASE_URL: z.string().url(),
},
runtimeEnv: process.env,
emptyStringAsUndefined: true,
Expand Down
27 changes: 27 additions & 0 deletions packages/backend/src/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,33 @@ import { AppContext } from "./types.js";
import { main } from "./main.js"
import { PrismaClient } from "@sourcebot/db";

// Register handler for normal exit
process.on('exit', (code) => {
console.log(`Process is exiting with code: ${code}`);
});

// Register handlers for abnormal terminations
process.on('SIGINT', () => {
console.log('Process interrupted (SIGINT)');
process.exit(130);
});

process.on('SIGTERM', () => {
console.log('Process terminated (SIGTERM)');
process.exit(143);
});

// Register handlers for uncaught exceptions and unhandled rejections
process.on('uncaughtException', (err) => {
console.log(`Uncaught exception: ${err.message}`);
process.exit(1);
});

process.on('unhandledRejection', (reason, promise) => {
console.log(`Unhandled rejection at: ${promise}, reason: ${reason}`);
process.exit(1);
});


const parser = new ArgumentParser({
description: "Sourcebot backend tool",
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/posthog.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,13 +8,13 @@ if (env.POSTHOG_PAPIK) {
posthog = new PostHog(
env.POSTHOG_PAPIK,
{
host: env.POSTHOG_HOST,
host: "https://us.i.posthog.com",
}
);
}

export function captureEvent<E extends PosthogEvent>(event: E, properties: PosthogEventMap[E]) {
if (env.SOURCEBOT_TELEMETRY_DISABLED) {
if (env.SOURCEBOT_TELEMETRY_DISABLED === 'true') {
return;
}

Expand Down
3 changes: 2 additions & 1 deletion packages/crypto/package.json
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
{
"name": "@sourcebot/crypto",
"main": "dist/index.js",
"version": "0.1.0",
"main": "dist/index.js",
"private": true,
"scripts": {
"build": "tsc",
"postinstall": "yarn build"
Expand Down
1 change: 0 additions & 1 deletion packages/web/src/app/posthogProvider.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,6 @@ export function PostHogProvider({ children, disabled }: PostHogProviderProps) {
posthog.init(env.NEXT_PUBLIC_POSTHOG_PAPIK, {
// @see next.config.mjs for path rewrites to the "/ingest" route.
api_host: "/ingest",
ui_host: env.NEXT_PUBLIC_POSTHOG_UI_HOST,
person_profiles: 'identified_only',
capture_pageview: false, // @nocheckin Disable automatic pageview capture if we're not in public demo mode
autocapture: false, // Disable automatic event capture
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/auth.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -76,7 +76,7 @@ export const getProviders = () => {
}));
}

if (env.AUTH_CREDENTIALS_LOGIN_ENABLED) {
if (env.AUTH_CREDENTIALS_LOGIN_ENABLED === 'true') {
providers.push(Credentials({
credentials: {
email: {},
Expand Down
11 changes: 6 additions & 5 deletions packages/web/src/env.mjs
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
import { createEnv } from "@t3-oss/env-nextjs";
import { z } from "zod";

// Booleans are specified as 'true' or 'false' strings.
const booleanSchema = z.enum(["true", "false"]);

export const env = createEnv({
server: {
// Zoekt
ZOEKT_WEBSERVER_URL: z.string().url().default('http://localhost:6070'),
ZOEKT_WEBSERVER_URL: z.string().url(),
SHARD_MAX_MATCH_COUNT: z.number().default(10000),
TOTAL_MAX_MATCH_COUNT: z.number().default(100000),

Expand All@@ -15,7 +18,7 @@ export const env = createEnv({
AUTH_GOOGLE_CLIENT_ID: z.string().optional(),
AUTH_GOOGLE_CLIENT_SECRET: z.string().optional(),
AUTH_URL: z.string().url(),
AUTH_CREDENTIALS_LOGIN_ENABLED: z.boolean().default(true),
AUTH_CREDENTIALS_LOGIN_ENABLED: booleanSchema.default('true'),

// Email
SMTP_CONNECTION_URL: z.string().url().optional(),
Expand All@@ -30,15 +33,14 @@ export const env = createEnv({
CONFIG_MAX_REPOS_NO_TOKEN: z.number().default(500),
SOURCEBOT_ROOT_DOMAIN: z.string().default("localhost:3000"),
NODE_ENV: z.enum(["development", "test", "production"]),
SOURCEBOT_TELEMETRY_DISABLED: z.enum(["true", "false"]).default("false"),
SOURCEBOT_TELEMETRY_DISABLED: booleanSchema.default('false'),
DATABASE_URL: z.string().url(),
},
// @NOTE: Make sure you destructure all client variables in the
// `experimental__runtimeEnv` block below.
client: {
// PostHog
NEXT_PUBLIC_POSTHOG_PAPIK: z.string().optional(),
NEXT_PUBLIC_POSTHOG_UI_HOST: z.string().url().default('https://us.posthog.com'),

// Misc
NEXT_PUBLIC_SOURCEBOT_VERSION: z.string().default('unknown'),
Expand All@@ -47,7 +49,6 @@ export const env = createEnv({
// For Next.js >= 13.4.4, you only need to destructure client variables:
experimental__runtimeEnv: {
NEXT_PUBLIC_POSTHOG_PAPIK: process.env.NEXT_PUBLIC_POSTHOG_PAPIK,
NEXT_PUBLIC_POSTHOG_UI_HOST: process.env.NEXT_PUBLIC_POSTHOG_UI_HOST,
NEXT_PUBLIC_SOURCEBOT_VERSION: process.env.NEXT_PUBLIC_SOURCEBOT_VERSION,
NEXT_PUBLIC_POLLING_INTERVAL_MS: process.env.NEXT_PUBLIC_POLLING_INTERVAL_MS,
},
Expand Down
19 changes: 17 additions & 2 deletions yarn.lock
Original file line numberDiff line numberDiff line change
Expand Up@@ -5096,7 +5096,7 @@ cross-spawn@^6.0.5:
shebang-command "^1.2.0"
which "^1.2.9"

cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.2, cross-spawn@^7.0.3, cross-spawn@^7.0.6:
version "7.0.6"
resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz"
integrity sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==
Expand DownExpand Up@@ -5382,7 +5382,22 @@ domutils@^3.0.1:
domelementtype "^2.3.0"
domhandler "^5.0.3"

dotenv@^16.3.1:
dotenv-cli@^8.0.0:
version "8.0.0"
resolved "https://registry.npmjs.org/dotenv-cli/-/dotenv-cli-8.0.0.tgz#cea1519f5a06c7372a1428fca4605fcf3d50e1cf"
integrity sha512-aLqYbK7xKOiTMIRf1lDPbI+Y+Ip/wo5k3eyp6ePysVaSqbyxjyK3dK35BTxG+rmd7djf5q2UPs4noPNH+cj0Qw==
dependencies:
cross-spawn "^7.0.6"
dotenv "^16.3.0"
dotenv-expand "^10.0.0"
minimist "^1.2.6"

dotenv-expand@^10.0.0:
version "10.0.0"
resolved "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-10.0.0.tgz#12605d00fb0af6d0a592e6558585784032e4ef37"
integrity sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==

dotenv@^16.3.0, dotenv@^16.3.1:
version "16.4.7"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.7.tgz#0e20c5b82950140aa99be360a8a5f52335f53c26"
integrity sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==
Expand Down