Compare commits

...

9 Commits

Author SHA1 Message Date
Michael Lin
3117b03be9
[Backport 5.5.x] Upgrade cody web experimental package to 0.2.7 (#63863) (#63901)
backport https://github.com/sourcegraph/sourcegraph/pull/63863

S2 Cody Web is broken at the moment. New client-config handlers fail
with 401 status because we don't send custom headers, this works for gql
queries since they all are POST requests and the browser automatically
sends an Origin header for them and this is enough for our auth
middleware to check cookies, but with client-config which is rest it's
not the case and we should send `X-Requested-Client: Sourcegraph` header
to make our auth middleware to pass this query correctly

Note that this problem doesn't exist in local builds since we proxy all
requests and add `X-Requested-Client: Sourcegraph` in dev server.

See Cody latest build PR for more details
https://github.com/sourcegraph/cody/pull/4898

## Test plan

CI

Co-authored-by: Vova Kulikov <vovakulikov@icloud.com>
2024-07-18 10:29:02 +01:00
Release Bot
9cf00da25a
[Backport 5.5.x] fix(batches): the baseURL for github instance is now updated when creating a GitHub app (#63833)
Closes SRCH-723

The baseURL for GitHub apps defaults to `https://github.com` when no
`externalServiceURL`, we somehow missed this during our testing.

![CleanShot 2024-07-12 at 11 57
00@2x](https://github.com/user-attachments/assets/99b68a11-de38-4a2d-8c4c-3219f0c9abf7)


## Test plan



Manual testing with the GHE instance.

## Changelog


 <br> Backport 1c40c9e5bc from #63803

Co-authored-by: Bolaji Olajide <25608335+BolajiOlajide@users.noreply.github.com>
Co-authored-by: Anish Lakhwara <anish+github@lakhwara.com>
2024-07-17 18:18:13 +00:00
Varun Gandhi
6b8d334563
Backport 63870 to 5.5.x (#63882)
See  https://github.com/sourcegraph/sourcegraph/pull/63870

cc @sourcegraph/release

## Test plan

Covered by existing tests

## Changelog

- Adds an experimental feature `commitGraphUpdates` to control how
upload visibility is calculated.
2024-07-17 13:45:36 -04:00
Release Bot
21247e44ac
[Backport 5.5.x] Upgrade cody web experimental package to 0.2.5 (#63856)
This PR upgrades the cody web experimental package to 0.2.5, in the new
version we fixed
- Telemetry problem with init extension-related events (we don&#39;t
send install extension events anymore)
- Most recent updates on LLM availability for enterprise instances 
 
## Test plan
- CI is green
- Manual check on basic Cody Web functionality (highly recommended) <br>
Backport e6bd85e4b7 from #63839

Co-authored-by: Vova Kulikov <vovakulikov@icloud.com>
2024-07-17 12:01:11 -04:00
Vova Kulikov
20adc60d67
[Backport-5.5.x]: Move Cody Web to beta (#63806) (#63808)
Closes

https://linear.app/sourcegraph/issue/CODY-2847/change-experimental-labels-to-beta

## Test plan
- Check that the cody web page and cody web side panel have beta badges

(cherry-picked from commit fbb0a1fec1)

## Test plan
- Check that the side-panel Cody and Cody Chat page have beta product
status badges
2024-07-15 12:07:10 -07:00
Release Bot
308624f144
[Backport 5.5.x] Context: return lines around symbol match (#63788)
This PR fixes an important bug in #62976, where we didn&#39;t properly
map the
symbol line match to the return type. Instead, we accidentally treated
symbol
matches like file matches and returned the start of the file.

## Test plan

Add new unit test for symbol match conversion. Extensive manual testing.
<br> Backport 004eb0fd83 from #63773

Co-authored-by: Julie Tibshirani <julietibs@apache.org>
2024-07-11 16:14:52 -04:00
Release Bot
174c08c8c2
[Backport 5.5.x] fix/alertmanager: downgrade prometheus/common to fix generated config (#63793)
The OTEL upgrade https://github.com/sourcegraph/sourcegraph/pull/63171
bumps the `prometheus/common` package too far via transitive deps,
causing us to generate configuration for alertmanager that altertmanager
doesn&#39;t accept, at least until the alertmanager project cuts a new
release with a newer version of `promethues/common`.

For now we forcibly downgrade with a replace. Everything still builds,
so we should be good to go.

## Test plan
`sg start` and `sg run prometheus`. On `main`, editing
`observability.alerts` will cause Alertmanager to refuse to accept the
generated configuration. With this patch, all is well it seems - config
changes go through as expected. This is a similar test plan for
https://github.com/sourcegraph/sourcegraph/pull/63329

## Changelog

- Fix Prometheus Alertmanager configuration failing to apply
`observability.alerts` from site config <br> Backport
ffa873f3ad from #63790

Co-authored-by: Robert Lin <robert@bobheadxi.dev>
2024-07-11 15:49:58 -04:00
Release Bot
8ee41490b9
[Backport 5.5.x] release/bug: generate a new stitched migration graph (#63769)
This will correct6 upgrade path for mvu plan creation

## Test plan

CI test



## Changelog


 <br> Backport cb19d6f0a9 from #63764

Co-authored-by: Warren Gifford <warren@sourcegraph.com>
2024-07-10 22:01:36 +00:00
Release Bot
344169fd47
[Backport 5.5.x] chore(release): bump stitch graph generation (#63768)
Missing bit for the minor release version bump

## Test plan

CI


 <br> Backport 087ad83995 from #63767

Co-authored-by: Jean-Hadrien Chabran <jean-hadrien.chabran@sourcegraph.com>
2024-07-10 21:00:59 +00:00
32 changed files with 2039 additions and 618 deletions

View File

@ -501,7 +501,7 @@ load("//dev:schema_migrations.bzl", "schema_migrations")
schema_migrations(
name = "schemas_migrations",
updated_at = "2024-07-10 12:15",
updated_at = "2024-07-10 23:24",
)
# wolfi images setup ================================

View File

@ -3,7 +3,7 @@ import type { FC } from 'react'
import { CodyWebHistory, CodyWebChatProvider } from 'cody-web-experimental'
import { Navigate } from 'react-router-dom'
import { Badge, ButtonLink, PageHeader, Text } from '@sourcegraph/wildcard'
import { ButtonLink, PageHeader, ProductStatusBadge, Text } from '@sourcegraph/wildcard'
import { Page } from '../../../components/Page'
import { PageTitle } from '../../../components/PageTitle'
@ -31,7 +31,11 @@ export const NewCodyChatPage: FC<NewCodyChatPageProps> = props => {
<CodyPageHeader isSourcegraphDotCom={isSourcegraphDotCom} className={styles.pageHeader} />
<div className={styles.chatContainer}>
<CodyWebChatProvider accessToken="" serverEndpoint={window.location.origin}>
<CodyWebChatProvider
accessToken=""
serverEndpoint={window.location.origin}
customHeaders={window.context.xhrHeaders}
>
<CodyWebHistory>
{history => (
<div className={styles.chatHistory}>
@ -95,9 +99,7 @@ const CodyPageHeader: FC<CodyPageHeaderProps> = props => {
<PageHeader.Breadcrumb icon={CodyColorIcon}>
<div className="d-inline-flex align-items-center">
Cody Chat
<Badge variant="info" className="ml-2">
Experimental
</Badge>
<ProductStatusBadge status="beta" className="ml-2" />
</div>
</PageHeader.Breadcrumb>
</PageHeader.Heading>

View File

@ -4,7 +4,7 @@ import { mdiClose } from '@mdi/js'
import { CodyLogo } from '@sourcegraph/cody-ui'
import { lazyComponent } from '@sourcegraph/shared/src/util/lazyComponent'
import { Alert, Badge, Button, H4, Icon, LoadingSpinner } from '@sourcegraph/wildcard'
import { Alert, Button, H4, Icon, LoadingSpinner, ProductStatusBadge } from '@sourcegraph/wildcard'
import styles from './NewCodySidebar.module.scss'
@ -32,7 +32,7 @@ export const NewCodySidebar: FC<NewCodySidebarProps> = props => {
<CodyLogo />
Cody
<div className="ml-2">
<Badge variant="info">Experimental</Badge>
<ProductStatusBadge status="beta" />
</div>
</div>
<Button variant="icon" aria-label="Close" onClick={onClose}>

View File

@ -48,6 +48,7 @@ export const NewCodySidebarWebChat: FC<NewCodySidebarWebChatProps> = memo(functi
chatID={chatID}
initialContext={contextInfo}
serverEndpoint={window.location.origin}
customHeaders={window.context.xhrHeaders}
onNewChatCreated={handleNewChatCreated}
>
<ChatUi />

View File

@ -383,6 +383,7 @@ const AddToken: FC<AddTokenProps> = ({
authenticatedUser={user as unknown as AuthenticatedUser}
minimizedMode={true}
kind={kind}
externalServiceURL={externalServiceURL}
/>
)}
</>

View File

@ -23,16 +23,18 @@ interface BatchChangesCreateGitHubAppPageProps {
authenticatedUser: AuthenticatedUser
minimizedMode?: boolean
kind: GitHubAppKind
externalServiceURL?: string
}
export const BatchChangesCreateGitHubAppPage: FC<BatchChangesCreateGitHubAppPageProps> = ({
minimizedMode,
kind,
authenticatedUser,
externalServiceURL,
}) => {
const location = useLocation()
const searchParams = new URLSearchParams(location.search)
const baseURL = searchParams.get('baseURL')
const baseURL = externalServiceURL || searchParams.get('baseURL')
const isGitHubAppKindCredential = kind === GitHubAppKind.USER_CREDENTIAL || kind === GitHubAppKind.SITE_CREDENTIAL

View File

@ -351,23 +351,18 @@ func addLimitsAndFilter(plan *search.Inputs, filter fileMatcher, args GetContext
}
func fileMatchToContextMatch(fm *result.FileMatch) FileChunkContext {
if len(fm.ChunkMatches) == 0 {
var startLine int
if len(fm.Symbols) != 0 {
startLine = max(0, fm.Symbols[0].Symbol.Line-5) // 5 lines of leading context, clamped to zero
} else if len(fm.ChunkMatches) != 0 {
// To provide some context variety, we just use the top-ranked
// chunk (the first chunk) from each file match.
startLine = max(0, fm.ChunkMatches[0].ContentStart.Line-5) // 5 lines of leading context, clamped to zero
} else {
// If this is a filename-only match, return a single chunk at the start of the file
return FileChunkContext{
RepoName: fm.Repo.Name,
RepoID: fm.Repo.ID,
CommitID: fm.CommitID,
Path: fm.Path,
StartLine: 0,
}
startLine = 0
}
// To provide some context variety, we just use the top-ranked
// chunk (the first chunk) from each file
// 5 lines of leading context, clamped to zero
startLine := max(0, fm.ChunkMatches[0].ContentStart.Line-5)
return FileChunkContext{
RepoName: fm.Repo.Name,
RepoID: fm.Repo.ID,

View File

@ -64,6 +64,40 @@ func TestFileMatchToContextMatches(t *testing.T) {
StartLine: 85,
},
},
{
// With symbol match returns context around first symbol
fileMatch: &result.FileMatch{
File: result.File{
Path: "main.go",
CommitID: "abc123",
Repo: types.MinimalRepo{
Name: "repo",
ID: 1,
},
},
Symbols: []*result.SymbolMatch{
{
Symbol: result.Symbol{
Line: 23,
Name: "symbol",
},
},
{
Symbol: result.Symbol{
Line: 37,
Name: "symbol",
},
},
},
},
want: FileChunkContext{
RepoName: "repo",
RepoID: 1,
CommitID: "abc123",
Path: "main.go",
StartLine: 18,
},
},
}
for _, tc := range cases {

206
deps.bzl
View File

@ -34,8 +34,8 @@ def go_dependencies():
name = "co_honnef_go_tools",
build_file_proto_mode = "disable_global",
importpath = "honnef.co/go/tools",
sum = "h1:UoveltGrhghAA7ePc+e+QYDHXrBps2PqFZiHkGR/xK8=",
version = "v0.0.1-2020.1.4",
sum = "h1:qTakTkI6ni6LFD5sBwwsdSO+AQqbSIxOauHTTQKZ/7o=",
version = "v0.1.3",
)
go_repository(
name = "com_connectrpc_connect",
@ -93,6 +93,20 @@ def go_dependencies():
sum = "h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRBij0P8=",
version = "v1.1.1",
)
go_repository(
name = "com_github_ajstarks_deck",
build_file_proto_mode = "disable_global",
importpath = "github.com/ajstarks/deck",
sum = "h1:7kQgkwGRoLzC9K0oyXdJo7nve/bynv/KwUsxbiTlzAM=",
version = "v0.0.0-20200831202436-30c9fc6549a9",
)
go_repository(
name = "com_github_ajstarks_deck_generate",
build_file_proto_mode = "disable_global",
importpath = "github.com/ajstarks/deck/generate",
sum = "h1:iXUgAaqDcIUGbRoy2TdeofRG/j1zpGRSEmNK05T+bi8=",
version = "v0.0.0-20210309230005-c3f852c02e19",
)
go_repository(
name = "com_github_ajstarks_svgo",
build_file_proto_mode = "disable_global",
@ -275,6 +289,20 @@ def go_dependencies():
sum = "h1:7fpzNGoJ3VA8qcrm++XEE1QUe0mIwNeLa02Nwq7RDkg=",
version = "v1.0.1",
)
go_repository(
name = "com_github_apache_arrow_go_v10",
build_file_proto_mode = "disable_global",
importpath = "github.com/apache/arrow/go/v10",
sum = "h1:n9dERvixoC/1JjDmBcs9FPaEryoANa2sCgVFo6ez9cI=",
version = "v10.0.1",
)
go_repository(
name = "com_github_apache_arrow_go_v11",
build_file_proto_mode = "disable_global",
importpath = "github.com/apache/arrow/go/v11",
sum = "h1:hqauxvFQxww+0mEU/2XHG6LT7eZternCZq+A5Yly2uM=",
version = "v11.0.0",
)
go_repository(
name = "com_github_apache_arrow_go_v14",
build_file_proto_mode = "disable_global",
@ -793,6 +821,13 @@ def go_dependencies():
sum = "h1:RmdPFa+slIr4SCBg4st/l/vZWVe9QJKMXGO60Bxbe04=",
version = "v0.0.0-20180917114910-cd5dcc76aeff",
)
go_repository(
name = "com_github_boombuler_barcode",
build_file_proto_mode = "disable_global",
importpath = "github.com/boombuler/barcode",
sum = "h1:NDBbPmhS+EqABEs5Kg3n/5ZNjy73Pz7SIV+KCeqyXcs=",
version = "v1.0.1",
)
go_repository(
name = "com_github_bradfitz_gomemcache",
build_file_proto_mode = "disable_global",
@ -1087,8 +1122,8 @@ def go_dependencies():
name = "com_github_cncf_udpa_go",
build_file_proto_mode = "disable_global",
importpath = "github.com/cncf/udpa/go",
sum = "h1:hzAQntlaYRkVSFEfj9OTWlVV1H155FMD8BTKktLv0QI=",
version = "v0.0.0-20210930031921-04548b0d99d4",
sum = "h1:QQ3GSy+MqSHxm/d8nCtnAiZdYFd45cYZPs8vOOIYKfk=",
version = "v0.0.0-20220112060539-c52dc94e7fbe",
)
go_repository(
name = "com_github_cncf_xds_go",
@ -1902,6 +1937,13 @@ def go_dependencies():
sum = "h1:gv+5Pe3vaSVmiJvh/BZa82b7/00YUGm0PIyVVLop0Hw=",
version = "v4.0.2",
)
go_repository(
name = "com_github_fogleman_gg",
build_file_proto_mode = "disable_global",
importpath = "github.com/fogleman/gg",
sum = "h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8=",
version = "v1.3.0",
)
go_repository(
name = "com_github_form3tech_oss_jwt_go",
build_file_proto_mode = "disable_global",
@ -2043,6 +2085,13 @@ def go_dependencies():
sum = "h1:nNIPOBkprlKzkThvS/0YaX8Zs9KewLCOSFQS5BU06FI=",
version = "v0.6.1",
)
go_repository(
name = "com_github_go_fonts_dejavu",
build_file_proto_mode = "disable_global",
importpath = "github.com/go-fonts/dejavu",
sum = "h1:JSajPXURYqpr+Cu8U9bt8K+XcACIHWqWrvWCKyeFmVQ=",
version = "v0.1.0",
)
go_repository(
name = "com_github_go_fonts_latin_modern",
build_file_proto_mode = "disable_global",
@ -2057,6 +2106,13 @@ def go_dependencies():
sum = "h1:XuwG0vGHFBPRRI8Qwbi5tIvR3cku9LUfZGq/Ar16wlQ=",
version = "v0.3.2",
)
go_repository(
name = "com_github_go_fonts_stix",
build_file_proto_mode = "disable_global",
importpath = "github.com/go-fonts/stix",
sum = "h1:UlZlgrvvmT/58o573ot7NFw0vZasZ5I6bcIft/oMdgg=",
version = "v0.1.0",
)
go_repository(
name = "com_github_go_git_gcfg",
build_file_proto_mode = "disable_global",
@ -2782,6 +2838,13 @@ def go_dependencies():
sum = "h1:9fHAtK0uDfpveeqqo1hkEZJcFvYXAiCN3UutL8F9xHw=",
version = "v0.5.5",
)
go_repository(
name = "com_github_googleapis_go_type_adapters",
build_file_proto_mode = "disable_global",
importpath = "github.com/googleapis/go-type-adapters",
sum = "h1:9XdMn+d/G57qq1s8dNc5IesGCXHf6V2HZ2JwRxfA2tA=",
version = "v1.0.0",
)
go_repository(
name = "com_github_googleapis_google_cloud_go_testing",
build_file_proto_mode = "disable_global",
@ -3920,8 +3983,8 @@ def go_dependencies():
name = "com_github_konsorten_go_windows_terminal_sequences",
build_file_proto_mode = "disable_global",
importpath = "github.com/konsorten/go-windows-terminal-sequences",
sum = "h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=",
version = "v1.0.3",
sum = "h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=",
version = "v1.0.2",
)
go_repository(
name = "com_github_kr_fs",
@ -4098,6 +4161,13 @@ def go_dependencies():
sum = "h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=",
version = "v0.0.0-20211012122336-39d0f177ccd0",
)
go_repository(
name = "com_github_lyft_protoc_gen_star",
build_file_proto_mode = "disable_global",
importpath = "github.com/lyft/protoc-gen-star",
sum = "h1:erE0rdztuaDq3bpGifD95wfoPrSZc95nGA6tbiNYh6M=",
version = "v0.6.1",
)
go_repository(
name = "com_github_lyft_protoc_gen_star_v2",
build_file_proto_mode = "disable_global",
@ -4935,6 +5005,20 @@ def go_dependencies():
sum = "h1:s2+RH8EGuI/mI4QwrWGSYQCRz7uNgip9BaM04HKu5kc=",
version = "v1.1.0",
)
go_repository(
name = "com_github_phpdave11_gofpdf",
build_file_proto_mode = "disable_global",
importpath = "github.com/phpdave11/gofpdf",
sum = "h1:KPKiIbfwbvC/wOncwhrpRdXVj2CZTCFlw4wnoyjtHfQ=",
version = "v1.4.2",
)
go_repository(
name = "com_github_phpdave11_gofpdi",
build_file_proto_mode = "disable_global",
importpath = "github.com/phpdave11/gofpdi",
sum = "h1:o61duiW8M9sMlkVXWlvP92sZJtGKENvW3VExs6dZukQ=",
version = "v1.0.13",
)
go_repository(
name = "com_github_pierrec_lz4",
build_file_proto_mode = "disable_global",
@ -5087,8 +5171,9 @@ def go_dependencies():
name = "com_github_prometheus_common",
build_file_proto_mode = "disable_global",
importpath = "github.com/prometheus/common",
sum = "h1:ZlZy0BgJhTwVZUn7dLOkwCZHUkrAqd3WYtcFCWnM1D8=",
version = "v0.54.0",
replace = "github.com/prometheus/common",
sum = "h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE=",
version = "v0.48.0",
)
go_repository(
name = "com_github_prometheus_common_assets",
@ -5381,6 +5466,13 @@ def go_dependencies():
sum = "h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=",
version = "v2.1.0",
)
go_repository(
name = "com_github_ruudk_golang_pdf417",
build_file_proto_mode = "disable_global",
importpath = "github.com/ruudk/golang-pdf417",
sum = "h1:K1Xf3bKttbF+koVGaX5xngRIZ5bVjbmPnaxE/dR08uY=",
version = "v0.0.0-20201230142125-a7e3863a1245",
)
go_repository(
name = "com_github_ryanuber_columnize",
build_file_proto_mode = "disable_global",
@ -6621,6 +6713,13 @@ def go_dependencies():
sum = "h1:l8VFHdNMC+9Q4EHKye2eOZBu5IwddXF6ufAXI7D+PB8=",
version = "v0.8.4",
)
go_repository(
name = "com_google_cloud_go_apikeys",
build_file_proto_mode = "disable_global",
importpath = "cloud.google.com/go/apikeys",
sum = "h1:B9CdHFZTFjVti89tmyXXrO+7vSNo2jvZuHG8zD5trdQ=",
version = "v0.6.0",
)
go_repository(
name = "com_google_cloud_go_appengine",
build_file_proto_mode = "disable_global",
@ -6831,6 +6930,13 @@ def go_dependencies():
sum = "h1:Ob8NPT1UcB4kDaDx7/UdsRfZ8xUvUggZshXUlGWDahk=",
version = "v1.15.0",
)
go_repository(
name = "com_google_cloud_go_dataproc",
build_file_proto_mode = "disable_global",
importpath = "cloud.google.com/go/dataproc",
sum = "h1:W47qHL3W4BPkAIbk4SWmIERwsWBaNnWm0P2sdx3YgGU=",
version = "v1.12.0",
)
go_repository(
name = "com_google_cloud_go_dataproc_v2",
build_file_proto_mode = "disable_global",
@ -6943,6 +7049,13 @@ def go_dependencies():
sum = "h1:0kcko/2AKwm4USnWcGs/W/k++PAYPA3dYaQw1y5Xg3M=",
version = "v1.16.1",
)
go_repository(
name = "com_google_cloud_go_gaming",
build_file_proto_mode = "disable_global",
importpath = "cloud.google.com/go/gaming",
sum = "h1:7vEhFnZmd931Mo7sZ6pJy7uQPDxF7m7v8xtBheG08tc=",
version = "v1.9.0",
)
go_repository(
name = "com_google_cloud_go_gkebackup",
build_file_proto_mode = "disable_global",
@ -6971,6 +7084,13 @@ def go_dependencies():
sum = "h1:CFBoDcQi9zLOkzM6xqmRzljZhF4A6A47QaQ0WtNd+DA=",
version = "v1.1.2",
)
go_repository(
name = "com_google_cloud_go_grafeas",
build_file_proto_mode = "disable_global",
importpath = "cloud.google.com/go/grafeas",
sum = "h1:CYjC+xzdPvbV65gi6Dr4YowKcmLo045pm18L0DhdELM=",
version = "v0.2.0",
)
go_repository(
name = "com_google_cloud_go_gsuiteaddons",
build_file_proto_mode = "disable_global",
@ -7188,6 +7308,13 @@ def go_dependencies():
sum = "h1:pX+idpWMIH30/K7c0epN6V703xpIcMXWRjKJsz0tYGY=",
version = "v1.8.1",
)
go_repository(
name = "com_google_cloud_go_recaptchaenterprise",
build_file_proto_mode = "disable_global",
importpath = "cloud.google.com/go/recaptchaenterprise",
sum = "h1:u6EznTGzIdsyOsvm+Xkw0aSuKFXQlyjGE9a4exk6iNQ=",
version = "v1.3.1",
)
go_repository(
name = "com_google_cloud_go_recaptchaenterprise_v2",
build_file_proto_mode = "disable_global",
@ -7272,6 +7399,13 @@ def go_dependencies():
sum = "h1:NpEJeFbm3ad3ibpbpIBKXJS7eQq1cZhtt9nrDTMO/QQ=",
version = "v1.28.0",
)
go_repository(
name = "com_google_cloud_go_servicecontrol",
build_file_proto_mode = "disable_global",
importpath = "cloud.google.com/go/servicecontrol",
sum = "h1:d0uV7Qegtfaa7Z2ClDzr9HJmnbJW7jn0WhZ7wOX6hLE=",
version = "v1.11.1",
)
go_repository(
name = "com_google_cloud_go_servicedirectory",
build_file_proto_mode = "disable_global",
@ -7279,6 +7413,20 @@ def go_dependencies():
sum = "h1:gkzx9Cd+OTOD+zY4u5vtbdvOx7vrvHYdeDiNdC6vKyw=",
version = "v1.11.5",
)
go_repository(
name = "com_google_cloud_go_servicemanagement",
build_file_proto_mode = "disable_global",
importpath = "cloud.google.com/go/servicemanagement",
sum = "h1:fopAQI/IAzlxnVeiKn/8WiV6zKndjFkvi+gzu+NjywY=",
version = "v1.8.0",
)
go_repository(
name = "com_google_cloud_go_serviceusage",
build_file_proto_mode = "disable_global",
importpath = "cloud.google.com/go/serviceusage",
sum = "h1:rXyq+0+RSIm3HFypctp7WoXxIA563rn206CfMWdqXX4=",
version = "v1.6.0",
)
go_repository(
name = "com_google_cloud_go_shell",
build_file_proto_mode = "disable_global",
@ -7363,6 +7511,13 @@ def go_dependencies():
sum = "h1:P0Sa8+5KOEAVk/fazUNjVPzRCijCheZWJ8wL8xBn9Uk=",
version = "v1.11.6",
)
go_repository(
name = "com_google_cloud_go_vision",
build_file_proto_mode = "disable_global",
importpath = "cloud.google.com/go/vision",
sum = "h1:/CsSTkbmO9HC8iQpxbK8ATms3OQaX3YQUeTMGCxlaK4=",
version = "v1.2.0",
)
go_repository(
name = "com_google_cloud_go_vision_v2",
build_file_proto_mode = "disable_global",
@ -8548,6 +8703,13 @@ def go_dependencies():
sum = "h1:2lYxjRbTYyxkJxlhC+LvJIx3SsANPdRybu1tGj9/OrQ=",
version = "v0.15.0",
)
go_repository(
name = "org_gonum_v1_netlib",
build_file_proto_mode = "disable_global",
importpath = "gonum.org/v1/netlib",
sum = "h1:OE9mWmgKkjJyEmDAAtGMPjXu+YNeGvK9VTSHY6+Qihc=",
version = "v0.0.0-20190313105609-8cb42192e0e0",
)
go_repository(
name = "org_gonum_v1_plot",
build_file_proto_mode = "disable_global",
@ -8597,6 +8759,13 @@ def go_dependencies():
sum = "h1:6wrtRozgrhCxieCeJh85QsxkX/2FFrT9hdaWPlbn4Zo=",
version = "v4.17.10",
)
go_repository(
name = "org_modernc_ccorpus",
build_file_proto_mode = "disable_global",
importpath = "modernc.org/ccorpus",
sum = "h1:J16RXiiqiCgua6+ZvQot4yUuUy8zxgqbqEEUuGPlISk=",
version = "v1.11.6",
)
go_repository(
name = "org_modernc_fileutil",
build_file_proto_mode = "disable_global",
@ -8618,6 +8787,13 @@ def go_dependencies():
sum = "h1:5D53IMaUuA5InSeMu9eJtlQXS2NxAhyWQvkKEgXZhHI=",
version = "v3.0.0-20240107210532-573471604cb6",
)
go_repository(
name = "org_modernc_httpfs",
build_file_proto_mode = "disable_global",
importpath = "modernc.org/httpfs",
sum = "h1:AAgIpFZRXuYnkjftxTAZwMIiwEqAfk8aVB2/oA6nAeM=",
version = "v1.0.6",
)
go_repository(
name = "org_modernc_libc",
build_file_proto_mode = "disable_global",
@ -8667,6 +8843,13 @@ def go_dependencies():
sum = "h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA=",
version = "v1.2.0",
)
go_repository(
name = "org_modernc_tcl",
build_file_proto_mode = "disable_global",
importpath = "modernc.org/tcl",
sum = "h1:npxzTwFTZYM8ghWicVIX1cRWzj7Nd8i6AqqX2p+IYao=",
version = "v1.13.1",
)
go_repository(
name = "org_modernc_token",
build_file_proto_mode = "disable_global",
@ -8674,6 +8857,13 @@ def go_dependencies():
sum = "h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=",
version = "v1.1.0",
)
go_repository(
name = "org_modernc_z",
build_file_proto_mode = "disable_global",
importpath = "modernc.org/z",
sum = "h1:RTNHdsrOpeoSeOF4FbzTo8gBYByaJ5xT7NgZ9ZqRiJM=",
version = "v1.5.1",
)
go_repository(
name = "org_mongodb_go_mongo_driver",
build_file_proto_mode = "disable_global",

5
go.mod
View File

@ -45,6 +45,11 @@ replace (
github.com/googleapis/gnostic => github.com/googleapis/gnostic v0.5.5
// Pending: https://github.com/openfga/openfga/pull/1688
github.com/openfga/openfga => github.com/sourcegraph/openfga v0.0.0-20240614204729-de6b563022de
// We need to wait for https://github.com/prometheus/alertmanager to cut a
// release that uses a newer 'prometheus/common'. Then we need to update
// https://github.com/sourcegraph/alertmanager. Upgrading before then will
// cause problems with generated alertmanager configuration.
github.com/prometheus/common => github.com/prometheus/common v0.48.0
// Pending: https://github.com/shurcooL/httpgzip/pull/9
github.com/shurcooL/httpgzip => github.com/sourcegraph/httpgzip v0.0.0-20211015085752-0bad89b3b4df
)

1028
go.sum

File diff suppressed because it is too large Load Diff

View File

@ -50,6 +50,7 @@ go_test(
tags = [TAG_PLATFORM_GRAPH],
deps = [
"//internal/api",
"//internal/codeintel/core",
"//internal/codeintel/policies/shared",
"//internal/codeintel/uploads/internal/commitgraph",
"//internal/codeintel/uploads/internal/lsifstore",

View File

@ -33,6 +33,7 @@ go_test(
tags = [TAG_PLATFORM_GRAPH],
deps = [
"//internal/api",
"//internal/codeintel/core",
"//internal/codeintel/uploads/internal/commitgraph",
"//internal/codeintel/uploads/internal/store",
"//internal/codeintel/uploads/shared",

View File

@ -12,6 +12,7 @@ import (
"time"
api "github.com/sourcegraph/sourcegraph/internal/api"
core "github.com/sourcegraph/sourcegraph/internal/codeintel/core"
commitgraph "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/internal/commitgraph"
store "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/internal/store"
shared "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared"
@ -75,6 +76,10 @@ type MockStore struct {
// GetAuditLogsForUploadFunc is an instance of a mock function object
// controlling the behavior of the method GetAuditLogsForUpload.
GetAuditLogsForUploadFunc *StoreGetAuditLogsForUploadFunc
// GetCommitAndDateForOldestUploadFunc is an instance of a mock function
// object controlling the behavior of the method
// GetCommitAndDateForOldestUpload.
GetCommitAndDateForOldestUploadFunc *StoreGetCommitAndDateForOldestUploadFunc
// GetCommitGraphMetadataFunc is an instance of a mock function object
// controlling the behavior of the method GetCommitGraphMetadata.
GetCommitGraphMetadataFunc *StoreGetCommitGraphMetadataFunc
@ -108,9 +113,6 @@ type MockStore struct {
// function object controlling the behavior of the method
// GetLastUploadRetentionScanForRepository.
GetLastUploadRetentionScanForRepositoryFunc *StoreGetLastUploadRetentionScanForRepositoryFunc
// GetOldestCommitDateFunc is an instance of a mock function object
// controlling the behavior of the method GetOldestCommitDate.
GetOldestCommitDateFunc *StoreGetOldestCommitDateFunc
// GetRecentIndexesSummaryFunc is an instance of a mock function object
// controlling the behavior of the method GetRecentIndexesSummary.
GetRecentIndexesSummaryFunc *StoreGetRecentIndexesSummaryFunc
@ -315,6 +317,11 @@ func NewMockStore() *MockStore {
return
},
},
GetCommitAndDateForOldestUploadFunc: &StoreGetCommitAndDateForOldestUploadFunc{
defaultHook: func(context.Context, int) (r0 core.Option[store.CommitWithDate], r1 error) {
return
},
},
GetCommitGraphMetadataFunc: &StoreGetCommitGraphMetadataFunc{
defaultHook: func(context.Context, int) (r0 bool, r1 *time.Time, r2 error) {
return
@ -365,11 +372,6 @@ func NewMockStore() *MockStore {
return
},
},
GetOldestCommitDateFunc: &StoreGetOldestCommitDateFunc{
defaultHook: func(context.Context, int) (r0 time.Time, r1 bool, r2 error) {
return
},
},
GetRecentIndexesSummaryFunc: &StoreGetRecentIndexesSummaryFunc{
defaultHook: func(context.Context, int) (r0 []shared.IndexesWithRepositoryNamespace, r1 error) {
return
@ -642,6 +644,11 @@ func NewStrictMockStore() *MockStore {
panic("unexpected invocation of MockStore.GetAuditLogsForUpload")
},
},
GetCommitAndDateForOldestUploadFunc: &StoreGetCommitAndDateForOldestUploadFunc{
defaultHook: func(context.Context, int) (core.Option[store.CommitWithDate], error) {
panic("unexpected invocation of MockStore.GetCommitAndDateForOldestUpload")
},
},
GetCommitGraphMetadataFunc: &StoreGetCommitGraphMetadataFunc{
defaultHook: func(context.Context, int) (bool, *time.Time, error) {
panic("unexpected invocation of MockStore.GetCommitGraphMetadata")
@ -692,11 +699,6 @@ func NewStrictMockStore() *MockStore {
panic("unexpected invocation of MockStore.GetLastUploadRetentionScanForRepository")
},
},
GetOldestCommitDateFunc: &StoreGetOldestCommitDateFunc{
defaultHook: func(context.Context, int) (time.Time, bool, error) {
panic("unexpected invocation of MockStore.GetOldestCommitDate")
},
},
GetRecentIndexesSummaryFunc: &StoreGetRecentIndexesSummaryFunc{
defaultHook: func(context.Context, int) ([]shared.IndexesWithRepositoryNamespace, error) {
panic("unexpected invocation of MockStore.GetRecentIndexesSummary")
@ -941,6 +943,9 @@ func NewMockStoreFrom(i store.Store) *MockStore {
GetAuditLogsForUploadFunc: &StoreGetAuditLogsForUploadFunc{
defaultHook: i.GetAuditLogsForUpload,
},
GetCommitAndDateForOldestUploadFunc: &StoreGetCommitAndDateForOldestUploadFunc{
defaultHook: i.GetCommitAndDateForOldestUpload,
},
GetCommitGraphMetadataFunc: &StoreGetCommitGraphMetadataFunc{
defaultHook: i.GetCommitGraphMetadata,
},
@ -971,9 +976,6 @@ func NewMockStoreFrom(i store.Store) *MockStore {
GetLastUploadRetentionScanForRepositoryFunc: &StoreGetLastUploadRetentionScanForRepositoryFunc{
defaultHook: i.GetLastUploadRetentionScanForRepository,
},
GetOldestCommitDateFunc: &StoreGetOldestCommitDateFunc{
defaultHook: i.GetOldestCommitDate,
},
GetRecentIndexesSummaryFunc: &StoreGetRecentIndexesSummaryFunc{
defaultHook: i.GetRecentIndexesSummary,
},
@ -2651,6 +2653,118 @@ func (c StoreGetAuditLogsForUploadFuncCall) Results() []interface{} {
return []interface{}{c.Result0, c.Result1}
}
// StoreGetCommitAndDateForOldestUploadFunc describes the behavior when the
// GetCommitAndDateForOldestUpload method of the parent MockStore instance
// is invoked.
type StoreGetCommitAndDateForOldestUploadFunc struct {
defaultHook func(context.Context, int) (core.Option[store.CommitWithDate], error)
hooks []func(context.Context, int) (core.Option[store.CommitWithDate], error)
history []StoreGetCommitAndDateForOldestUploadFuncCall
mutex sync.Mutex
}
// GetCommitAndDateForOldestUpload delegates to the next hook function in
// the queue and stores the parameter and result values of this invocation.
func (m *MockStore) GetCommitAndDateForOldestUpload(v0 context.Context, v1 int) (core.Option[store.CommitWithDate], error) {
r0, r1 := m.GetCommitAndDateForOldestUploadFunc.nextHook()(v0, v1)
m.GetCommitAndDateForOldestUploadFunc.appendCall(StoreGetCommitAndDateForOldestUploadFuncCall{v0, v1, r0, r1})
return r0, r1
}
// SetDefaultHook sets function that is called when the
// GetCommitAndDateForOldestUpload method of the parent MockStore instance
// is invoked and the hook queue is empty.
func (f *StoreGetCommitAndDateForOldestUploadFunc) SetDefaultHook(hook func(context.Context, int) (core.Option[store.CommitWithDate], error)) {
f.defaultHook = hook
}
// PushHook adds a function to the end of hook queue. Each invocation of the
// GetCommitAndDateForOldestUpload method of the parent MockStore instance
// invokes the hook at the front of the queue and discards it. After the
// queue is empty, the default hook function is invoked for any future
// action.
func (f *StoreGetCommitAndDateForOldestUploadFunc) PushHook(hook func(context.Context, int) (core.Option[store.CommitWithDate], error)) {
f.mutex.Lock()
f.hooks = append(f.hooks, hook)
f.mutex.Unlock()
}
// SetDefaultReturn calls SetDefaultHook with a function that returns the
// given values.
func (f *StoreGetCommitAndDateForOldestUploadFunc) SetDefaultReturn(r0 core.Option[store.CommitWithDate], r1 error) {
f.SetDefaultHook(func(context.Context, int) (core.Option[store.CommitWithDate], error) {
return r0, r1
})
}
// PushReturn calls PushHook with a function that returns the given values.
func (f *StoreGetCommitAndDateForOldestUploadFunc) PushReturn(r0 core.Option[store.CommitWithDate], r1 error) {
f.PushHook(func(context.Context, int) (core.Option[store.CommitWithDate], error) {
return r0, r1
})
}
func (f *StoreGetCommitAndDateForOldestUploadFunc) nextHook() func(context.Context, int) (core.Option[store.CommitWithDate], error) {
f.mutex.Lock()
defer f.mutex.Unlock()
if len(f.hooks) == 0 {
return f.defaultHook
}
hook := f.hooks[0]
f.hooks = f.hooks[1:]
return hook
}
func (f *StoreGetCommitAndDateForOldestUploadFunc) appendCall(r0 StoreGetCommitAndDateForOldestUploadFuncCall) {
f.mutex.Lock()
f.history = append(f.history, r0)
f.mutex.Unlock()
}
// History returns a sequence of
// StoreGetCommitAndDateForOldestUploadFuncCall objects describing the
// invocations of this function.
func (f *StoreGetCommitAndDateForOldestUploadFunc) History() []StoreGetCommitAndDateForOldestUploadFuncCall {
f.mutex.Lock()
history := make([]StoreGetCommitAndDateForOldestUploadFuncCall, len(f.history))
copy(history, f.history)
f.mutex.Unlock()
return history
}
// StoreGetCommitAndDateForOldestUploadFuncCall is an object that describes
// an invocation of method GetCommitAndDateForOldestUpload on an instance of
// MockStore.
type StoreGetCommitAndDateForOldestUploadFuncCall struct {
// Arg0 is the value of the 1st argument passed to this method
// invocation.
Arg0 context.Context
// Arg1 is the value of the 2nd argument passed to this method
// invocation.
Arg1 int
// Result0 is the value of the 1st result returned from this method
// invocation.
Result0 core.Option[store.CommitWithDate]
// Result1 is the value of the 2nd result returned from this method
// invocation.
Result1 error
}
// Args returns an interface slice containing the arguments of this
// invocation.
func (c StoreGetCommitAndDateForOldestUploadFuncCall) Args() []interface{} {
return []interface{}{c.Arg0, c.Arg1}
}
// Results returns an interface slice containing the results of this
// invocation.
func (c StoreGetCommitAndDateForOldestUploadFuncCall) Results() []interface{} {
return []interface{}{c.Result0, c.Result1}
}
// StoreGetCommitGraphMetadataFunc describes the behavior when the
// GetCommitGraphMetadata method of the parent MockStore instance is
// invoked.
@ -3766,117 +3880,6 @@ func (c StoreGetLastUploadRetentionScanForRepositoryFuncCall) Results() []interf
return []interface{}{c.Result0, c.Result1}
}
// StoreGetOldestCommitDateFunc describes the behavior when the
// GetOldestCommitDate method of the parent MockStore instance is invoked.
type StoreGetOldestCommitDateFunc struct {
defaultHook func(context.Context, int) (time.Time, bool, error)
hooks []func(context.Context, int) (time.Time, bool, error)
history []StoreGetOldestCommitDateFuncCall
mutex sync.Mutex
}
// GetOldestCommitDate delegates to the next hook function in the queue and
// stores the parameter and result values of this invocation.
func (m *MockStore) GetOldestCommitDate(v0 context.Context, v1 int) (time.Time, bool, error) {
r0, r1, r2 := m.GetOldestCommitDateFunc.nextHook()(v0, v1)
m.GetOldestCommitDateFunc.appendCall(StoreGetOldestCommitDateFuncCall{v0, v1, r0, r1, r2})
return r0, r1, r2
}
// SetDefaultHook sets function that is called when the GetOldestCommitDate
// method of the parent MockStore instance is invoked and the hook queue is
// empty.
func (f *StoreGetOldestCommitDateFunc) SetDefaultHook(hook func(context.Context, int) (time.Time, bool, error)) {
f.defaultHook = hook
}
// PushHook adds a function to the end of hook queue. Each invocation of the
// GetOldestCommitDate method of the parent MockStore instance invokes the
// hook at the front of the queue and discards it. After the queue is empty,
// the default hook function is invoked for any future action.
func (f *StoreGetOldestCommitDateFunc) PushHook(hook func(context.Context, int) (time.Time, bool, error)) {
f.mutex.Lock()
f.hooks = append(f.hooks, hook)
f.mutex.Unlock()
}
// SetDefaultReturn calls SetDefaultHook with a function that returns the
// given values.
func (f *StoreGetOldestCommitDateFunc) SetDefaultReturn(r0 time.Time, r1 bool, r2 error) {
f.SetDefaultHook(func(context.Context, int) (time.Time, bool, error) {
return r0, r1, r2
})
}
// PushReturn calls PushHook with a function that returns the given values.
func (f *StoreGetOldestCommitDateFunc) PushReturn(r0 time.Time, r1 bool, r2 error) {
f.PushHook(func(context.Context, int) (time.Time, bool, error) {
return r0, r1, r2
})
}
func (f *StoreGetOldestCommitDateFunc) nextHook() func(context.Context, int) (time.Time, bool, error) {
f.mutex.Lock()
defer f.mutex.Unlock()
if len(f.hooks) == 0 {
return f.defaultHook
}
hook := f.hooks[0]
f.hooks = f.hooks[1:]
return hook
}
func (f *StoreGetOldestCommitDateFunc) appendCall(r0 StoreGetOldestCommitDateFuncCall) {
f.mutex.Lock()
f.history = append(f.history, r0)
f.mutex.Unlock()
}
// History returns a sequence of StoreGetOldestCommitDateFuncCall objects
// describing the invocations of this function.
func (f *StoreGetOldestCommitDateFunc) History() []StoreGetOldestCommitDateFuncCall {
f.mutex.Lock()
history := make([]StoreGetOldestCommitDateFuncCall, len(f.history))
copy(history, f.history)
f.mutex.Unlock()
return history
}
// StoreGetOldestCommitDateFuncCall is an object that describes an
// invocation of method GetOldestCommitDate on an instance of MockStore.
type StoreGetOldestCommitDateFuncCall struct {
// Arg0 is the value of the 1st argument passed to this method
// invocation.
Arg0 context.Context
// Arg1 is the value of the 2nd argument passed to this method
// invocation.
Arg1 int
// Result0 is the value of the 1st result returned from this method
// invocation.
Result0 time.Time
// Result1 is the value of the 2nd result returned from this method
// invocation.
Result1 bool
// Result2 is the value of the 3rd result returned from this method
// invocation.
Result2 error
}
// Args returns an interface slice containing the arguments of this
// invocation.
func (c StoreGetOldestCommitDateFuncCall) Args() []interface{} {
return []interface{}{c.Arg0, c.Arg1}
}
// Results returns an interface slice containing the results of this
// invocation.
func (c StoreGetOldestCommitDateFuncCall) Results() []interface{} {
return []interface{}{c.Result0, c.Result1, c.Result2}
}
// StoreGetRecentIndexesSummaryFunc describes the behavior when the
// GetRecentIndexesSummary method of the parent MockStore instance is
// invoked.

View File

@ -15,11 +15,14 @@ go_library(
"//internal/api",
"//internal/codeintel/uploads/internal/commitgraph",
"//internal/codeintel/uploads/internal/store",
"//internal/conf",
"//internal/database/locker",
"//internal/env",
"//internal/gitserver",
"//internal/gitserver/gitdomain",
"//internal/goroutine",
"//lib/errors",
"@com_github_grafana_regexp//:regexp",
"@com_github_life4_genesis//slices",
],
)

View File

@ -2,12 +2,17 @@ package commitgraph
import (
"context"
"fmt"
"time"
"github.com/grafana/regexp"
genslices "github.com/life4/genesis/slices"
"github.com/sourcegraph/sourcegraph/internal/actor"
"github.com/sourcegraph/sourcegraph/internal/api"
"github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/internal/commitgraph"
"github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/internal/store"
"github.com/sourcegraph/sourcegraph/internal/conf"
"github.com/sourcegraph/sourcegraph/internal/database/locker"
"github.com/sourcegraph/sourcegraph/internal/gitserver"
"github.com/sourcegraph/sourcegraph/internal/gitserver/gitdomain"
@ -126,6 +131,13 @@ func mapRefsToCommits(refs []gitdomain.Ref) map[string][]gitdomain.Ref {
return commitsByRef
}
type CommitGraphRefreshStrategy string
const (
HeadTopoOnly CommitGraphRefreshStrategy = "head-topo-only"
AllRefsSince CommitGraphRefreshStrategy = "all-refs-since"
)
// getCommitGraph builds a partial commit graph that includes the most recent commits on each branch
// extending back as as the date of the oldest commit for which we have a processed upload for this
// repository.
@ -138,25 +150,53 @@ func mapRefsToCommits(refs []gitdomain.Ref) map[string][]gitdomain.Ref {
// accelerating rate, as we routinely expire old information for active repositories in a janitor
// process.
func (s *commitGraphUpdater) getCommitGraph(ctx context.Context, repositoryID int, repo api.RepoName) (*commitgraph.CommitGraph, error) {
commitDate, ok, err := s.store.GetOldestCommitDate(ctx, repositoryID)
optCommitWithDate, err := s.store.GetCommitAndDateForOldestUpload(ctx, repositoryID)
if err != nil {
return nil, err
}
commitWithDate, ok := optCommitWithDate.Get()
if !ok {
// No uploads exist for this repository
return commitgraph.ParseCommitGraph(nil), nil
}
// The --since flag for git log is exclusive, but we want to include the commit where the
// oldest dump is defined. This flag only has second resolution, so we shouldn't be pulling
// back any more data than we wanted.
commitDate = commitDate.Add(-time.Second)
siteConfig := conf.SiteConfig()
exptFeatures := siteConfig.ExperimentalFeatures
var strat CommitGraphRefreshStrategy = AllRefsSince
var defaultBranchRef string
if exptFeatures != nil && exptFeatures.CommitGraphUpdates != nil {
match := genslices.Any(exptFeatures.CommitGraphUpdates.DefaultBranchOnly, func(repoPattern string) bool {
matched, err := regexp.MatchString(repoPattern, string(repo))
return err == nil && matched
})
if match {
if refName, _, err := s.gitserverClient.GetDefaultBranch(ctx, repo, false); err == nil {
defaultBranchRef = refName
strat = HeadTopoOnly
}
}
}
commits, err := s.gitserverClient.Commits(ctx, repo, gitserver.CommitsOptions{
AllRefs: true,
Order: gitserver.CommitsOrderTopoDate,
After: commitDate,
})
var opts gitserver.CommitsOptions
switch strat {
case HeadTopoOnly:
opts = gitserver.CommitsOptions{
Ranges: []string{string(commitWithDate.Commit) + ".." + defaultBranchRef},
Order: gitserver.CommitsOrderTopoDate,
}
case AllRefsSince:
opts = gitserver.CommitsOptions{
AllRefs: true,
Order: gitserver.CommitsOrderTopoDate,
// The --since flag for git log is exclusive, but we want to include the commit where the
// oldest dump is defined. This flag only has second resolution, so we shouldn't be pulling
// back any more data than we wanted.
After: commitWithDate.CommitterDate.Add(-time.Second),
}
default:
panic(fmt.Sprintf("Unhandled case for strategy: %q", strat))
}
commits, err := s.gitserverClient.Commits(ctx, repo, opts)
if err != nil {
return nil, errors.Wrap(err, "gitserver.Commits")
}

View File

@ -42,6 +42,7 @@ go_test(
tags = [TAG_PLATFORM_GRAPH],
deps = [
"//internal/api",
"//internal/codeintel/core",
"//internal/codeintel/policies",
"//internal/codeintel/policies/shared",
"//internal/codeintel/uploads/internal/commitgraph",

View File

@ -14,6 +14,7 @@ import (
sqlf "github.com/keegancsmith/sqlf"
scip "github.com/sourcegraph/scip/bindings/go/scip"
api "github.com/sourcegraph/sourcegraph/internal/api"
core "github.com/sourcegraph/sourcegraph/internal/codeintel/core"
policies "github.com/sourcegraph/sourcegraph/internal/codeintel/policies"
shared "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/shared"
commitgraph "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/internal/commitgraph"
@ -418,6 +419,10 @@ type MockStore struct {
// GetAuditLogsForUploadFunc is an instance of a mock function object
// controlling the behavior of the method GetAuditLogsForUpload.
GetAuditLogsForUploadFunc *StoreGetAuditLogsForUploadFunc
// GetCommitAndDateForOldestUploadFunc is an instance of a mock function
// object controlling the behavior of the method
// GetCommitAndDateForOldestUpload.
GetCommitAndDateForOldestUploadFunc *StoreGetCommitAndDateForOldestUploadFunc
// GetCommitGraphMetadataFunc is an instance of a mock function object
// controlling the behavior of the method GetCommitGraphMetadata.
GetCommitGraphMetadataFunc *StoreGetCommitGraphMetadataFunc
@ -451,9 +456,6 @@ type MockStore struct {
// function object controlling the behavior of the method
// GetLastUploadRetentionScanForRepository.
GetLastUploadRetentionScanForRepositoryFunc *StoreGetLastUploadRetentionScanForRepositoryFunc
// GetOldestCommitDateFunc is an instance of a mock function object
// controlling the behavior of the method GetOldestCommitDate.
GetOldestCommitDateFunc *StoreGetOldestCommitDateFunc
// GetRecentIndexesSummaryFunc is an instance of a mock function object
// controlling the behavior of the method GetRecentIndexesSummary.
GetRecentIndexesSummaryFunc *StoreGetRecentIndexesSummaryFunc
@ -658,6 +660,11 @@ func NewMockStore() *MockStore {
return
},
},
GetCommitAndDateForOldestUploadFunc: &StoreGetCommitAndDateForOldestUploadFunc{
defaultHook: func(context.Context, int) (r0 core.Option[store.CommitWithDate], r1 error) {
return
},
},
GetCommitGraphMetadataFunc: &StoreGetCommitGraphMetadataFunc{
defaultHook: func(context.Context, int) (r0 bool, r1 *time.Time, r2 error) {
return
@ -708,11 +715,6 @@ func NewMockStore() *MockStore {
return
},
},
GetOldestCommitDateFunc: &StoreGetOldestCommitDateFunc{
defaultHook: func(context.Context, int) (r0 time.Time, r1 bool, r2 error) {
return
},
},
GetRecentIndexesSummaryFunc: &StoreGetRecentIndexesSummaryFunc{
defaultHook: func(context.Context, int) (r0 []shared1.IndexesWithRepositoryNamespace, r1 error) {
return
@ -985,6 +987,11 @@ func NewStrictMockStore() *MockStore {
panic("unexpected invocation of MockStore.GetAuditLogsForUpload")
},
},
GetCommitAndDateForOldestUploadFunc: &StoreGetCommitAndDateForOldestUploadFunc{
defaultHook: func(context.Context, int) (core.Option[store.CommitWithDate], error) {
panic("unexpected invocation of MockStore.GetCommitAndDateForOldestUpload")
},
},
GetCommitGraphMetadataFunc: &StoreGetCommitGraphMetadataFunc{
defaultHook: func(context.Context, int) (bool, *time.Time, error) {
panic("unexpected invocation of MockStore.GetCommitGraphMetadata")
@ -1035,11 +1042,6 @@ func NewStrictMockStore() *MockStore {
panic("unexpected invocation of MockStore.GetLastUploadRetentionScanForRepository")
},
},
GetOldestCommitDateFunc: &StoreGetOldestCommitDateFunc{
defaultHook: func(context.Context, int) (time.Time, bool, error) {
panic("unexpected invocation of MockStore.GetOldestCommitDate")
},
},
GetRecentIndexesSummaryFunc: &StoreGetRecentIndexesSummaryFunc{
defaultHook: func(context.Context, int) ([]shared1.IndexesWithRepositoryNamespace, error) {
panic("unexpected invocation of MockStore.GetRecentIndexesSummary")
@ -1284,6 +1286,9 @@ func NewMockStoreFrom(i store.Store) *MockStore {
GetAuditLogsForUploadFunc: &StoreGetAuditLogsForUploadFunc{
defaultHook: i.GetAuditLogsForUpload,
},
GetCommitAndDateForOldestUploadFunc: &StoreGetCommitAndDateForOldestUploadFunc{
defaultHook: i.GetCommitAndDateForOldestUpload,
},
GetCommitGraphMetadataFunc: &StoreGetCommitGraphMetadataFunc{
defaultHook: i.GetCommitGraphMetadata,
},
@ -1314,9 +1319,6 @@ func NewMockStoreFrom(i store.Store) *MockStore {
GetLastUploadRetentionScanForRepositoryFunc: &StoreGetLastUploadRetentionScanForRepositoryFunc{
defaultHook: i.GetLastUploadRetentionScanForRepository,
},
GetOldestCommitDateFunc: &StoreGetOldestCommitDateFunc{
defaultHook: i.GetOldestCommitDate,
},
GetRecentIndexesSummaryFunc: &StoreGetRecentIndexesSummaryFunc{
defaultHook: i.GetRecentIndexesSummary,
},
@ -2994,6 +2996,118 @@ func (c StoreGetAuditLogsForUploadFuncCall) Results() []interface{} {
return []interface{}{c.Result0, c.Result1}
}
// StoreGetCommitAndDateForOldestUploadFunc describes the behavior when the
// GetCommitAndDateForOldestUpload method of the parent MockStore instance
// is invoked.
type StoreGetCommitAndDateForOldestUploadFunc struct {
defaultHook func(context.Context, int) (core.Option[store.CommitWithDate], error)
hooks []func(context.Context, int) (core.Option[store.CommitWithDate], error)
history []StoreGetCommitAndDateForOldestUploadFuncCall
mutex sync.Mutex
}
// GetCommitAndDateForOldestUpload delegates to the next hook function in
// the queue and stores the parameter and result values of this invocation.
func (m *MockStore) GetCommitAndDateForOldestUpload(v0 context.Context, v1 int) (core.Option[store.CommitWithDate], error) {
r0, r1 := m.GetCommitAndDateForOldestUploadFunc.nextHook()(v0, v1)
m.GetCommitAndDateForOldestUploadFunc.appendCall(StoreGetCommitAndDateForOldestUploadFuncCall{v0, v1, r0, r1})
return r0, r1
}
// SetDefaultHook sets function that is called when the
// GetCommitAndDateForOldestUpload method of the parent MockStore instance
// is invoked and the hook queue is empty.
func (f *StoreGetCommitAndDateForOldestUploadFunc) SetDefaultHook(hook func(context.Context, int) (core.Option[store.CommitWithDate], error)) {
f.defaultHook = hook
}
// PushHook adds a function to the end of hook queue. Each invocation of the
// GetCommitAndDateForOldestUpload method of the parent MockStore instance
// invokes the hook at the front of the queue and discards it. After the
// queue is empty, the default hook function is invoked for any future
// action.
func (f *StoreGetCommitAndDateForOldestUploadFunc) PushHook(hook func(context.Context, int) (core.Option[store.CommitWithDate], error)) {
f.mutex.Lock()
f.hooks = append(f.hooks, hook)
f.mutex.Unlock()
}
// SetDefaultReturn calls SetDefaultHook with a function that returns the
// given values.
func (f *StoreGetCommitAndDateForOldestUploadFunc) SetDefaultReturn(r0 core.Option[store.CommitWithDate], r1 error) {
f.SetDefaultHook(func(context.Context, int) (core.Option[store.CommitWithDate], error) {
return r0, r1
})
}
// PushReturn calls PushHook with a function that returns the given values.
func (f *StoreGetCommitAndDateForOldestUploadFunc) PushReturn(r0 core.Option[store.CommitWithDate], r1 error) {
f.PushHook(func(context.Context, int) (core.Option[store.CommitWithDate], error) {
return r0, r1
})
}
func (f *StoreGetCommitAndDateForOldestUploadFunc) nextHook() func(context.Context, int) (core.Option[store.CommitWithDate], error) {
f.mutex.Lock()
defer f.mutex.Unlock()
if len(f.hooks) == 0 {
return f.defaultHook
}
hook := f.hooks[0]
f.hooks = f.hooks[1:]
return hook
}
func (f *StoreGetCommitAndDateForOldestUploadFunc) appendCall(r0 StoreGetCommitAndDateForOldestUploadFuncCall) {
f.mutex.Lock()
f.history = append(f.history, r0)
f.mutex.Unlock()
}
// History returns a sequence of
// StoreGetCommitAndDateForOldestUploadFuncCall objects describing the
// invocations of this function.
func (f *StoreGetCommitAndDateForOldestUploadFunc) History() []StoreGetCommitAndDateForOldestUploadFuncCall {
f.mutex.Lock()
history := make([]StoreGetCommitAndDateForOldestUploadFuncCall, len(f.history))
copy(history, f.history)
f.mutex.Unlock()
return history
}
// StoreGetCommitAndDateForOldestUploadFuncCall is an object that describes
// an invocation of method GetCommitAndDateForOldestUpload on an instance of
// MockStore.
type StoreGetCommitAndDateForOldestUploadFuncCall struct {
// Arg0 is the value of the 1st argument passed to this method
// invocation.
Arg0 context.Context
// Arg1 is the value of the 2nd argument passed to this method
// invocation.
Arg1 int
// Result0 is the value of the 1st result returned from this method
// invocation.
Result0 core.Option[store.CommitWithDate]
// Result1 is the value of the 2nd result returned from this method
// invocation.
Result1 error
}
// Args returns an interface slice containing the arguments of this
// invocation.
func (c StoreGetCommitAndDateForOldestUploadFuncCall) Args() []interface{} {
return []interface{}{c.Arg0, c.Arg1}
}
// Results returns an interface slice containing the results of this
// invocation.
func (c StoreGetCommitAndDateForOldestUploadFuncCall) Results() []interface{} {
return []interface{}{c.Result0, c.Result1}
}
// StoreGetCommitGraphMetadataFunc describes the behavior when the
// GetCommitGraphMetadata method of the parent MockStore instance is
// invoked.
@ -4109,117 +4223,6 @@ func (c StoreGetLastUploadRetentionScanForRepositoryFuncCall) Results() []interf
return []interface{}{c.Result0, c.Result1}
}
// StoreGetOldestCommitDateFunc describes the behavior when the
// GetOldestCommitDate method of the parent MockStore instance is invoked.
type StoreGetOldestCommitDateFunc struct {
defaultHook func(context.Context, int) (time.Time, bool, error)
hooks []func(context.Context, int) (time.Time, bool, error)
history []StoreGetOldestCommitDateFuncCall
mutex sync.Mutex
}
// GetOldestCommitDate delegates to the next hook function in the queue and
// stores the parameter and result values of this invocation.
func (m *MockStore) GetOldestCommitDate(v0 context.Context, v1 int) (time.Time, bool, error) {
r0, r1, r2 := m.GetOldestCommitDateFunc.nextHook()(v0, v1)
m.GetOldestCommitDateFunc.appendCall(StoreGetOldestCommitDateFuncCall{v0, v1, r0, r1, r2})
return r0, r1, r2
}
// SetDefaultHook sets function that is called when the GetOldestCommitDate
// method of the parent MockStore instance is invoked and the hook queue is
// empty.
func (f *StoreGetOldestCommitDateFunc) SetDefaultHook(hook func(context.Context, int) (time.Time, bool, error)) {
f.defaultHook = hook
}
// PushHook adds a function to the end of hook queue. Each invocation of the
// GetOldestCommitDate method of the parent MockStore instance invokes the
// hook at the front of the queue and discards it. After the queue is empty,
// the default hook function is invoked for any future action.
func (f *StoreGetOldestCommitDateFunc) PushHook(hook func(context.Context, int) (time.Time, bool, error)) {
f.mutex.Lock()
f.hooks = append(f.hooks, hook)
f.mutex.Unlock()
}
// SetDefaultReturn calls SetDefaultHook with a function that returns the
// given values.
func (f *StoreGetOldestCommitDateFunc) SetDefaultReturn(r0 time.Time, r1 bool, r2 error) {
f.SetDefaultHook(func(context.Context, int) (time.Time, bool, error) {
return r0, r1, r2
})
}
// PushReturn calls PushHook with a function that returns the given values.
func (f *StoreGetOldestCommitDateFunc) PushReturn(r0 time.Time, r1 bool, r2 error) {
f.PushHook(func(context.Context, int) (time.Time, bool, error) {
return r0, r1, r2
})
}
func (f *StoreGetOldestCommitDateFunc) nextHook() func(context.Context, int) (time.Time, bool, error) {
f.mutex.Lock()
defer f.mutex.Unlock()
if len(f.hooks) == 0 {
return f.defaultHook
}
hook := f.hooks[0]
f.hooks = f.hooks[1:]
return hook
}
func (f *StoreGetOldestCommitDateFunc) appendCall(r0 StoreGetOldestCommitDateFuncCall) {
f.mutex.Lock()
f.history = append(f.history, r0)
f.mutex.Unlock()
}
// History returns a sequence of StoreGetOldestCommitDateFuncCall objects
// describing the invocations of this function.
func (f *StoreGetOldestCommitDateFunc) History() []StoreGetOldestCommitDateFuncCall {
f.mutex.Lock()
history := make([]StoreGetOldestCommitDateFuncCall, len(f.history))
copy(history, f.history)
f.mutex.Unlock()
return history
}
// StoreGetOldestCommitDateFuncCall is an object that describes an
// invocation of method GetOldestCommitDate on an instance of MockStore.
type StoreGetOldestCommitDateFuncCall struct {
// Arg0 is the value of the 1st argument passed to this method
// invocation.
Arg0 context.Context
// Arg1 is the value of the 2nd argument passed to this method
// invocation.
Arg1 int
// Result0 is the value of the 1st result returned from this method
// invocation.
Result0 time.Time
// Result1 is the value of the 2nd result returned from this method
// invocation.
Result1 bool
// Result2 is the value of the 3rd result returned from this method
// invocation.
Result2 error
}
// Args returns an interface slice containing the arguments of this
// invocation.
func (c StoreGetOldestCommitDateFuncCall) Args() []interface{} {
return []interface{}{c.Arg0, c.Arg1}
}
// Results returns an interface slice containing the results of this
// invocation.
func (c StoreGetOldestCommitDateFuncCall) Results() []interface{} {
return []interface{}{c.Result0, c.Result1, c.Result2}
}
// StoreGetRecentIndexesSummaryFunc describes the behavior when the
// GetRecentIndexesSummary method of the parent MockStore instance is
// invoked.

View File

@ -58,6 +58,7 @@ go_test(
deps = [
"//cmd/frontend/backend",
"//internal/api",
"//internal/codeintel/core",
"//internal/codeintel/uploads/internal/commitgraph",
"//internal/codeintel/uploads/internal/lsifstore",
"//internal/codeintel/uploads/internal/store",

View File

@ -14,6 +14,7 @@ import (
sqlf "github.com/keegancsmith/sqlf"
scip "github.com/sourcegraph/scip/bindings/go/scip"
api "github.com/sourcegraph/sourcegraph/internal/api"
core "github.com/sourcegraph/sourcegraph/internal/codeintel/core"
commitgraph "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/internal/commitgraph"
lsifstore "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/internal/lsifstore"
store "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/internal/store"
@ -232,6 +233,10 @@ type MockStore struct {
// GetAuditLogsForUploadFunc is an instance of a mock function object
// controlling the behavior of the method GetAuditLogsForUpload.
GetAuditLogsForUploadFunc *StoreGetAuditLogsForUploadFunc
// GetCommitAndDateForOldestUploadFunc is an instance of a mock function
// object controlling the behavior of the method
// GetCommitAndDateForOldestUpload.
GetCommitAndDateForOldestUploadFunc *StoreGetCommitAndDateForOldestUploadFunc
// GetCommitGraphMetadataFunc is an instance of a mock function object
// controlling the behavior of the method GetCommitGraphMetadata.
GetCommitGraphMetadataFunc *StoreGetCommitGraphMetadataFunc
@ -265,9 +270,6 @@ type MockStore struct {
// function object controlling the behavior of the method
// GetLastUploadRetentionScanForRepository.
GetLastUploadRetentionScanForRepositoryFunc *StoreGetLastUploadRetentionScanForRepositoryFunc
// GetOldestCommitDateFunc is an instance of a mock function object
// controlling the behavior of the method GetOldestCommitDate.
GetOldestCommitDateFunc *StoreGetOldestCommitDateFunc
// GetRecentIndexesSummaryFunc is an instance of a mock function object
// controlling the behavior of the method GetRecentIndexesSummary.
GetRecentIndexesSummaryFunc *StoreGetRecentIndexesSummaryFunc
@ -472,6 +474,11 @@ func NewMockStore() *MockStore {
return
},
},
GetCommitAndDateForOldestUploadFunc: &StoreGetCommitAndDateForOldestUploadFunc{
defaultHook: func(context.Context, int) (r0 core.Option[store.CommitWithDate], r1 error) {
return
},
},
GetCommitGraphMetadataFunc: &StoreGetCommitGraphMetadataFunc{
defaultHook: func(context.Context, int) (r0 bool, r1 *time.Time, r2 error) {
return
@ -522,11 +529,6 @@ func NewMockStore() *MockStore {
return
},
},
GetOldestCommitDateFunc: &StoreGetOldestCommitDateFunc{
defaultHook: func(context.Context, int) (r0 time.Time, r1 bool, r2 error) {
return
},
},
GetRecentIndexesSummaryFunc: &StoreGetRecentIndexesSummaryFunc{
defaultHook: func(context.Context, int) (r0 []shared.IndexesWithRepositoryNamespace, r1 error) {
return
@ -799,6 +801,11 @@ func NewStrictMockStore() *MockStore {
panic("unexpected invocation of MockStore.GetAuditLogsForUpload")
},
},
GetCommitAndDateForOldestUploadFunc: &StoreGetCommitAndDateForOldestUploadFunc{
defaultHook: func(context.Context, int) (core.Option[store.CommitWithDate], error) {
panic("unexpected invocation of MockStore.GetCommitAndDateForOldestUpload")
},
},
GetCommitGraphMetadataFunc: &StoreGetCommitGraphMetadataFunc{
defaultHook: func(context.Context, int) (bool, *time.Time, error) {
panic("unexpected invocation of MockStore.GetCommitGraphMetadata")
@ -849,11 +856,6 @@ func NewStrictMockStore() *MockStore {
panic("unexpected invocation of MockStore.GetLastUploadRetentionScanForRepository")
},
},
GetOldestCommitDateFunc: &StoreGetOldestCommitDateFunc{
defaultHook: func(context.Context, int) (time.Time, bool, error) {
panic("unexpected invocation of MockStore.GetOldestCommitDate")
},
},
GetRecentIndexesSummaryFunc: &StoreGetRecentIndexesSummaryFunc{
defaultHook: func(context.Context, int) ([]shared.IndexesWithRepositoryNamespace, error) {
panic("unexpected invocation of MockStore.GetRecentIndexesSummary")
@ -1098,6 +1100,9 @@ func NewMockStoreFrom(i store.Store) *MockStore {
GetAuditLogsForUploadFunc: &StoreGetAuditLogsForUploadFunc{
defaultHook: i.GetAuditLogsForUpload,
},
GetCommitAndDateForOldestUploadFunc: &StoreGetCommitAndDateForOldestUploadFunc{
defaultHook: i.GetCommitAndDateForOldestUpload,
},
GetCommitGraphMetadataFunc: &StoreGetCommitGraphMetadataFunc{
defaultHook: i.GetCommitGraphMetadata,
},
@ -1128,9 +1133,6 @@ func NewMockStoreFrom(i store.Store) *MockStore {
GetLastUploadRetentionScanForRepositoryFunc: &StoreGetLastUploadRetentionScanForRepositoryFunc{
defaultHook: i.GetLastUploadRetentionScanForRepository,
},
GetOldestCommitDateFunc: &StoreGetOldestCommitDateFunc{
defaultHook: i.GetOldestCommitDate,
},
GetRecentIndexesSummaryFunc: &StoreGetRecentIndexesSummaryFunc{
defaultHook: i.GetRecentIndexesSummary,
},
@ -2808,6 +2810,118 @@ func (c StoreGetAuditLogsForUploadFuncCall) Results() []interface{} {
return []interface{}{c.Result0, c.Result1}
}
// StoreGetCommitAndDateForOldestUploadFunc describes the behavior when the
// GetCommitAndDateForOldestUpload method of the parent MockStore instance
// is invoked.
type StoreGetCommitAndDateForOldestUploadFunc struct {
defaultHook func(context.Context, int) (core.Option[store.CommitWithDate], error)
hooks []func(context.Context, int) (core.Option[store.CommitWithDate], error)
history []StoreGetCommitAndDateForOldestUploadFuncCall
mutex sync.Mutex
}
// GetCommitAndDateForOldestUpload delegates to the next hook function in
// the queue and stores the parameter and result values of this invocation.
func (m *MockStore) GetCommitAndDateForOldestUpload(v0 context.Context, v1 int) (core.Option[store.CommitWithDate], error) {
r0, r1 := m.GetCommitAndDateForOldestUploadFunc.nextHook()(v0, v1)
m.GetCommitAndDateForOldestUploadFunc.appendCall(StoreGetCommitAndDateForOldestUploadFuncCall{v0, v1, r0, r1})
return r0, r1
}
// SetDefaultHook sets function that is called when the
// GetCommitAndDateForOldestUpload method of the parent MockStore instance
// is invoked and the hook queue is empty.
func (f *StoreGetCommitAndDateForOldestUploadFunc) SetDefaultHook(hook func(context.Context, int) (core.Option[store.CommitWithDate], error)) {
f.defaultHook = hook
}
// PushHook adds a function to the end of hook queue. Each invocation of the
// GetCommitAndDateForOldestUpload method of the parent MockStore instance
// invokes the hook at the front of the queue and discards it. After the
// queue is empty, the default hook function is invoked for any future
// action.
func (f *StoreGetCommitAndDateForOldestUploadFunc) PushHook(hook func(context.Context, int) (core.Option[store.CommitWithDate], error)) {
f.mutex.Lock()
f.hooks = append(f.hooks, hook)
f.mutex.Unlock()
}
// SetDefaultReturn calls SetDefaultHook with a function that returns the
// given values.
func (f *StoreGetCommitAndDateForOldestUploadFunc) SetDefaultReturn(r0 core.Option[store.CommitWithDate], r1 error) {
f.SetDefaultHook(func(context.Context, int) (core.Option[store.CommitWithDate], error) {
return r0, r1
})
}
// PushReturn calls PushHook with a function that returns the given values.
func (f *StoreGetCommitAndDateForOldestUploadFunc) PushReturn(r0 core.Option[store.CommitWithDate], r1 error) {
f.PushHook(func(context.Context, int) (core.Option[store.CommitWithDate], error) {
return r0, r1
})
}
func (f *StoreGetCommitAndDateForOldestUploadFunc) nextHook() func(context.Context, int) (core.Option[store.CommitWithDate], error) {
f.mutex.Lock()
defer f.mutex.Unlock()
if len(f.hooks) == 0 {
return f.defaultHook
}
hook := f.hooks[0]
f.hooks = f.hooks[1:]
return hook
}
func (f *StoreGetCommitAndDateForOldestUploadFunc) appendCall(r0 StoreGetCommitAndDateForOldestUploadFuncCall) {
f.mutex.Lock()
f.history = append(f.history, r0)
f.mutex.Unlock()
}
// History returns a sequence of
// StoreGetCommitAndDateForOldestUploadFuncCall objects describing the
// invocations of this function.
func (f *StoreGetCommitAndDateForOldestUploadFunc) History() []StoreGetCommitAndDateForOldestUploadFuncCall {
f.mutex.Lock()
history := make([]StoreGetCommitAndDateForOldestUploadFuncCall, len(f.history))
copy(history, f.history)
f.mutex.Unlock()
return history
}
// StoreGetCommitAndDateForOldestUploadFuncCall is an object that describes
// an invocation of method GetCommitAndDateForOldestUpload on an instance of
// MockStore.
type StoreGetCommitAndDateForOldestUploadFuncCall struct {
// Arg0 is the value of the 1st argument passed to this method
// invocation.
Arg0 context.Context
// Arg1 is the value of the 2nd argument passed to this method
// invocation.
Arg1 int
// Result0 is the value of the 1st result returned from this method
// invocation.
Result0 core.Option[store.CommitWithDate]
// Result1 is the value of the 2nd result returned from this method
// invocation.
Result1 error
}
// Args returns an interface slice containing the arguments of this
// invocation.
func (c StoreGetCommitAndDateForOldestUploadFuncCall) Args() []interface{} {
return []interface{}{c.Arg0, c.Arg1}
}
// Results returns an interface slice containing the results of this
// invocation.
func (c StoreGetCommitAndDateForOldestUploadFuncCall) Results() []interface{} {
return []interface{}{c.Result0, c.Result1}
}
// StoreGetCommitGraphMetadataFunc describes the behavior when the
// GetCommitGraphMetadata method of the parent MockStore instance is
// invoked.
@ -3923,117 +4037,6 @@ func (c StoreGetLastUploadRetentionScanForRepositoryFuncCall) Results() []interf
return []interface{}{c.Result0, c.Result1}
}
// StoreGetOldestCommitDateFunc describes the behavior when the
// GetOldestCommitDate method of the parent MockStore instance is invoked.
type StoreGetOldestCommitDateFunc struct {
defaultHook func(context.Context, int) (time.Time, bool, error)
hooks []func(context.Context, int) (time.Time, bool, error)
history []StoreGetOldestCommitDateFuncCall
mutex sync.Mutex
}
// GetOldestCommitDate delegates to the next hook function in the queue and
// stores the parameter and result values of this invocation.
func (m *MockStore) GetOldestCommitDate(v0 context.Context, v1 int) (time.Time, bool, error) {
r0, r1, r2 := m.GetOldestCommitDateFunc.nextHook()(v0, v1)
m.GetOldestCommitDateFunc.appendCall(StoreGetOldestCommitDateFuncCall{v0, v1, r0, r1, r2})
return r0, r1, r2
}
// SetDefaultHook sets function that is called when the GetOldestCommitDate
// method of the parent MockStore instance is invoked and the hook queue is
// empty.
func (f *StoreGetOldestCommitDateFunc) SetDefaultHook(hook func(context.Context, int) (time.Time, bool, error)) {
f.defaultHook = hook
}
// PushHook adds a function to the end of hook queue. Each invocation of the
// GetOldestCommitDate method of the parent MockStore instance invokes the
// hook at the front of the queue and discards it. After the queue is empty,
// the default hook function is invoked for any future action.
func (f *StoreGetOldestCommitDateFunc) PushHook(hook func(context.Context, int) (time.Time, bool, error)) {
f.mutex.Lock()
f.hooks = append(f.hooks, hook)
f.mutex.Unlock()
}
// SetDefaultReturn calls SetDefaultHook with a function that returns the
// given values.
func (f *StoreGetOldestCommitDateFunc) SetDefaultReturn(r0 time.Time, r1 bool, r2 error) {
f.SetDefaultHook(func(context.Context, int) (time.Time, bool, error) {
return r0, r1, r2
})
}
// PushReturn calls PushHook with a function that returns the given values.
func (f *StoreGetOldestCommitDateFunc) PushReturn(r0 time.Time, r1 bool, r2 error) {
f.PushHook(func(context.Context, int) (time.Time, bool, error) {
return r0, r1, r2
})
}
func (f *StoreGetOldestCommitDateFunc) nextHook() func(context.Context, int) (time.Time, bool, error) {
f.mutex.Lock()
defer f.mutex.Unlock()
if len(f.hooks) == 0 {
return f.defaultHook
}
hook := f.hooks[0]
f.hooks = f.hooks[1:]
return hook
}
func (f *StoreGetOldestCommitDateFunc) appendCall(r0 StoreGetOldestCommitDateFuncCall) {
f.mutex.Lock()
f.history = append(f.history, r0)
f.mutex.Unlock()
}
// History returns a sequence of StoreGetOldestCommitDateFuncCall objects
// describing the invocations of this function.
func (f *StoreGetOldestCommitDateFunc) History() []StoreGetOldestCommitDateFuncCall {
f.mutex.Lock()
history := make([]StoreGetOldestCommitDateFuncCall, len(f.history))
copy(history, f.history)
f.mutex.Unlock()
return history
}
// StoreGetOldestCommitDateFuncCall is an object that describes an
// invocation of method GetOldestCommitDate on an instance of MockStore.
type StoreGetOldestCommitDateFuncCall struct {
// Arg0 is the value of the 1st argument passed to this method
// invocation.
Arg0 context.Context
// Arg1 is the value of the 2nd argument passed to this method
// invocation.
Arg1 int
// Result0 is the value of the 1st result returned from this method
// invocation.
Result0 time.Time
// Result1 is the value of the 2nd result returned from this method
// invocation.
Result1 bool
// Result2 is the value of the 3rd result returned from this method
// invocation.
Result2 error
}
// Args returns an interface slice containing the arguments of this
// invocation.
func (c StoreGetOldestCommitDateFuncCall) Args() []interface{} {
return []interface{}{c.Arg0, c.Arg1}
}
// Results returns an interface slice containing the results of this
// invocation.
func (c StoreGetOldestCommitDateFuncCall) Results() []interface{} {
return []interface{}{c.Result0, c.Result1, c.Result2}
}
// StoreGetRecentIndexesSummaryFunc describes the behavior when the
// GetRecentIndexesSummary method of the parent MockStore instance is
// invoked.

View File

@ -23,6 +23,7 @@ go_library(
visibility = ["//:__subpackages__"],
deps = [
"//internal/api",
"//internal/codeintel/core",
"//internal/codeintel/uploads/internal/commitgraph",
"//internal/codeintel/uploads/shared",
"//internal/database",
@ -92,5 +93,6 @@ go_test(
"@com_github_lib_pq//:pq",
"@com_github_sourcegraph_log//:log",
"@com_github_sourcegraph_log//logtest",
"@com_github_stretchr_testify//require",
],
)

View File

@ -8,38 +8,56 @@ import (
"github.com/keegancsmith/sqlf"
"go.opentelemetry.io/otel/attribute"
"github.com/sourcegraph/sourcegraph/internal/api"
"github.com/sourcegraph/sourcegraph/internal/codeintel/core"
"github.com/sourcegraph/sourcegraph/internal/database/basestore"
"github.com/sourcegraph/sourcegraph/internal/database/dbutil"
"github.com/sourcegraph/sourcegraph/internal/observation"
)
// GetOldestCommitDate returns the oldest commit date for all uploads for the given repository. If there are no
// non-nil values, a false-valued flag is returned. If there are any null values, the commit date backfill job
// has not yet completed and an error is returned to prevent downstream expiration errors being made due to
// outdated commit graph data.
func (s *store) GetOldestCommitDate(ctx context.Context, repositoryID int) (_ time.Time, _ bool, err error) {
ctx, _, endObservation := s.operations.getOldestCommitDate.With(ctx, &err, observation.Args{Attrs: []attribute.KeyValue{
type CommitWithDate struct {
Commit api.CommitID
CommitterDate time.Time
}
// GetCommitDateForOldestUpload returns the oldest commit date for all uploads for the given repository.
// - If there are any null values, the commit date backfill job has not yet completed and
// an error is returned to prevent downstream expiration errors being made due to outdated commit graph data.
// - Otherwise if there are no non-nil timestamps, Some is returned.
func (s *store) GetCommitAndDateForOldestUpload(ctx context.Context, repositoryID int) (_ core.Option[CommitWithDate], err error) {
ctx, _, endObservation := s.operations.getCommitAndDateForOldestUpload.With(ctx, &err, observation.Args{Attrs: []attribute.KeyValue{
attribute.Int("repositoryID", repositoryID),
}})
defer endObservation(1, observation.Args{})
t, ok, err := basestore.ScanFirstNullTime(s.db.Query(ctx, sqlf.Sprintf(getOldestCommitDateQuery, repositoryID)))
if err != nil || !ok {
return time.Time{}, false, err
var none = core.None[CommitWithDate]()
type commitWithNullDate struct {
commit string
t *time.Time
}
if t == nil {
return time.Time{}, false, &backfillIncompleteError{repositoryID}
data, ok, err := basestore.NewFirstScanner(func(scanner dbutil.Scanner) (commitWithNullDate, error) {
var commit string
var t *time.Time
err := scanner.Scan(&commit, &t)
return commitWithNullDate{commit, t}, err
})(s.db.Query(ctx, sqlf.Sprintf(getCommitAndDateForOldestUploadQuery, repositoryID)))
if err != nil || !ok {
return none, err
}
if data.t == nil {
return none, &backfillIncompleteError{repositoryID}
}
return *t, true, nil
return core.Some(CommitWithDate{Commit: api.CommitID(data.commit), CommitterDate: *data.t}), nil
}
// Note: we check against '-infinity' here, as the backfill operation will use this sentinel value in the case
// that the commit is no longer know by gitserver. This allows the backfill migration to make progress without
// having pristine database.
const getOldestCommitDateQuery = `
const getCommitAndDateForOldestUploadQuery = `
SELECT
cd.committed_at
u.commit, cd.committed_at
FROM lsif_uploads u
LEFT JOIN codeintel_commit_dates cd ON cd.repository_id = u.repository_id AND cd.commit_bytea = decode(u.commit, 'hex')
WHERE

View File

@ -7,7 +7,9 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/sourcegraph/log/logtest"
"github.com/stretchr/testify/require"
"github.com/sourcegraph/sourcegraph/internal/api"
"github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared"
"github.com/sourcegraph/sourcegraph/internal/database"
"github.com/sourcegraph/sourcegraph/internal/database/dbtest"
@ -53,7 +55,7 @@ func TestGetOldestCommitDate(t *testing.T) {
}
}
if _, _, err := store.GetOldestCommitDate(context.Background(), 50); err == nil {
if _, err := store.GetCommitAndDateForOldestUpload(context.Background(), 50); err == nil {
t.Fatalf("expected error getting oldest commit date")
} else if !errors.Is(err, &backfillIncompleteError{50}) {
t.Fatalf("unexpected backfill error, got %q", err)
@ -64,12 +66,12 @@ func TestGetOldestCommitDate(t *testing.T) {
t.Fatalf("unexpected error updating commit date %s", err)
}
if commitDate, ok, err := store.GetOldestCommitDate(context.Background(), 50); err != nil {
if commitWithDate, err := store.GetCommitAndDateForOldestUpload(context.Background(), 50); err != nil {
t.Fatalf("unexpected error getting oldest commit date: %s", err)
} else if !ok {
} else if commitWithDate.IsNone() {
t.Fatalf("expected commit date for repository")
} else if !commitDate.Equal(t3) {
t.Fatalf("unexpected commit date. want=%s have=%s", t3, commitDate)
} else {
require.Equal(t, CommitWithDate{Commit: api.CommitID(makeCommit(1)), CommitterDate: t3}, commitWithDate.Unwrap())
}
// Repo 51
@ -83,18 +85,18 @@ func TestGetOldestCommitDate(t *testing.T) {
}
}
if commitDate, ok, err := store.GetOldestCommitDate(context.Background(), 51); err != nil {
if commitAndDate, err := store.GetCommitAndDateForOldestUpload(context.Background(), 51); err != nil {
t.Fatalf("unexpected error getting oldest commit date: %s", err)
} else if !ok {
} else if commitAndDate.IsNone() {
t.Fatalf("expected commit date for repository")
} else if !commitDate.Equal(t2) {
t.Fatalf("unexpected commit date. want=%s have=%s", t2, commitDate)
} else {
require.Equal(t, CommitWithDate{Commit: api.CommitID(makeCommit(6)), CommitterDate: t2}, commitAndDate.Unwrap())
}
// Missing repository
if _, ok, err := store.GetOldestCommitDate(context.Background(), 52); err != nil {
if commitDate, err := store.GetCommitAndDateForOldestUpload(context.Background(), 52); err != nil {
t.Fatalf("unexpected error getting oldest commit date: %s", err)
} else if ok {
} else if commitDate.IsSome() {
t.Fatalf("unexpected commit date for repository")
}
}

View File

@ -16,7 +16,7 @@ type operations struct {
deleteSourcedCommits *observation.Operation
updateSourcedCommits *observation.Operation
getCommitsVisibleToUpload *observation.Operation
getOldestCommitDate *observation.Operation
getCommitAndDateForOldestUpload *observation.Operation
getCommitGraphMetadata *observation.Operation
hasCommit *observation.Operation
repositoryIDsWithErrors *observation.Operation
@ -121,13 +121,13 @@ func newOperations(observationCtx *observation.Context) *operations {
list: op("List"),
// Commits
getCommitsVisibleToUpload: op("CommitsVisibleToUploads"),
getOldestCommitDate: op("GetOldestCommitDate"),
getStaleSourcedCommits: op("GetStaleSourcedCommits"),
getCommitGraphMetadata: op("GetCommitGraphMetadata"),
deleteSourcedCommits: op("DeleteSourcedCommits"),
updateSourcedCommits: op("UpdateSourcedCommits"),
hasCommit: op("HasCommit"),
getCommitsVisibleToUpload: op("CommitsVisibleToUploads"),
getCommitAndDateForOldestUpload: op("GetCommitAndDateForOldestUpload"),
getStaleSourcedCommits: op("GetStaleSourcedCommits"),
getCommitGraphMetadata: op("GetCommitGraphMetadata"),
deleteSourcedCommits: op("DeleteSourcedCommits"),
updateSourcedCommits: op("UpdateSourcedCommits"),
hasCommit: op("HasCommit"),
// Repositories
getRepositoriesForIndexScan: op("GetRepositoriesForIndexScan"),

View File

@ -7,6 +7,7 @@ import (
logger "github.com/sourcegraph/log"
"github.com/sourcegraph/sourcegraph/internal/api"
"github.com/sourcegraph/sourcegraph/internal/codeintel/core"
"github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/internal/commitgraph"
"github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/shared"
"github.com/sourcegraph/sourcegraph/internal/database"
@ -87,7 +88,7 @@ type Store interface {
SoftDeleteExpiredUploadsViaTraversal(ctx context.Context, maxTraversal int) (int, int, error)
// Commit date
GetOldestCommitDate(ctx context.Context, repositoryID int) (time.Time, bool, error)
GetCommitAndDateForOldestUpload(ctx context.Context, repositoryID int) (core.Option[CommitWithDate], error)
UpdateCommittedAt(ctx context.Context, repositoryID int, commit, commitDateString string) error
SourcedCommitsWithoutCommittedAt(ctx context.Context, batchSize int) ([]SourcedCommits, error)

View File

@ -13,6 +13,7 @@ import (
sqlf "github.com/keegancsmith/sqlf"
api "github.com/sourcegraph/sourcegraph/internal/api"
core "github.com/sourcegraph/sourcegraph/internal/codeintel/core"
shared1 "github.com/sourcegraph/sourcegraph/internal/codeintel/policies/shared"
commitgraph "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/internal/commitgraph"
lsifstore "github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/internal/lsifstore"
@ -81,6 +82,10 @@ type MockStore struct {
// GetAuditLogsForUploadFunc is an instance of a mock function object
// controlling the behavior of the method GetAuditLogsForUpload.
GetAuditLogsForUploadFunc *StoreGetAuditLogsForUploadFunc
// GetCommitAndDateForOldestUploadFunc is an instance of a mock function
// object controlling the behavior of the method
// GetCommitAndDateForOldestUpload.
GetCommitAndDateForOldestUploadFunc *StoreGetCommitAndDateForOldestUploadFunc
// GetCommitGraphMetadataFunc is an instance of a mock function object
// controlling the behavior of the method GetCommitGraphMetadata.
GetCommitGraphMetadataFunc *StoreGetCommitGraphMetadataFunc
@ -114,9 +119,6 @@ type MockStore struct {
// function object controlling the behavior of the method
// GetLastUploadRetentionScanForRepository.
GetLastUploadRetentionScanForRepositoryFunc *StoreGetLastUploadRetentionScanForRepositoryFunc
// GetOldestCommitDateFunc is an instance of a mock function object
// controlling the behavior of the method GetOldestCommitDate.
GetOldestCommitDateFunc *StoreGetOldestCommitDateFunc
// GetRecentIndexesSummaryFunc is an instance of a mock function object
// controlling the behavior of the method GetRecentIndexesSummary.
GetRecentIndexesSummaryFunc *StoreGetRecentIndexesSummaryFunc
@ -321,6 +323,11 @@ func NewMockStore() *MockStore {
return
},
},
GetCommitAndDateForOldestUploadFunc: &StoreGetCommitAndDateForOldestUploadFunc{
defaultHook: func(context.Context, int) (r0 core.Option[store.CommitWithDate], r1 error) {
return
},
},
GetCommitGraphMetadataFunc: &StoreGetCommitGraphMetadataFunc{
defaultHook: func(context.Context, int) (r0 bool, r1 *time.Time, r2 error) {
return
@ -371,11 +378,6 @@ func NewMockStore() *MockStore {
return
},
},
GetOldestCommitDateFunc: &StoreGetOldestCommitDateFunc{
defaultHook: func(context.Context, int) (r0 time.Time, r1 bool, r2 error) {
return
},
},
GetRecentIndexesSummaryFunc: &StoreGetRecentIndexesSummaryFunc{
defaultHook: func(context.Context, int) (r0 []shared.IndexesWithRepositoryNamespace, r1 error) {
return
@ -648,6 +650,11 @@ func NewStrictMockStore() *MockStore {
panic("unexpected invocation of MockStore.GetAuditLogsForUpload")
},
},
GetCommitAndDateForOldestUploadFunc: &StoreGetCommitAndDateForOldestUploadFunc{
defaultHook: func(context.Context, int) (core.Option[store.CommitWithDate], error) {
panic("unexpected invocation of MockStore.GetCommitAndDateForOldestUpload")
},
},
GetCommitGraphMetadataFunc: &StoreGetCommitGraphMetadataFunc{
defaultHook: func(context.Context, int) (bool, *time.Time, error) {
panic("unexpected invocation of MockStore.GetCommitGraphMetadata")
@ -698,11 +705,6 @@ func NewStrictMockStore() *MockStore {
panic("unexpected invocation of MockStore.GetLastUploadRetentionScanForRepository")
},
},
GetOldestCommitDateFunc: &StoreGetOldestCommitDateFunc{
defaultHook: func(context.Context, int) (time.Time, bool, error) {
panic("unexpected invocation of MockStore.GetOldestCommitDate")
},
},
GetRecentIndexesSummaryFunc: &StoreGetRecentIndexesSummaryFunc{
defaultHook: func(context.Context, int) ([]shared.IndexesWithRepositoryNamespace, error) {
panic("unexpected invocation of MockStore.GetRecentIndexesSummary")
@ -947,6 +949,9 @@ func NewMockStoreFrom(i store.Store) *MockStore {
GetAuditLogsForUploadFunc: &StoreGetAuditLogsForUploadFunc{
defaultHook: i.GetAuditLogsForUpload,
},
GetCommitAndDateForOldestUploadFunc: &StoreGetCommitAndDateForOldestUploadFunc{
defaultHook: i.GetCommitAndDateForOldestUpload,
},
GetCommitGraphMetadataFunc: &StoreGetCommitGraphMetadataFunc{
defaultHook: i.GetCommitGraphMetadata,
},
@ -977,9 +982,6 @@ func NewMockStoreFrom(i store.Store) *MockStore {
GetLastUploadRetentionScanForRepositoryFunc: &StoreGetLastUploadRetentionScanForRepositoryFunc{
defaultHook: i.GetLastUploadRetentionScanForRepository,
},
GetOldestCommitDateFunc: &StoreGetOldestCommitDateFunc{
defaultHook: i.GetOldestCommitDate,
},
GetRecentIndexesSummaryFunc: &StoreGetRecentIndexesSummaryFunc{
defaultHook: i.GetRecentIndexesSummary,
},
@ -2657,6 +2659,118 @@ func (c StoreGetAuditLogsForUploadFuncCall) Results() []interface{} {
return []interface{}{c.Result0, c.Result1}
}
// StoreGetCommitAndDateForOldestUploadFunc describes the behavior when the
// GetCommitAndDateForOldestUpload method of the parent MockStore instance
// is invoked.
type StoreGetCommitAndDateForOldestUploadFunc struct {
defaultHook func(context.Context, int) (core.Option[store.CommitWithDate], error)
hooks []func(context.Context, int) (core.Option[store.CommitWithDate], error)
history []StoreGetCommitAndDateForOldestUploadFuncCall
mutex sync.Mutex
}
// GetCommitAndDateForOldestUpload delegates to the next hook function in
// the queue and stores the parameter and result values of this invocation.
func (m *MockStore) GetCommitAndDateForOldestUpload(v0 context.Context, v1 int) (core.Option[store.CommitWithDate], error) {
r0, r1 := m.GetCommitAndDateForOldestUploadFunc.nextHook()(v0, v1)
m.GetCommitAndDateForOldestUploadFunc.appendCall(StoreGetCommitAndDateForOldestUploadFuncCall{v0, v1, r0, r1})
return r0, r1
}
// SetDefaultHook sets function that is called when the
// GetCommitAndDateForOldestUpload method of the parent MockStore instance
// is invoked and the hook queue is empty.
func (f *StoreGetCommitAndDateForOldestUploadFunc) SetDefaultHook(hook func(context.Context, int) (core.Option[store.CommitWithDate], error)) {
f.defaultHook = hook
}
// PushHook adds a function to the end of hook queue. Each invocation of the
// GetCommitAndDateForOldestUpload method of the parent MockStore instance
// invokes the hook at the front of the queue and discards it. After the
// queue is empty, the default hook function is invoked for any future
// action.
func (f *StoreGetCommitAndDateForOldestUploadFunc) PushHook(hook func(context.Context, int) (core.Option[store.CommitWithDate], error)) {
f.mutex.Lock()
f.hooks = append(f.hooks, hook)
f.mutex.Unlock()
}
// SetDefaultReturn calls SetDefaultHook with a function that returns the
// given values.
func (f *StoreGetCommitAndDateForOldestUploadFunc) SetDefaultReturn(r0 core.Option[store.CommitWithDate], r1 error) {
f.SetDefaultHook(func(context.Context, int) (core.Option[store.CommitWithDate], error) {
return r0, r1
})
}
// PushReturn calls PushHook with a function that returns the given values.
func (f *StoreGetCommitAndDateForOldestUploadFunc) PushReturn(r0 core.Option[store.CommitWithDate], r1 error) {
f.PushHook(func(context.Context, int) (core.Option[store.CommitWithDate], error) {
return r0, r1
})
}
func (f *StoreGetCommitAndDateForOldestUploadFunc) nextHook() func(context.Context, int) (core.Option[store.CommitWithDate], error) {
f.mutex.Lock()
defer f.mutex.Unlock()
if len(f.hooks) == 0 {
return f.defaultHook
}
hook := f.hooks[0]
f.hooks = f.hooks[1:]
return hook
}
func (f *StoreGetCommitAndDateForOldestUploadFunc) appendCall(r0 StoreGetCommitAndDateForOldestUploadFuncCall) {
f.mutex.Lock()
f.history = append(f.history, r0)
f.mutex.Unlock()
}
// History returns a sequence of
// StoreGetCommitAndDateForOldestUploadFuncCall objects describing the
// invocations of this function.
func (f *StoreGetCommitAndDateForOldestUploadFunc) History() []StoreGetCommitAndDateForOldestUploadFuncCall {
f.mutex.Lock()
history := make([]StoreGetCommitAndDateForOldestUploadFuncCall, len(f.history))
copy(history, f.history)
f.mutex.Unlock()
return history
}
// StoreGetCommitAndDateForOldestUploadFuncCall is an object that describes
// an invocation of method GetCommitAndDateForOldestUpload on an instance of
// MockStore.
type StoreGetCommitAndDateForOldestUploadFuncCall struct {
// Arg0 is the value of the 1st argument passed to this method
// invocation.
Arg0 context.Context
// Arg1 is the value of the 2nd argument passed to this method
// invocation.
Arg1 int
// Result0 is the value of the 1st result returned from this method
// invocation.
Result0 core.Option[store.CommitWithDate]
// Result1 is the value of the 2nd result returned from this method
// invocation.
Result1 error
}
// Args returns an interface slice containing the arguments of this
// invocation.
func (c StoreGetCommitAndDateForOldestUploadFuncCall) Args() []interface{} {
return []interface{}{c.Arg0, c.Arg1}
}
// Results returns an interface slice containing the results of this
// invocation.
func (c StoreGetCommitAndDateForOldestUploadFuncCall) Results() []interface{} {
return []interface{}{c.Result0, c.Result1}
}
// StoreGetCommitGraphMetadataFunc describes the behavior when the
// GetCommitGraphMetadata method of the parent MockStore instance is
// invoked.
@ -3772,117 +3886,6 @@ func (c StoreGetLastUploadRetentionScanForRepositoryFuncCall) Results() []interf
return []interface{}{c.Result0, c.Result1}
}
// StoreGetOldestCommitDateFunc describes the behavior when the
// GetOldestCommitDate method of the parent MockStore instance is invoked.
type StoreGetOldestCommitDateFunc struct {
defaultHook func(context.Context, int) (time.Time, bool, error)
hooks []func(context.Context, int) (time.Time, bool, error)
history []StoreGetOldestCommitDateFuncCall
mutex sync.Mutex
}
// GetOldestCommitDate delegates to the next hook function in the queue and
// stores the parameter and result values of this invocation.
func (m *MockStore) GetOldestCommitDate(v0 context.Context, v1 int) (time.Time, bool, error) {
r0, r1, r2 := m.GetOldestCommitDateFunc.nextHook()(v0, v1)
m.GetOldestCommitDateFunc.appendCall(StoreGetOldestCommitDateFuncCall{v0, v1, r0, r1, r2})
return r0, r1, r2
}
// SetDefaultHook sets function that is called when the GetOldestCommitDate
// method of the parent MockStore instance is invoked and the hook queue is
// empty.
func (f *StoreGetOldestCommitDateFunc) SetDefaultHook(hook func(context.Context, int) (time.Time, bool, error)) {
f.defaultHook = hook
}
// PushHook adds a function to the end of hook queue. Each invocation of the
// GetOldestCommitDate method of the parent MockStore instance invokes the
// hook at the front of the queue and discards it. After the queue is empty,
// the default hook function is invoked for any future action.
func (f *StoreGetOldestCommitDateFunc) PushHook(hook func(context.Context, int) (time.Time, bool, error)) {
f.mutex.Lock()
f.hooks = append(f.hooks, hook)
f.mutex.Unlock()
}
// SetDefaultReturn calls SetDefaultHook with a function that returns the
// given values.
func (f *StoreGetOldestCommitDateFunc) SetDefaultReturn(r0 time.Time, r1 bool, r2 error) {
f.SetDefaultHook(func(context.Context, int) (time.Time, bool, error) {
return r0, r1, r2
})
}
// PushReturn calls PushHook with a function that returns the given values.
func (f *StoreGetOldestCommitDateFunc) PushReturn(r0 time.Time, r1 bool, r2 error) {
f.PushHook(func(context.Context, int) (time.Time, bool, error) {
return r0, r1, r2
})
}
func (f *StoreGetOldestCommitDateFunc) nextHook() func(context.Context, int) (time.Time, bool, error) {
f.mutex.Lock()
defer f.mutex.Unlock()
if len(f.hooks) == 0 {
return f.defaultHook
}
hook := f.hooks[0]
f.hooks = f.hooks[1:]
return hook
}
func (f *StoreGetOldestCommitDateFunc) appendCall(r0 StoreGetOldestCommitDateFuncCall) {
f.mutex.Lock()
f.history = append(f.history, r0)
f.mutex.Unlock()
}
// History returns a sequence of StoreGetOldestCommitDateFuncCall objects
// describing the invocations of this function.
func (f *StoreGetOldestCommitDateFunc) History() []StoreGetOldestCommitDateFuncCall {
f.mutex.Lock()
history := make([]StoreGetOldestCommitDateFuncCall, len(f.history))
copy(history, f.history)
f.mutex.Unlock()
return history
}
// StoreGetOldestCommitDateFuncCall is an object that describes an
// invocation of method GetOldestCommitDate on an instance of MockStore.
type StoreGetOldestCommitDateFuncCall struct {
// Arg0 is the value of the 1st argument passed to this method
// invocation.
Arg0 context.Context
// Arg1 is the value of the 2nd argument passed to this method
// invocation.
Arg1 int
// Result0 is the value of the 1st result returned from this method
// invocation.
Result0 time.Time
// Result1 is the value of the 2nd result returned from this method
// invocation.
Result1 bool
// Result2 is the value of the 3rd result returned from this method
// invocation.
Result2 error
}
// Args returns an interface slice containing the arguments of this
// invocation.
func (c StoreGetOldestCommitDateFuncCall) Args() []interface{} {
return []interface{}{c.Arg0, c.Arg1}
}
// Results returns an interface slice containing the results of this
// invocation.
func (c StoreGetOldestCommitDateFuncCall) Results() []interface{} {
return []interface{}{c.Result0, c.Result1, c.Result2}
}
// StoreGetRecentIndexesSummaryFunc describes the behavior when the
// GetRecentIndexesSummary method of the parent MockStore instance is
// invoked.

View File

@ -10,7 +10,7 @@ import (
// NOTE: This should be kept up-to-date with the upcoming version to be released, and bumped after.
// fallback schemas everything we support migrating to. The release tool automates this upgrade, so don't touch this :)
// This should be the last minor version since patch releases only happen in the release branch.
const maxVersionString = "5.4.0"
const maxVersionString = "5.5.0"
// MaxVersion is the highest known released version at the time the migrator was built.
var MaxVersion = func() oobmigration.Version {

View File

@ -692,6 +692,19 @@
],
"IsCreateIndexConcurrently": false,
"IndexMetadata": null
},
{
"ID": 1719914228,
"Name": "insight_series_modify_query",
"UpQuery": "ALTER TABLE insight_series ADD COLUMN IF NOT EXISTS query_old TEXT;\nUPDATE insight_series SET query_old = query;\n\n-- prefix query with patternType:standard if there is no patterntype: in the query\nUPDATE insight_series\nSET query = 'patterntype:standard ' || query\nWHERE query NOT ILIKE '%patterntype:%'\n -- exclude empty queries, which are created by language stats insights\n AND query != '';\n\nCOMMENT ON COLUMN insight_series.query_old IS 'Backup for migration. Remove with release 5.6 or later.';",
"DownQuery": "DO\n$$\n BEGIN\n -- Check if column 'query_old' exists\n IF EXISTS (SELECT 1\n FROM information_schema.columns\n WHERE table_name = 'insight_series' AND column_name = 'query_old') THEN\n -- Update the 'query' column with values from 'query_old'\n UPDATE insight_series SET query = query_old;\n ALTER TABLE insight_series DROP COLUMN query_old;\n END IF;\n END\n$$;",
"Privileged": false,
"NonIdempotent": false,
"Parents": [
1679051112
],
"IsCreateIndexConcurrently": false,
"IndexMetadata": null
}
],
"BoundsByRev": {
@ -933,6 +946,13 @@
1679051112
],
"PreCreation": false
},
"v5.5.0": {
"RootID": 1000000027,
"LeafIDs": [
1719914228
],
"PreCreation": false
}
}
},
@ -1909,6 +1929,13 @@
1686315964
],
"PreCreation": false
},
"v5.5.0": {
"RootID": 1000000033,
"LeafIDs": [
1686315964
],
"PreCreation": false
}
}
},
@ -11221,6 +11248,85 @@
],
"IsCreateIndexConcurrently": false,
"IndexMetadata": null
},
{
"ID": 1717699555,
"Name": "Fix unique index for SCIM external account connection",
"UpQuery": "DROP INDEX IF EXISTS user_external_accounts_user_id_scim_service_type;\n\nCREATE UNIQUE INDEX\n user_external_accounts_user_id_scim_service_type\nON\n user_external_accounts (user_id, service_type)\nWHERE\n service_type = 'scim'::text\n AND deleted_at IS NULL;",
"DownQuery": "DROP INDEX IF EXISTS user_external_accounts_user_id_scim_service_type;\n\nCREATE UNIQUE INDEX\n user_external_accounts_user_id_scim_service_type\nON\n user_external_accounts (user_id, service_type)\nWHERE\n service_type = 'scim'::text;",
"Privileged": false,
"NonIdempotent": false,
"Parents": [
1713958707
],
"IsCreateIndexConcurrently": false,
"IndexMetadata": null
},
{
"ID": 1719214941,
"Name": "notebooks_add_field_pattern_type",
"UpQuery": "DO $$\nBEGIN\n IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'pattern_type') THEN\n CREATE TYPE pattern_type AS ENUM ('keyword', 'literal', 'regexp', 'standard', 'structural');\n END IF;\nEND\n$$;\n\nALTER TABLE notebooks ADD COLUMN IF NOT EXISTS pattern_type pattern_type NOT NULL DEFAULT 'standard';",
"DownQuery": "ALTER TABLE notebooks DROP COLUMN IF EXISTS pattern_type;\nDROP TYPE IF EXISTS pattern_type;",
"Privileged": false,
"NonIdempotent": false,
"Parents": [
1717699555
],
"IsCreateIndexConcurrently": false,
"IndexMetadata": null
},
{
"ID": 1719498032,
"Name": "add_github_app_batch_changes_site_credential",
"UpQuery": "ALTER TABLE IF EXISTS batch_changes_site_credentials\n ADD COLUMN IF NOT EXISTS github_app_id INT NULL REFERENCES github_apps(id) ON DELETE CASCADE;\n\nALTER TABLE batch_changes_site_credentials DROP CONSTRAINT IF EXISTS check_github_app_id_and_external_service_type_site_credentials;\n\n-- We want to make sure that we never have a site_credential with a `github_app_id` with an `external_service_type`\n-- that isn't `github`.\nALTER TABLE IF EXISTS batch_changes_site_credentials\n ADD CONSTRAINT check_github_app_id_and_external_service_type_site_credentials\n CHECK ((github_app_id IS NULL) OR (external_service_type = 'github'));",
"DownQuery": "-- delete the constraints\nALTER TABLE IF EXISTS batch_changes_site_credentials DROP CONSTRAINT IF EXISTS check_github_app_id_and_external_service_type_site_credentials;\n\n-- delete the `github_app_id` column\nALTER TABLE IF EXISTS batch_changes_site_credentials DROP COLUMN IF EXISTS github_app_id;",
"Privileged": false,
"NonIdempotent": false,
"Parents": [
1717699555
],
"IsCreateIndexConcurrently": false,
"IndexMetadata": null
},
{
"ID": 1719498091,
"Name": "add_github_app_id_user_credentials",
"UpQuery": "ALTER TABLE IF EXISTS user_credentials\n ADD COLUMN IF NOT EXISTS github_app_id INT NULL REFERENCES github_apps(id) ON DELETE CASCADE;\n\nALTER TABLE user_credentials DROP CONSTRAINT IF EXISTS check_github_app_id_and_external_service_type_user_credentials;\n\n-- We want to make sure that we never have a user_credential with a `github_app_id` with an `external_service_type`\n-- that isn't `github`.\nALTER TABLE IF EXISTS user_credentials\n ADD CONSTRAINT check_github_app_id_and_external_service_type_user_credentials\n CHECK ((github_app_id IS NULL) OR (external_service_type = 'github'));",
"DownQuery": "-- delete the constraints\nALTER TABLE IF EXISTS user_credentials DROP CONSTRAINT IF EXISTS check_github_app_id_and_external_service_type_user_credentials;\n\n-- delete the `github_app_id` column\nALTER TABLE IF EXISTS user_credentials DROP COLUMN IF EXISTS github_app_id;",
"Privileged": false,
"NonIdempotent": false,
"Parents": [
1719498032
],
"IsCreateIndexConcurrently": false,
"IndexMetadata": null
},
{
"ID": 1719498128,
"Name": "add_kind_column_github_app",
"UpQuery": "DO $$\nBEGIN\n IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'github_app_kind') THEN\n CREATE TYPE github_app_kind AS ENUM (\n 'COMMIT_SIGNING',\n 'REPO_SYNC',\n 'USER_CREDENTIAL',\n 'SITE_CREDENTIAL'\n );\n END IF;\nEND\n$$;\n\nALTER TABLE IF EXISTS github_apps\n ADD COLUMN IF NOT EXISTS kind github_app_kind DEFAULT 'REPO_SYNC';\n\nUPDATE github_apps\nSET kind = 'COMMIT_SIGNING'\nWHERE domain = 'batches';\n\n-- This is expected to fail if any row is using an unknown value that is not repos or batches.\n-- We only allow repos or batches at this time.\nALTER TABLE IF EXISTS github_apps\nALTER COLUMN kind SET NOT NULL;",
"DownQuery": "ALTER TABLE IF EXISTS github_apps DROP COLUMN IF EXISTS kind;\n\nDROP TYPE IF EXISTS github_app_kind;",
"Privileged": false,
"NonIdempotent": false,
"Parents": [
1719498091
],
"IsCreateIndexConcurrently": false,
"IndexMetadata": null
},
{
"ID": 1720165387,
"Name": "notebooks default to keyword search",
"UpQuery": "ALTER TABLE IF EXISTS notebooks ALTER COLUMN pattern_type SET DEFAULT 'keyword';",
"DownQuery": "ALTER TABLE IF EXISTS notebooks ALTER COLUMN pattern_type SET DEFAULT 'standard';",
"Privileged": false,
"NonIdempotent": false,
"Parents": [
1719214941,
1719498128
],
"IsCreateIndexConcurrently": false,
"IndexMetadata": null
}
],
"BoundsByRev": {
@ -11484,6 +11590,13 @@
1713958707
],
"PreCreation": false
},
"v5.5.0": {
"RootID": 1648051770,
"LeafIDs": [
1720165387
],
"PreCreation": false
}
}
}

View File

@ -333,7 +333,7 @@
"bloomfilter": "^0.0.18",
"buffer": "^6.0.3",
"classnames": "^2.2.6",
"cody-web-experimental": "^0.2.4",
"cody-web-experimental": "^0.2.7",
"comlink": "^4.3.0",
"copy-to-clipboard": "^3.3.1",
"core-js": "^3.8.2",

View File

@ -206,8 +206,8 @@ importers:
specifier: ^2.2.6
version: 2.3.2
cody-web-experimental:
specifier: ^0.2.4
version: 0.2.4
specifier: ^0.2.7
version: 0.2.7
comlink:
specifier: ^4.3.0
version: 4.3.0
@ -15270,6 +15270,10 @@ packages:
resolution: {integrity: sha512-92MNNTlZTndHN+kNUa4ojrZMIxgl78o+wswOhdzmIQm/FJFi977rnuQPSg/bV5jm8S3y3pdwUM7SUTqCKlwSHw==}
dev: false
/cody-web-experimental@0.2.7:
resolution: {integrity: sha512-OI2nW/3CKqSajDyl3Sojlb4bX4fJcwIY2TQ3k0Sw1CSGyNxbqkxCA37dlhBLPMEq3ByC9trX68ppNJEi2ZFuWg==}
dev: false
/color-convert@1.9.3:
resolution: {integrity: sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==}
dependencies:

View File

@ -670,6 +670,12 @@ type CodyProConfig struct {
UseEmbeddedUI bool `json:"useEmbeddedUI,omitempty"`
}
// CommitGraphUpdates description: Customize strategy used for commit graph updates
type CommitGraphUpdates struct {
// DefaultBranchOnly description: Disables precise code nav on non-default branches. Specify repo names using regex syntax.
DefaultBranchOnly []string `json:"defaultBranchOnly,omitempty"`
}
// Completions description: Configuration for the completions service.
type Completions struct {
// AccessToken description: The access token used to authenticate with the external completions provider. If using the default provider 'sourcegraph', and if 'licenseKey' is set, a default access token is generated.
@ -1039,6 +1045,8 @@ type ExperimentalFeatures struct {
CodeintelSyntacticIndexingEnabled bool `json:"codeintelSyntacticIndexing.enabled,omitempty"`
// CodyContextIgnore description: Enabled filtering of remote Cody context based on repositories ./cody/ignore file
CodyContextIgnore *bool `json:"codyContextIgnore,omitempty"`
// CommitGraphUpdates description: Customize strategy used for commit graph updates
CommitGraphUpdates *CommitGraphUpdates `json:"commitGraphUpdates,omitempty"`
// CustomGitFetch description: JSON array of configuration that maps from Git clone URL domain/path to custom git fetch command. To enable this feature set environment variable `ENABLE_CUSTOM_GIT_FETCH` as `true` on gitserver.
CustomGitFetch []*CustomGitFetchMapping `json:"customGitFetch,omitempty"`
// DebugLog description: Turns on debug logging for specific debugging scenarios.
@ -1138,6 +1146,7 @@ func (v *ExperimentalFeatures) UnmarshalJSON(data []byte) error {
delete(m, "batchChanges.enablePerforce")
delete(m, "codeintelSyntacticIndexing.enabled")
delete(m, "codyContextIgnore")
delete(m, "commitGraphUpdates")
delete(m, "customGitFetch")
delete(m, "debug.log")
delete(m, "enableGithubInternalRepoVisibility")

View File

@ -175,6 +175,21 @@
"type": "object",
"additionalProperties": true,
"properties": {
"commitGraphUpdates": {
"description": "Customize strategy used for commit graph updates",
"type": "object",
"additionalProperties": false,
"properties": {
"defaultBranchOnly": {
"description": "Disables precise code nav on non-default branches. Specify repo names using regex syntax.",
"type": "array",
"items": {
"type": "string",
"examples": ["github.com/myorg/huge-monorepo", "github.com/other-org/.*"]
}
}
}
},
"scipBasedAPIs": {
"description": "Enable usage of new CodeGraph and usagesForSymbol APIs",
"type": "boolean",