Skip to content

v3 effort #158

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 247 commits into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
247 commits
Select commit Hold shift + click to select a range
15b9e77
SQL Database (#157)
brendan-kellam Jan 14, 2025
95f637f
point zoekt to v3 branch
brendan-kellam Jan 14, 2025
3c3140e
bump zoekt version
msukkari Jan 14, 2025
553f5d2
Add tenant ID concept into web app and backend (#160)
msukkari Jan 15, 2025
bd027f7
bump zoekt version
msukkari Jan 15, 2025
7029aa7
parallelize repo indexing (#163)
msukkari Jan 15, 2025
6cf10b4
Authentication (#164)
brendan-kellam Jan 16, 2025
5d253ff
Add Org table (#167)
brendan-kellam Jan 17, 2025
a5091fb
Move logout button & profile picture into settings dropdown (#172)
brendan-kellam Jan 19, 2025
7c6adf1
Multi tenancy support in config syncer (#171)
msukkari Jan 21, 2025
738bbaa
add tenant mode support in docker container:
msukkari Jan 21, 2025
9c120c6
Organization switching & active org management (#173)
brendan-kellam Jan 21, 2025
8a3521b
updated syncedAt date after config sync:
msukkari Jan 23, 2025
a5006c5
Migrate to postgres (#174)
msukkari Jan 23, 2025
0322cd8
Connection creation form (#175)
brendan-kellam Jan 23, 2025
ed0d28a
fix issue with yarn dev startup
brendan-kellam Jan 23, 2025
78c9111
init (#176)
brendan-kellam Jan 23, 2025
bae7ca3
Add `@sourcebot/schemas` package (#177)
brendan-kellam Jan 24, 2025
dd8ff6e
Connection management (#178)
brendan-kellam Jan 24, 2025
31114a9
add concept of secrets (#180)
msukkari Jan 27, 2025
a88f9e6
bump zoekt version
msukkari Jan 28, 2025
75d4189
enforce tenancy on search and repo listing endpoints (#181)
msukkari Jan 28, 2025
dffbbae
adds garbage collection for repos (#182)
msukkari Jan 29, 2025
9946901
add initial logic for staging environment
msukkari Jan 30, 2025
f92acc0
try to move encryption key env decleration in docker file to fix buil…
msukkari Jan 30, 2025
92530a7
switch encryption key as build arg to se if that fixes build issues
msukkari Jan 30, 2025
2b6125b
add deployment action for staging image
msukkari Jan 30, 2025
d37a969
try using mac github action runners instead
msukkari Jan 30, 2025
d513f93
switch to using arm64 runners on arm64 build
msukkari Jan 30, 2025
bb4ff37
change workflow names to fix trigger issue
msukkari Jan 30, 2025
22e0096
trigger staging actions to see if it works
msukkari Jan 31, 2025
7b6226b
fix working directory typo and pray it doesnt push to prod
msukkari Jan 31, 2025
44dd53f
checkout v3 when deploying staging
msukkari Jan 31, 2025
4e7ac93
try to change into the staging dir manuall
msukkari Jan 31, 2025
94908c0
dummy commit to trigger v3 workflows to test
msukkari Jan 31, 2025
4d4988d
update staging deploy script to match new version in main
msukkari Jan 31, 2025
829eede
reference proper image:tag in staging fly config
msukkari Jan 31, 2025
afff36f
update staging fly config to point to ghcr
msukkari Jan 31, 2025
846d73b
Connection management (#183)
brendan-kellam Feb 4, 2025
9055018
add invite system and google oauth provider (#185)
msukkari Feb 10, 2025
70f7729
fix reference to header component in connections
msukkari Feb 10, 2025
5858e31
add google logo to google oauth
msukkari Feb 10, 2025
7da8a7f
fix web build errors
msukkari Feb 10, 2025
775138c
bump staging resources
msukkari Feb 10, 2025
568ded8
change staging cpu to perf
msukkari Feb 11, 2025
23f3c60
add side bar nav in settings page
msukkari Feb 11, 2025
04991fd
improve styling of members page
msukkari Feb 11, 2025
fde2179
wip adding stripe checkout button
msukkari Feb 11, 2025
9665f14
wip onboarding flow
msukkari Feb 12, 2025
33ae585
add stripe subscription id to org
msukkari Feb 12, 2025
e7f8f51
save stripe session id and add manage subscription button in settings
msukkari Feb 12, 2025
3ad6c2d
properly block access to pages if user isn't in an org
msukkari Feb 12, 2025
0a79f7c
wip add paywall
msukkari Feb 12, 2025
8d2c731
Domain support
brendan-kellam Feb 12, 2025
34c9c1d
Domain support (#188)
brendan-kellam Feb 12, 2025
ac15b7c
Update Makefile to include crypto package when doing a make clean
brendan-kellam Feb 12, 2025
e0976e4
Add default for AUTH_URL in attempt to fix build
brendan-kellam Feb 12, 2025
d17c90a
attempt 2
brendan-kellam Feb 12, 2025
98becf5
fix attempt #3: Do not require a encrpytion key at build time
brendan-kellam Feb 12, 2025
53dac38
merge domain changes
msukkari Feb 12, 2025
ba333dd
Fix generate script race condition
brendan-kellam Feb 12, 2025
19780aa
Attempt #4
brendan-kellam Feb 12, 2025
6caed35
add back paywall and also add support for incrememnting seat count on…
msukkari Feb 13, 2025
8ad6ba7
prevent self invite
msukkari Feb 13, 2025
258585e
action button styling in settings and toast on copy
msukkari Feb 13, 2025
84e8ec2
add ability to remove member from org
msukkari Feb 13, 2025
0b4140f
move stripe product id to env var
msukkari Feb 13, 2025
875f9b8
add await for blocking loop in backend
msukkari Feb 13, 2025
193c7e0
add subscription info to billing page
msukkari Feb 13, 2025
e2c90b8
handle trial case in billing info page
msukkari Feb 13, 2025
8929d05
add trial duration indicator to nav bar
msukkari Feb 13, 2025
a70c577
merge v3 changes into billing branch
msukkari Feb 13, 2025
5a3eab2
check if domain starts or ends with dash
msukkari Feb 13, 2025
e369925
remove unused no org component
msukkari Feb 13, 2025
e6ee45c
Generate AUTH_SECRET if not provided (#189)
brendan-kellam Feb 13, 2025
b0cbcf0
remove package lock file and fix prisma dep version
msukkari Feb 13, 2025
d463748
revert dep version updates
msukkari Feb 13, 2025
4c0805c
fix yarn.lock
brendan-kellam Feb 13, 2025
0f43c00
add auth and membership check to fetchSubscription
msukkari Feb 13, 2025
cf97955
properly handle invite redeem with no valid subscription case
msukkari Feb 13, 2025
ea4c29d
change back fetch subscription to not require org membership
msukkari Feb 13, 2025
87efbf7
add back subscription check in invite redeem page
msukkari Feb 13, 2025
7c18712
Add stripe billing logic (#190)
msukkari Feb 13, 2025
674511a
fix nits
msukkari Feb 14, 2025
8fb438b
remove providers check
brendan-kellam Feb 14, 2025
fbd3e41
fix more nits
msukkari Feb 14, 2025
6234967
merge v3 changes
msukkari Feb 14, 2025
888a2e3
change stripe init to be behind function
msukkari Feb 14, 2025
26cc70c
fix publishible stripe key handling in docker container
msukkari Feb 14, 2025
e2e5433
enforce owner perms (#191)
msukkari Feb 14, 2025
da33220
add back gitlab, gitea, and gerrit support (#184)
msukkari Feb 14, 2025
4cf3024
fix apos usage in redeem page
msukkari Feb 14, 2025
354b004
change csrf cookie to secure not host
msukkari Feb 14, 2025
86a80a4
Credentials provider (#192)
brendan-kellam Feb 15, 2025
3be3680
cleanup org's repos and shards if it's inactive (#194)
msukkari Feb 15, 2025
e0d3634
connections qol improvements (#195)
msukkari Feb 15, 2025
2111a77
Fix build with suspense boundary
brendan-kellam Feb 15, 2025
331a418
improved fix
brendan-kellam Feb 15, 2025
54d14ea
add retries for 429 issues (#196)
msukkari Feb 16, 2025
e17331a
fix build errors and add index concurrency env var
msukkari Feb 16, 2025
e09b21f
add config upsert timeout env var
msukkari Feb 16, 2025
f652ca5
Membership settings rework (#198)
brendan-kellam Feb 18, 2025
bbf8b9b
Magic links (#199)
brendan-kellam Feb 18, 2025
390d92d
Fix build
brendan-kellam Feb 18, 2025
5d7a77b
db performance improvements and job resilience (#200)
msukkari Feb 19, 2025
63af99a
remove non secret token options
msukkari Feb 19, 2025
b99a648
fix token examples in schema
msukkari Feb 19, 2025
fdd71cf
add better visualization for connection/repo errors and warnings (#201)
msukkari Feb 20, 2025
62e64c1
add orgid unique constraint to repo
msukkari Feb 20, 2025
c930fe0
revert repo compile update logic to upsert loop
msukkari Feb 20, 2025
0ac9509
log upsert stats
msukkari Feb 20, 2025
5076ee7
[temp] disable polling everywhere (#205)
brendan-kellam Feb 21, 2025
a79c162
add health check endpoint
msukkari Feb 21, 2025
fee0767
Refined onboarding flow (#202)
brendan-kellam Feb 21, 2025
70e309b
Redeem UX pass (#204)
brendan-kellam Feb 21, 2025
fa0bb82
add log for health check
msukkari Feb 21, 2025
dc42a76
fix new connection complete callback route
msukkari Feb 21, 2025
ced6c52
add cpu split logic and only wait for postgres if we're going to conn…
msukkari Feb 22, 2025
0ff34d1
Inline secret creation (#207)
brendan-kellam Feb 22, 2025
bf8bfdb
use docker scopes to try and improve caching
brendan-kellam Feb 22, 2025
e648ed3
Dummy change
brendan-kellam Feb 23, 2025
d70b729
remove cpu split logic
msukkari Feb 23, 2025
ce52f65
Add some instrumentation to web
brendan-kellam Feb 23, 2025
de44c81
add posthog events on various user actions (#208)
msukkari Feb 25, 2025
69db8f2
fix merge error
msukkari Feb 25, 2025
07cafdd
use staging posthog papik when building staging image
msukkari Feb 25, 2025
e1f7cd9
fix other merge error and build warnings
msukkari Feb 25, 2025
72da582
Add invite email (#209)
brendan-kellam Feb 25, 2025
04f6772
wrap posthog provider in suspense to fix build error
msukkari Feb 25, 2025
fc33f26
add grafana alloy config and setup (#210)
msukkari Feb 25, 2025
07863b2
remove invalid characters when auto filling domain
msukkari Feb 25, 2025
f853335
add login posthog events
msukkari Feb 25, 2025
88fe84e
remove hard coded sourcebot.app references
msukkari Feb 25, 2025
3f586dd
make repo garbage collection async (#211)
msukkari Feb 25, 2025
5c2bf01
fix typo in trial card
msukkari Feb 26, 2025
fab2fea
onboarding tweaks
brendan-kellam Feb 26, 2025
8531b14
rename some prom metrics and cleanup unused
msukkari Feb 26, 2025
b77f55f
wipe existing repo if we've picked up a killed job to ensure good state
msukkari Feb 26, 2025
50b94b2
Connections UX pass + query optimizations (#212)
brendan-kellam Feb 26, 2025
386a3b5
remove git & local schemas (#213)
brendan-kellam Feb 27, 2025
4869137
skip stripe checkout for trial + fix indexing in progress UI + additi…
msukkari Feb 27, 2025
6316166
fix skipping onboard complete check
msukkari Feb 27, 2025
c0b62a2
fix build error
msukkari Feb 27, 2025
3d6c7dc
add back button in onboard connection creation flow
msukkari Feb 27, 2025
46be044
Add back revision support (#215)
brendan-kellam Feb 27, 2025
fcf0b83
fix build
brendan-kellam Feb 27, 2025
85d7b1e
Fix bug with repository snapshot
brendan-kellam Feb 27, 2025
cfff416
fix share links
brendan-kellam Feb 27, 2025
d0b75ce
fix repo rm issue, 502 page, condition on test clock
msukkari Feb 27, 2025
161f21e
Make login and onboarding mobile friendly
brendan-kellam Feb 27, 2025
8b44505
fix ordering of quick actions
msukkari Feb 27, 2025
7ce1067
remove error msg dump on failed repo index job, and update indexedAt …
msukkari Feb 28, 2025
b935234
Add mobile unsupported splash screne
brendan-kellam Feb 28, 2025
1bdb65c
cherry pick fix for file links
msukkari Feb 28, 2025
e1533f2
[Cherry Pick] Syntax reference guide (#169) (#216)
brendan-kellam Feb 28, 2025
6d3be81
Add .env to db gitignore
brendan-kellam Feb 28, 2025
5006a93
fix case where we have repos but they're all failed for repo snapshot
msukkari Feb 28, 2025
83ab0a0
/settings/secrets page (#217)
brendan-kellam Feb 28, 2025
cdfcb5a
display domain properly in org create form
msukkari Feb 28, 2025
7685d9c
Quick action tweaks (#218)
brendan-kellam Feb 28, 2025
bdab90b
revamp repo page (#220)
msukkari Feb 28, 2025
8f6052c
fix (#219)
brendan-kellam Feb 28, 2025
4093442
remove / keyboard shortcut hint in search bar
msukkari Feb 28, 2025
072f77b
prevent switching to first page on data update and truncate long repo…
msukkari Feb 28, 2025
041eab1
General settings + cleanup (#221)
brendan-kellam Feb 28, 2025
8b9a469
First attempt at sending logs to grafana
brendan-kellam Mar 1, 2025
a5fdcb3
logs wip
brendan-kellam Mar 1, 2025
6edfb1b
add alloy logs
brendan-kellam Mar 1, 2025
4c4482d
wip
brendan-kellam Mar 1, 2025
06ba66d
[temp] comment out loki for now
brendan-kellam Mar 1, 2025
b527ec4
update trial card content and add events for code host selection on o…
msukkari Mar 1, 2025
c841894
reduce scraping interval to 15s
brendan-kellam Mar 1, 2025
51186fe
Add prometheus metric for pending repo indexing jobs
brendan-kellam Mar 1, 2025
ff35056
switch magic link to invite code (#222)
msukkari Mar 2, 2025
47b3e1a
remove unused middleware file
msukkari Mar 2, 2025
ec5ec9d
fix build error and warnings
msukkari Mar 2, 2025
85c21a2
fix build error with useSearchParam not wrapped in suspense
msukkari Mar 2, 2025
a93ee65
add sentry support to backend and webapp (#223)
msukkari Mar 2, 2025
7307134
Fix root domain issue on onboarding
brendan-kellam Mar 2, 2025
7253c5a
add setup sentry cli step to github action
msukkari Mar 2, 2025
36f79d7
login to sentry
msukkari Mar 2, 2025
20eac7b
fix sentry login in action
msukkari Mar 2, 2025
99fda9a
Update grafana loki endpoint
brendan-kellam Mar 2, 2025
d33185c
switch source map publish to runtime in entrypoint
msukkari Mar 2, 2025
b27507e
catch and rethrow simplegit exceptions
msukkari Mar 2, 2025
806db26
alloy nits
brendan-kellam Mar 2, 2025
d281523
fix alloy
brendan-kellam Mar 2, 2025
c48c093
backend logging (#224)
brendan-kellam Mar 2, 2025
274b635
revert grafana loki config
brendan-kellam Mar 2, 2025
66c8c74
fix login ui nits
msukkari Mar 2, 2025
5ea7197
fix quick actions
brendan-kellam Mar 2, 2025
395afcf
fix typo in secret creation
msukkari Mar 2, 2025
d920d0d
fix private repo clone issue for gitlab
brendan-kellam Mar 2, 2025
d439933
add repo index timeout logic
msukkari Mar 3, 2025
eab0007
add posthog identify call after registeration
msukkari Mar 4, 2025
a212e85
various changes to add terms and security info (#225)
msukkari Mar 4, 2025
49e24e8
fix build error
msukkari Mar 4, 2025
e82c5e4
nit fix: center 'get in touch' on security card
brendan-kellam Mar 6, 2025
2286d94
Dark theme improvements (#226)
brendan-kellam Mar 7, 2025
98a662c
(fix) Fixed bug with gitlab and gitea not including hostname in the r…
brendan-kellam Mar 7, 2025
e8acfcc
Merge branch 'main' into v3
brendan-kellam Mar 16, 2025
483217b
Switch to using t3-env for env-var management (#230)
brendan-kellam Mar 18, 2025
600cefb
Add missing env var
brendan-kellam Mar 18, 2025
98ec2c9
fix build
brendan-kellam Mar 18, 2025
ad60c5f
Centralize to using a single .env.development for development workflo…
brendan-kellam Mar 18, 2025
e8667da
Make billing optional (#232)
brendan-kellam Mar 19, 2025
583df1d
Massage environment variables from strings to numbers (#234)
brendan-kellam Mar 20, 2025
4ecd700
Single tenancy & auth modes (#233)
brendan-kellam Mar 20, 2025
dd49375
Add docs to this repo
brendan-kellam Mar 21, 2025
2b17fd6
dummy change
brendan-kellam Mar 21, 2025
4c52059
Declarative connection configuration (#235)
brendan-kellam Mar 21, 2025
338993e
fix build
brendan-kellam Mar 21, 2025
98abe23
upgrade to next 14.2.25
msukkari Mar 23, 2025
023edd1
Improved database DX
brendan-kellam Mar 23, 2025
484aea8
migrate to yarn v4
brendan-kellam Mar 24, 2025
7d0540d
Use origin from header for baseUrl of emails (instead of AUTH_URL). A…
brendan-kellam Mar 24, 2025
d8fd958
Remove SOURCEBOT_ENCRYPTION_KEY from build arg
brendan-kellam Mar 24, 2025
c892268
Fix issue with linking default user to org in single tenant + no-auth…
brendan-kellam Mar 24, 2025
8b65a1d
Fix fallback tokens (#242)
brendan-kellam Mar 24, 2025
fda7986
add SECURITY_CARD_ENABLED flag
msukkari Mar 24, 2025
f4db3d2
Add repository weburl (#243)
brendan-kellam Mar 24, 2025
92a8138
Random fixes and improvements (#244)
brendan-kellam Mar 25, 2025
b099b4a
add zoekt max wall time env var
msukkari Mar 25, 2025
c42bc97
remove empty warning in docs
msukkari Mar 25, 2025
a1b5d98
fix reference in sh docs
msukkari Mar 25, 2025
691c593
add connection manager upsert timeout env var
msukkari Mar 26, 2025
27a1066
Declarative connection cleanup + improvements (#245)
brendan-kellam Mar 26, 2025
78b8916
change contact us footer in app to point to main contact form
msukkari Mar 26, 2025
8e3235a
PostHog event pass (#246)
brendan-kellam Mar 26, 2025
889d488
fix typo
brendan-kellam Mar 26, 2025
df357e7
Add sourcebot cloud environment prop to staging workflow
brendan-kellam Mar 26, 2025
c2a129a
Update generated files
brendan-kellam Mar 27, 2025
1f4a5ae
remove AUTH_URL since it unused and (likely) unnecessary
brendan-kellam Mar 27, 2025
47bbad5
Revert "remove AUTH_URL since it unused and (likely) unnecessary"
brendan-kellam Mar 29, 2025
af2d123
cleanup GitHub action releases (#252)
brendan-kellam Mar 31, 2025
ba1e438
remove alloy, change auth defaul to disabled, add settings page in me…
msukkari Mar 31, 2025
2c0cd1a
enforce connection management perms to owner (#253)
msukkari Mar 31, 2025
23644a9
add CONTRIBUTING.md file
msukkari Mar 31, 2025
82f9d8b
hide settings in dropdown with auth isnt enabled
msukkari Apr 1, 2025
3b61138
handle case where gerrit weburl is just gitiles path
msukkari Apr 1, 2025
725ef80
Docs overhall (#251)
brendan-kellam Apr 1, 2025
6230b13
Merge branch 'main' into v3
brendan-kellam Apr 1, 2025
0ea9620
remove nocheckin
brendan-kellam Apr 1, 2025
0ac2fa7
fix build error
msukkari Apr 1, 2025
84968e4
remove v3 trigger from deploy staging
brendan-kellam Apr 1, 2025
e7dd35b
fix build errors round 2
msukkari Apr 1, 2025
4fe85f9
another error fix
msukkari Apr 1, 2025
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
2 changes: 2 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[submodule "vendor/zoekt"]
path = vendor/zoekt
url = https://github.com/sourcebot-dev/zoekt
# @nocheckin : update this to main when we have a release
branch=v3
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,24 @@ ENV NEXT_PUBLIC_POSTHOG_PAPIK=BAKED_NEXT_PUBLIC_POSTHOG_PAPIK
ARG NEXT_PUBLIC_DOMAIN_SUB_PATH=/BAKED_NEXT_PUBLIC_DOMAIN_SUB_PATH
RUN yarn workspace @sourcebot/web build

# ------ Build Database ------
FROM node-alpine AS database-builder
WORKDIR /app

COPY package.json yarn.lock* ./
COPY ./packages/db ./packages/db
RUN yarn workspace @sourcebot/db install --frozen-lockfile


# ------ Build Backend ------
FROM node-alpine AS backend-builder
WORKDIR /app

COPY package.json yarn.lock* ./
COPY ./schemas ./schemas
COPY ./packages/backend ./packages/backend
COPY --from=database-builder /app/node_modules ./node_modules
COPY --from=database-builder /app/packages/db ./packages/db
RUN yarn workspace @sourcebot/backend install --frozen-lockfile
RUN yarn workspace @sourcebot/backend build

Expand Down Expand Up @@ -100,6 +111,10 @@ COPY --from=web-builder /app/packages/web/.next/static ./packages/web/.next/stat
COPY --from=backend-builder /app/node_modules ./node_modules
COPY --from=backend-builder /app/packages/backend ./packages/backend

# Configure the database
COPY --from=database-builder /app/node_modules ./node_modules
COPY --from=database-builder /app/packages/db ./packages/db

COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY prefix-output.sh ./prefix-output.sh
RUN chmod +x ./prefix-output.sh
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@

CMDS := zoekt ui
CMDS := zoekt yarn

ALL: $(CMDS)

ui:
yarn:
yarn install
yarn workspace @sourcebot/db prisma:migrate:dev

zoekt:
mkdir -p bin
Expand All @@ -20,6 +21,8 @@ clean:
packages/web/.next \
packages/backend/dist \
packages/backend/node_modules \
packages/db/node_modules \
packages/db/dist \
.sourcebot

.PHONY: bin
5 changes: 5 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ if [ ! -d "$DATA_CACHE_DIR" ]; then
mkdir -p "$DATA_CACHE_DIR"
fi

# Run a Database migration
echo -e "\e[34m[Info] Running database migration...\e[0m"
export DATABASE_URL="file:$DATA_CACHE_DIR/db.sqlite"
yarn workspace @sourcebot/db prisma:migrate:prod

# In order to detect if this is the first run, we create a `.installed` file in
# the cache directory.
FIRST_RUN_FILE="$DATA_CACHE_DIR/.installedv2"
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"build": "yarn workspaces run build",
"test": "yarn workspaces run test",
"dev": "npm-run-all --print-label --parallel dev:zoekt dev:backend dev:web",
"dev:zoekt": "export PATH=\"$PWD/bin:$PATH\" && zoekt-webserver -index .sourcebot/index -rpc",
"dev:mt": "npm-run-all --print-label --parallel dev:zoekt:mt dev:backend dev:web",
"dev:zoekt": "export PATH=\"$PWD/bin:$PATH\" && export SRC_TENANT_ENFORCEMENT_MODE=none && zoekt-webserver -index .sourcebot/index -rpc",
"dev:zoekt:mt": "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"
},
Expand Down
137 changes: 137 additions & 0 deletions packages/backend/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import { PrismaClient } from '@sourcebot/db';
import { readFile } from 'fs/promises';
import stripJsonComments from 'strip-json-comments';
import { getGitHubReposFromConfig } from "./github.js";
import { getGitLabReposFromConfig, GITLAB_CLOUD_HOSTNAME } from "./gitlab.js";
import { SourcebotConfigurationSchema } from "./schemas/v2.js";
import { AppContext } from "./types.js";
import { getTokenFromConfig, isRemotePath, marshalBool } from "./utils.js";

export const syncConfig = async (configPath: string, db: PrismaClient, signal: AbortSignal, ctx: AppContext) => {
const configContent = await (async () => {
if (isRemotePath(configPath)) {
const response = await fetch(configPath, {
signal,
});
if (!response.ok) {
throw new Error(`Failed to fetch config file ${configPath}: ${response.statusText}`);
}
return response.text();
} else {
return readFile(configPath, {
encoding: 'utf-8',
signal,
});
}
})();

// @todo: we should validate the configuration file's structure here.
const config = JSON.parse(stripJsonComments(configContent)) as SourcebotConfigurationSchema;

for (const repoConfig of config.repos ?? []) {
switch (repoConfig.type) {
case 'github': {
const token = repoConfig.token ? getTokenFromConfig(repoConfig.token, ctx) : undefined;
const gitHubRepos = await getGitHubReposFromConfig(repoConfig, signal, ctx);
const hostUrl = repoConfig.url ?? 'https://github.com';
const hostname = repoConfig.url ? new URL(repoConfig.url).hostname : 'github.com';
const tenantId = repoConfig.tenantId ?? 0;

await Promise.all(gitHubRepos.map((repo) => {
const repoName = `${hostname}/${repo.full_name}`;
const cloneUrl = new URL(repo.clone_url!);
if (token) {
cloneUrl.username = token;
}

const data = {
external_id: repo.id.toString(),
external_codeHostType: 'github',
external_codeHostUrl: hostUrl,
cloneUrl: cloneUrl.toString(),
name: repoName,
isFork: repo.fork,
isArchived: !!repo.archived,
tenantId: tenantId,
metadata: {
'zoekt.web-url-type': 'github',
'zoekt.web-url': repo.html_url,
'zoekt.name': repoName,
'zoekt.github-stars': (repo.stargazers_count ?? 0).toString(),
'zoekt.github-watchers': (repo.watchers_count ?? 0).toString(),
'zoekt.github-subscribers': (repo.subscribers_count ?? 0).toString(),
'zoekt.github-forks': (repo.forks_count ?? 0).toString(),
'zoekt.archived': marshalBool(repo.archived),
'zoekt.fork': marshalBool(repo.fork),
'zoekt.public': marshalBool(repo.private === false)
},
};

return db.repo.upsert({
where: {
external_id_external_codeHostUrl: {
external_id: repo.id.toString(),
external_codeHostUrl: hostUrl,
},
},
create: data,
update: data,
})
}));

break;
}
case 'gitlab': {
const hostUrl = repoConfig.url ?? 'https://gitlab.com';
const hostname = repoConfig.url ? new URL(repoConfig.url).hostname : GITLAB_CLOUD_HOSTNAME;
const token = repoConfig.token ? getTokenFromConfig(repoConfig.token, ctx) : undefined;
const gitLabRepos = await getGitLabReposFromConfig(repoConfig, ctx);

await Promise.all(gitLabRepos.map((project) => {
const repoName = `${hostname}/${project.path_with_namespace}`;
const isFork = project.forked_from_project !== undefined;

const cloneUrl = new URL(project.http_url_to_repo);
if (token) {
cloneUrl.username = 'oauth2';
cloneUrl.password = token;
}

const data = {
external_id: project.id.toString(),
external_codeHostType: 'gitlab',
external_codeHostUrl: hostUrl,
cloneUrl: cloneUrl.toString(),
name: repoName,
tenantId: 0, // TODO: add support for tenantId in GitLab config
isFork,
isArchived: project.archived,
metadata: {
'zoekt.web-url-type': 'gitlab',
'zoekt.web-url': project.web_url,
'zoekt.name': repoName,
'zoekt.gitlab-stars': project.star_count?.toString() ?? '0',
'zoekt.gitlab-forks': project.forks_count?.toString() ?? '0',
'zoekt.archived': marshalBool(project.archived),
'zoekt.fork': marshalBool(isFork),
'zoekt.public': marshalBool(project.visibility === 'public'),
}
}

return db.repo.upsert({
where: {
external_id_external_codeHostUrl: {
external_id: project.id.toString(),
external_codeHostUrl: hostUrl,
},
},
create: data,
update: data,
})
}));

break;
}
}
}
}
4 changes: 2 additions & 2 deletions packages/backend/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import { Settings } from "./types.js";
export const DEFAULT_SETTINGS: Settings = {
maxFileSize: 2 * 1024 * 1024, // 2MB in bytes
autoDeleteStaleRepos: true,
reindexInterval: 1000 * 60 * 60, // 1 hour in milliseconds
resyncInterval: 1000 * 60 * 60 * 24, // 1 day in milliseconds
reindexIntervalMs: 1000 * 60 * 60, // 1 hour in milliseconds
resyncIntervalMs: 1000 * 60 * 60 * 24, // 1 day in milliseconds
}
125 changes: 0 additions & 125 deletions packages/backend/src/db.test.ts

This file was deleted.

Loading
Loading