Update buildfiles (#48908)

~Quick~ update to catchup with latest changes and fix edge cases. 

## Test plan

<!-- All pull requests REQUIRE a test plan:
https://docs.sourcegraph.com/dev/background-information/testing_principles
-->

Bazel jobs should be green.

---------

Co-authored-by: Jason Bedard <jason@aspect.dev>
Co-authored-by: Valery Bugakov <skymk1@gmail.com>
This commit is contained in:
Jean-Hadrien Chabran 2023-03-10 15:33:22 +01:00 committed by GitHub
parent 10c062c462
commit 868b79467c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
116 changed files with 343 additions and 1555 deletions

View File

@ -16,3 +16,7 @@ test --action_env=PATH
test --action_env=PGUSER
test --action_env=PGSSLMODE
test --action_env=PGDATABASE
# Allow tests to understand they're running in CI, which forces dbtest to drop database even in case of failures.
# TODO(JH) we should instead wipe all templates after a job finishes.
test --action_env=CI

View File

@ -230,11 +230,11 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
rules_rust_dependencies()
rust_register_toolchains(
edition = "2021",
# Keep in sync with docker-images/syntax-highlighter/Dockerfile
versions = [
"1.67.1"
],
edition = "2021",
# Keep in sync with docker-images/syntax-highlighter/Dockerfile
versions = [
"1.67.1",
],
)
load("@rules_rust//crate_universe:defs.bzl", "crates_repository")
@ -247,9 +247,9 @@ crates_repository(
# To regenerate this file run: CARGO_BAZEL_REPIN=1 bazel sync --only=crates_index
lockfile = "//docker-images/syntax-highlighter:Cargo.Bazel.lock",
manifests = [
"//docker-images/syntax-highlighter:crates/sg-macros/Cargo.toml",
"//docker-images/syntax-highlighter:crates/sg-syntax/Cargo.toml",
"//docker-images/syntax-highlighter:Cargo.toml",
"//docker-images/syntax-highlighter:crates/sg-macros/Cargo.toml",
"//docker-images/syntax-highlighter:crates/sg-syntax/Cargo.toml",
"//docker-images/syntax-highlighter:Cargo.toml",
],
)

View File

@ -1,3 +0,0 @@
dist/
dist-types/
node_modules/

View File

@ -1,2 +0,0 @@
dist
node_modules

View File

@ -1,40 +0,0 @@
load("@npm//:defs.bzl", "npm_link_all_packages")
load("//dev:defs.bzl", "ts_project")
npm_link_all_packages(name = "node_modules")
ts_project(
name = "backstage-backend",
srcs = [
"src/client/Query.ts",
"src/client/SourcegraphClient.ts",
"src/client/index.ts",
"src/index.ts",
"src/providers/index.ts",
"src/providers/parsers.ts",
"src/providers/providers.ts",
"src/setupTests.ts",
],
deps = [
":node_modules/@backstage/catalog-model",
":node_modules/@backstage/plugin-catalog-backend",
":node_modules/@sourcegraph/http-client",
":node_modules/@sourcegraph/shared",
"//:node_modules/@apollo/client",
],
)
ts_project(
name = "backstage-backend_tests",
testonly = True,
srcs = [
"src/client/Query.test.ts",
"src/client/SourcegraphClient.test.ts",
"src/tests/integration/e2e.test.ts",
],
deps = [
":backstage-backend",
":node_modules/@jest/globals",
"//:node_modules/@apollo/client",
],
)

View File

@ -1,187 +0,0 @@
# Sourcegraph Backstage Common library plugin
Welcome to the Sourcegraph Backstage common plugin!
## How this plugin was generated.
Backstage has a cli named `backstage-cli` which performs a bunch of operations relating to Backstage maintenance and developing, including generating scaffolding for plugins.
There are a few plugin types but we're only interested in the following types for now:
- frontend-plugin: a plugin that adds components and integration with the Backstage frontend. The generated scaffolding allows running the plugin on its own without Backstage, as long as there is an `app-config.yaml` for configuration.
- backend-plugin: a plugin that integrates with the Backstage backend. Typically does not contain any visual components. The generated scaffolding allows you to run the plugin on its own as a backend application, meaning there won't be a web page to visit.
- common-plugin: a plugin that is more a library, with common functionality you want to share across plugins. Unlike the other plugin types, this plugin cannot be run on its own.
### How to generate plugin scaffolding.
1. Make sure you're in the Backstage repo generated with `@backstage/create-app` (Not a hard requirement, but the rest of the points assume this directory).
2. Run `backstage-cli new`, where a mini wizard will ask you questions about your plugin.
3. Once the command completes, the generated plugin scaffolding can be found under `plugins/`.
The plugin scaffolding now has been generated but the scaffolding assumes the plugin will stay in the Backstage repo which it won't. To make the plugin 'workable' outside of the Backstage repository we have make some additional changes.
1. Add the following `tsconfig.json` to the plugin directory.
```json
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"target": "es2020",
"lib": ["esnext", "DOM", "DOM.Iterable"],
"sourceMap": true,
"sourceRoot": "src",
"baseUrl": "./src",
"paths": {
"@sourcegraph/*": ["../*"],
"*": ["types/*", "../../shared/src/types/*", "../../common/src/types/*", "*"]
},
"esModuleInterop": true,
"resolveJsonModule": true,
"strict": true,
"jsx": "react-jsx"
},
"references": [
{
"path": "../shared"
}
],
"include": ["./package.json", "**/*", ".*", "**/*.d.ts"],
"exclude": ["node_modules", "../../node_modules", "dist"]
}
```
The above `tsconfig` was copied from `client/jetbrains` and adapted to fit our usecase.
2. Take note of the plugin directory structure.
```console
.
├── README.md
├── dist
│   ├── index.cjs.js
│   ├── index.cjs.js.map
│   ├── index.d.ts
│   ├── index.esm.js
│   └── index.esm.js.map
├── dist-types
│   ├── src
│   │   ├── catalog
│   │   │   ├── index.d.ts
│   │   │   └── parsers.d.ts
│   │   ├── client
│   │   │   ├── SourcegraphClient.d.ts
│   │   │   ├── SourcegraphClient.test.d.ts
│   │   │   └── index.d.ts
│   │   ├── index.d.ts
│   │   ├── providers
│   │   │   ├── SourcegraphEntityProvider.d.ts
│   │   │   └── index.d.ts
│   │   └── setupTests.d.ts
│   └── tsconfig.tsbuildinfo
├── node_modules
├── package.json
├── src
│   ├── catalog
│   │   ├── index.ts
│   │   └── parsers.ts
│   ├── client
│   │   ├── SourcegraphClient.test.ts
│   │   ├── SourcegraphClient.ts
│   │   └── index.ts
│   ├── index.ts
│   ├── providers
│   │   ├── SourcegraphEntityProvider.ts
│   │   └── index.ts
│   └── setupTests.ts
└── tsconfig.json
17 directories, 27 files
```
3. The plugin will use libraries and components from the Sourcegraph repo, which are all private and not available on the npm registry. Which means, when this plugin is installed into Backstage, it will try to look for any dependencies defined in the `package.json` on the npm registry. It will find some, but any Sourcegraph referenced projects, it won't be able to find anything. We thus need to make some changes to the `package.json` and also look into using a bundler like `esbuild`.
4. The notable changes we make in the `package.json` are that:
- change the `main` attribute to have the `dist/index.js` - note no `cjs`. This is due to use using a bundler, which bundles everything into a `js` file.
- add a script `es` which invokes `esbuild` with a particular config and we copy `package.dist.json` to `dist/package.json`. `package.dist.json` is a slimmed down version of our root package.json and defines how one should install the bundled artefact of our plugin, namely `index.js`.
```json
{
"name": "backstage-plugin-sourcegraph-common",
"description": "Common functionalities for the Sourcegraph plugin",
"version": "0.1.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "Apache-2.0",
"private": true,
"publishConfig": {
"access": "public",
"main": "dist/index.js",
"module": "dist/index.esm.js",
"types": "dist/index.d.ts"
},
"backstage": {
"role": "common-library"
},
"scripts": {
"es": "ts-node --transpile-only ./scripts/esbuild.ts && cp package.dist.json dist/",
"build": "backstage-cli package build",
"lint": "backstage-cli package lint",
"test": "backstage-cli package test",
"clean": "backstage-cli package clean",
"prepack": "backstage-cli package prepack",
"postpack": "backstage-cli package postpack"
},
"devDependencies": {
"@backstage/cli": "^0.22.1",
"@jest/globals": "^29.4.0",
"@sourcegraph/tsconfig": "^4.0.1",
"@types/jest": "^29.4.0",
"ts-jest": "^29.0.5"
},
"dependencies": {
"@backstage/catalog-model": "^1.1.5",
"@backstage/config": "^1.0.6",
"@backstage/plugin-catalog-backend": "^1.7.1",
"@sourcegraph/shared": "workspace:^1.0.0"
},
"files": ["dist"]
}
```
5. If we take a look at the `esbuild` config defined in `scripts/esbuild.ts` there are a few options to take note of:
- we use `external` and define most of our dependencies except the Sourcegraph related ones. External tells `esbuild` that it shouldn't bundle these dependencies into the final artefact. We set it to the values we defined in our `package.json` because they can be found on the npm registry. This also explains why we don't have `@sourcegraph/*` defined there, since we **do** want them bundled. Unfortunately, some transitive dependencies will also be bundled as they're imported, which why `lodash` and `apollo` are defined. It is a bit of a cat and mouse game, to get the right dependencies excluded.
6. We can now copy the directory to wherever we want, like the Sourcgraph repo `cp plugins/backstage-plugin-test ~/sourcegraph/client/backstage/test`.
7. Depending on the type of plugin that was generated, a dependency entry was added to either the `packages/app/package.json or `packages/backend/packages.json`. Now that the plugin has been 'moved' we don't want Backstage to still refer to these locations, so remove the plugin with `yarn workspace backend remove <name>`or`yarn workspace app remove <name>`.
### Run the plugin with Backstage / Local Development
Since we copied the plugin to a different directory we need to tell Backstage where to find the plugin.
1. Make sure the plugin is built. Note that we use pnpm here and not yarn, which is because Sourcegraph uses pnpm. Both yarn and pnpm work with the command defined in the `package.json` which just executes `backstage-cli` with some args.
```console
$ cd sourcegraph/client/backstage/plugin
$ pnpm es
```
2. There should now be a dist directory in `sourcegraph/client/backstage/plugin`.
3. We're now ready to show Backstage where the plugin is. Move to the Backstage root directory and execute:
For a plugin that integrates with the backend:
```console
$ yarn workspace backend add link:~/sourcegraph/client/backstage/plugin/dist
```
For a plugin that integrates with the frontend:
```console
$ yarn workspace app add link:~/sourcegraph/client/backstage/plugin/dist
```
4. You should be able to start the Backstage app now with `yarn dev`

View File

@ -1,18 +0,0 @@
# an example config to use with Backstage
app:
title: Sourcegraph Backstage App
baseUrl: http://localhost:3000
organization:
name: Sourcegraph
sourcegraph:
endpoint: https://sourcegraph.test:3443
orgId: sourcegraph
token: ${SG_SUDO_TOKEN}
file:
query: "lang:yaml repo:^ghe\\.sgdev\\.org/william/service-catalog$"
grpc:
query: "repo:^github\\.com/sourcegraph/sourcegraph$ file:.proto$"
graphql:
query: "repo:^github\\.com/sourcegraph/sourcegraph$ file:schema\\.graphql"

View File

@ -1,8 +0,0 @@
// @ts-check
/** @type {import('@babel/core').TransformOptions} */
const config = {
extends: '../../babel.config.js',
}
module.exports = config

View File

@ -1,14 +0,0 @@
// @ts-check
const path = require('path')
const config = require('../../jest.config.base')
/** @type {import('@jest/types').Config.InitialOptions} */
const exportedConfig = {
...config,
displayName: 'backstage-backend',
rootDir: __dirname,
setupFiles: [...config.setupFiles],
}
module.exports = exportedConfig

View File

@ -1,20 +0,0 @@
{
"name": "@sourcegraph/backstage-common",
"description": "Common functionalities for the Sourcegraph plugin. This differs from the base package.json since it lists internal packages which cannot be fetched and are bundled instead.",
"version": "0.1.0",
"main": "index.js",
"types": "types/index.d.ts",
"license": "Apache-2.0",
"private": true,
"publishConfig": {
"access": "public"
},
"backstage": {
"role": "common-library"
},
"dependencies": {
"@backstage/catalog-model": "^1.1.5",
"@backstage/config": "^1.0.6",
"@backstage/plugin-catalog-backend": "^1.7.1"
}
}

View File

@ -1,46 +0,0 @@
{
"name": "@sourcegraph/backstage-backend",
"description": "Common functionalities for the Sourcegraph plugin",
"version": "0.1.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "Apache-2.0",
"private": true,
"publishConfig": {
"access": "public",
"main": "dist/index.js",
"module": "dist/index.esm.js",
"types": "dist/index.d.ts"
},
"backstage": {
"role": "common-library"
},
"scripts": {
"dist": "ts-node --transpile-only ./scripts/esbuild.ts && pnpm types && cp package.dist.json dist/package.json",
"types": "tsc -d -p tsconfig.json",
"format": "prettier -w true .",
"test": "jest --testPathIgnorePatterns src/tests/integration/",
"e2e": "jest --testPathPattern src/tests/integration/"
},
"devDependencies": {
"@backstage/cli": "^0.22.1",
"@jest/globals": "^29.4.0",
"@sourcegraph/build-config": "workspace:*",
"@sourcegraph/tsconfig": "^4.0.1",
"babel-jest": "^28.1.3",
"babel-loader": "^9.1.0",
"esbuild": "^0.17.8",
"winston": "^3.8.2"
},
"dependencies": {
"@backstage/backend-common": "^0.18.1",
"@backstage/catalog-model": "^1.1.5",
"@backstage/config": "^1.0.6",
"@backstage/plugin-catalog-backend": "^1.7.1",
"@sourcegraph/http-client": "workspace:^0.0.1",
"@sourcegraph/shared": "workspace:^1.0.0"
},
"files": [
"dist"
]
}

View File

@ -1,55 +0,0 @@
import { existsSync } from 'fs'
import path from 'path'
import * as esbuild from 'esbuild'
import { rm } from 'shelljs'
import { WORKSPACES_PATH, buildTimerPlugin } from '@sourcegraph/build-config'
const PACKAGE_ROOT_PATH = path.resolve(WORKSPACES_PATH, 'backstage-frontend')
const DIST_PATH = path.resolve(PACKAGE_ROOT_PATH, 'dist')
async function build(): Promise<void> {
if (existsSync(DIST_PATH)) {
rm('-rf', DIST_PATH)
}
await esbuild.build({
entryPoints: [path.resolve(PACKAGE_ROOT_PATH, 'src', 'index.ts')],
bundle: true,
external: [
'@backstage/cli',
'@backstage/catalog-model',
'@backstage/config',
'@backstage/backend-common',
'@backstage/plugin-catalog-backend',
'graphql-request',
'react',
'react-dom',
'lodash',
'apollo',
'winston',
],
// If we don't specify module first, esbuild bundles somethings "incorrectly" and you'll get a error with './impl/format' error
// Most likely due to https://github.com/evanw/esbuild/issues/1619#issuecomment-922787629
mainFields: ['module', 'main'],
format: 'cjs',
platform: 'node',
define: {
'process.env.IS_TEST': 'false',
global: 'globalThis',
},
plugins: [buildTimerPlugin],
ignoreAnnotations: true,
treeShaking: true,
sourcemap: true,
outdir: DIST_PATH,
})
}
if (require.main == module) {
build().catch(error => {
console.error('Error:', error)
process.exit(1)
})
}

View File

@ -1,26 +0,0 @@
import { describe, expect, test } from '@jest/globals'
import { createService, Config } from './SourcegraphClient'
const INTEGRATION_TEST = true
describe.skip('query marshalling', () => {
if (!INTEGRATION_TEST) {
return
}
const config: Config = {
// TODO(@burmudar): this should be made configurable, even though it is for an integration test
endpoint: 'https://sourcegraph.test:3443',
token: 'SOURCEGRAPH_TOKEN' in process.env ? (process.env['SOURCEGRAPH_TOKEN'] as string) : '',
sudoUsername: 'sourcegraph',
}
const client = createService(config)
test('check CurrentUser is marshalled', () => {
expect(client.Users.currentUsername).toBe('sourcegraph')
})
test('check AuthenticatedUser is marshalled', () => {
expect(client.Users.getAuthenticatedUser()).toBe({})
})
})

View File

@ -1,125 +0,0 @@
import { gql } from '@apollo/client'
import type { DocumentNode } from '@apollo/client'
export interface Query<T> {
gql(): DocumentNode
vars(): string
marshal(data: any): T
}
export type SearchResults = Array<SearchResult>
export interface SearchResult {
readonly __typename?: string
readonly repository: string
readonly filename?: string
readonly fileContent?: string
}
export class SearchQuery implements Query<SearchResults> {
private readonly query: string
static raw: string = `
query ($search: String!) {
search(query: $search) {
results {
results {
__typename
... on FileMatch {
repository {
name
}
file {
name
content
}
}
}
}
}
}
`
constructor(query: string) {
this.query = query
}
marshal(data: any): SearchResults {
const results = new Array<SearchResult>()
if (!data.search) {
return results
}
for (const value of data.search.results.results) {
let filename = ''
let fileContent = ''
if ('file' in value) {
filename = value.file.name
fileContent = value.file.content
}
results.push({ repository: value.repository.name, filename: filename, fileContent: fileContent })
}
return results
}
vars(): any {
return { search: this.query }
}
gql(): DocumentNode {
return gql(SearchQuery.raw)
}
}
export class SearchRepoQuery extends SearchQuery {
static raw: string = `
query ($search: String!) {
search(query: $search) {
results {
results {
__typename
... on FileMatch {
repository {
name
}
}
}
}
}
}
`
constructor(query: string) {
super(query)
}
gql(): DocumentNode {
return gql(SearchRepoQuery.raw)
}
}
export class UserQuery implements Query<string> {
static raw: string = `
query {
currentUser {
username
}
}
`
vars(): any {
return {}
}
gql(): DocumentNode {
return gql(UserQuery.raw)
}
marshal(data: any): string {
if ('currentUser' in data) {
const { currentUser } = data
return currentUser.username
}
throw new Error('currentUser field missing')
}
}

View File

@ -1,112 +0,0 @@
import { describe, expect, test } from '@jest/globals'
import { SourcegraphClient, SourcegraphService, BaseClient } from './SourcegraphClient'
import { SearchQuery, SearchRepoQuery, SearchResult, UserQuery } from './Query'
import { createMockClient } from '@apollo/client/testing'
describe('SourcegraphService', () => {
test('current user query', async () => {
// setup
const data = {
currentUser: {
username: 'william',
},
}
const query: UserQuery = new UserQuery()
const base = new BaseClient(createMockClient(data, query.gql()))
let sourcegraphService: SourcegraphService = new SourcegraphClient(base)
// test
const username = await sourcegraphService.Users.currentUsername()
// verify
expect(username).toBe('william')
})
test('search query with 2 results', async () => {
// setup
const expected: SearchResult[] = [
{ repository: 'repo 1', filename: 'filename-1', fileContent: 'logs of bogus content' },
{ repository: 'repo 1', filename: 'filename-2', fileContent: 'logs of bogus content' },
]
const data = {
search: {
results: {
results: [
{
__typename: 'FileMatch',
repository: { name: expected[0].repository },
file: {
name: expected[0].filename,
content: expected[0].fileContent,
},
},
{
__typename: 'FileMatch',
repository: { name: expected[1].repository },
file: {
name: expected[1].filename,
content: expected[1].fileContent,
},
},
],
},
},
}
const query: SearchQuery = new SearchQuery('mock query')
const base = new BaseClient(createMockClient(data, query.gql(), query.vars()))
let sourcegraphService: SourcegraphService = new SourcegraphClient(base)
// test
const results: SearchResult[] = await sourcegraphService.Search.searchQuery('mock query')
// verify
expect(results).toEqual(expected)
})
test('search query with 0 results', async () => {
// setup
const expected: SearchResult[] = []
const data = {
search: {
results: {
results: [],
},
},
}
const query: SearchQuery = new SearchQuery('mock query')
const base = new BaseClient(createMockClient(data, query.gql(), query.vars()))
let sourcegraphService: SourcegraphService = new SourcegraphClient(base)
// test
const results: SearchResult[] = await sourcegraphService.Search.searchQuery('mock query')
// verify
expect(results).toEqual(expected)
})
test('search query with only repository names', async () => {
// setup
const expected: SearchResult[] = [
{ repository: 'repo-1', filename: '', fileContent: '' },
{ repository: 'repo-2', filename: '', fileContent: '' },
]
const data = {
search: {
results: {
results: [
{
__typename: 'FileMatch',
repository: { name: 'repo-1' },
},
{
__typename: 'FileMatch',
repository: { name: 'repo-2' },
},
],
},
},
}
const query: SearchRepoQuery = new SearchRepoQuery('mock query')
const base = new BaseClient(createMockClient(data, query.gql(), query.vars()))
let sourcegraphService: SourcegraphService = new SourcegraphClient(base)
// test
const results: SearchResult[] = await sourcegraphService.Search.doQuery(query)
// verify
expect(results).toEqual(expected)
})
})

View File

@ -1,93 +0,0 @@
import { getGraphQLClient, GraphQLClient } from '@sourcegraph/http-client'
import { generateCache } from '@sourcegraph/shared/src/backend/apolloCache'
import { UserQuery, Query, SearchQuery, SearchResult, SearchResults } from './Query'
export interface Config {
endpoint: string
token: string
sudoUsername?: string
}
export interface UserService {
currentUsername(): Promise<string>
}
export interface SearchService {
searchQuery(query: string): Promise<SearchResults>
doQuery<T>(query: Query<T>): Promise<T>
}
export interface SourcegraphService {
Users: UserService
Search: SearchService
}
export const createService = async (config: Config): Promise<SourcegraphService> => {
const { endpoint, token, sudoUsername } = config
const base = await BaseClient.create(endpoint, token, sudoUsername || '')
return new SourcegraphClient(base)
}
export class SourcegraphClient implements SourcegraphService, UserService, SearchService {
private client: BaseClient
Users: UserService = this
Search: SearchService = this
constructor(client: BaseClient) {
this.client = client
}
async searchQuery(query: string): Promise<SearchResult[]> {
return await this.doQuery(new SearchQuery(query))
}
async doQuery<T>(query: Query<T>): Promise<T> {
return await this.client.fetch(query)
}
async currentUsername(): Promise<string> {
const q = new UserQuery()
const result = await this.client.fetch(q)
return result
}
}
export class BaseClient {
private client: GraphQLClient
static async create(baseUrl: string, token: string, sudoUsername: string): Promise<BaseClient> {
const authz =
sudoUsername?.length > 0 ? `token - sudo user = "${sudoUsername}", token = "${token}"` : `token ${token}`
const headers: RequestInit['headers'] = {
'X-Requested-With': `Sourcegraph - Backstage plugin DEV`,
Authorization: authz,
}
try {
const client: GraphQLClient = await getGraphQLClient({
baseUrl: baseUrl,
headers: headers,
isAuthenticated: true,
cache: generateCache(),
})
return new BaseClient(client)
} catch (e) {
throw new Error(`failed to create graphsql client: ${e}`)
}
}
constructor(client: GraphQLClient) {
this.client = client
}
async fetch<T>(query: Query<T>): Promise<T> {
const { data } = await this.client.query({
query: query.gql(),
variables: query.vars(),
})
if (!data) {
throw new Error('grapql request failed: no data')
}
return query.marshal(data)
}
}

View File

@ -1,2 +0,0 @@
export { SourcegraphService, createService, createDummySearch, SearchService, UserService } from './SourcegraphClient'
export * from './Query'

View File

@ -1,8 +0,0 @@
/**
* Common functionalities for the sg-common plugin.
*
* @packageDocumentation
*/
export * from './providers'
export * from './client'

View File

@ -1 +0,0 @@
export { GrpcEntityProvider, YamlFileEntityProvider, GraphQLEntityProvider } from './providers'

View File

@ -1,97 +0,0 @@
import { ANNOTATION_LOCATION, ANNOTATION_ORIGIN_LOCATION, ApiEntity } from '@backstage/catalog-model'
import { CatalogProcessorEntityResult, DeferredEntity, parseEntityYaml } from '@backstage/plugin-catalog-backend'
import { SearchResult } from '../client'
import type { EntityType } from './providers'
export type ParserFunction = (results: SearchResult[], providerName: string) => DeferredEntity[]
const apiEntityDefinitionParser = (
searchResults: SearchResult[],
providerName: string,
entityType: EntityType
): DeferredEntity[] => {
const results: DeferredEntity[] = []
// TODO(@burmudar): remove - only temporary
console.log(`parsing ${searchResults.length} proto results`)
searchResults.forEach((r: SearchResult) => {
const location = {
type: 'url',
target: `${r.repository}/${r.filename}`,
}
const definition = Buffer.from(r.fileContent, 'utf8').toString()
const entity: ApiEntity = {
kind: 'API',
apiVersion: 'backstage.io/v1alpha1',
metadata: {
name: r.filename,
annotations: {
[ANNOTATION_LOCATION]: `url:${location.target}`,
[ANNOTATION_ORIGIN_LOCATION]: providerName,
},
},
spec: {
type: entityType,
lifecycle: 'production',
owner: 'engineering',
definition: definition,
},
}
results.push({
entity: entity,
locationKey: `https://${location.target}`,
})
})
console.log(`${results.length} ${entityType} entities`)
return results
}
export const parseCatalogContent: ParserFunction = (
searchResults: SearchResult[],
providerName: string
): DeferredEntity[] => {
const results: DeferredEntity[] = []
searchResults.forEach((r: SearchResult) => {
const location = {
type: 'url',
target: `https://${r.repository}/${r.filename}`,
}
const yaml = Buffer.from(r.fileContent, 'utf8')
for (const item of parseEntityYaml(yaml, location)) {
const parsed = item as CatalogProcessorEntityResult
results.push({
entity: {
...parsed.entity,
metadata: {
...parsed.entity.metadata,
annotations: {
...parsed.entity.metadata.annotations,
[ANNOTATION_LOCATION]: `url:${parsed.location.target}`,
[ANNOTATION_ORIGIN_LOCATION]: providerName,
},
},
},
locationKey: parsed.location.target,
})
}
})
return results
}
const apiEntityParser =
(type: EntityType): ParserFunction =>
(src: SearchResult[], providerName: string): DeferredEntity[] =>
apiEntityDefinitionParser(src, providerName, type)
export const parserForType = (entityType: EntityType): ParserFunction => {
if (entityType === 'file') {
return parseCatalogContent
} else if (entityType === 'grpc' || entityType === 'graphql') {
return apiEntityParser(entityType)
} else {
throw new Error(`unknown Entity Type: ${entityType}`)
}
}

View File

@ -1,87 +0,0 @@
import { Config } from '@backstage/config'
import { SearchService, createService } from '../client'
import { parserForType, ParserFunction } from './parsers'
import { EntityProvider, EntityProviderConnection } from '@backstage/plugin-catalog-backend'
export type EntityType = 'file' | 'grpc' | 'graphql'
abstract class BaseEntityProvider implements EntityProvider {
private connection?: EntityProviderConnection
private sourcegraph?: SearchService
private query: string
private endpoint: string
private disabled: boolean = false
private readonly entityType: EntityType
private entityParseFn: ParserFunction
protected constructor(config: Config, entityType: EntityType) {
const token = config.getString('sourcegraph.token')
const sudoUsername = config.getOptionalString('sourcegraph.sudoUsername')
const queryConfig = config.getConfig(`sourcegraph.${entityType}`)
this.endpoint = config.getString('sourcegraph.endpoint')
this.entityType = entityType
this.entityParseFn = parserForType(entityType)
this.query = queryConfig.getOptionalString('query') ?? ''
this.disabled = this.query == ''
if (!this.disabled) {
createService({ endpoint: this.endpoint, token, sudoUsername }).then(
service => (this.sourcegraph = service.Search)
)
} else {
console.error("query '' is invalid - provider will be in disabled state")
}
}
getProviderName(): string {
return `url: ${this.endpoint}/sourcegraph-${this.entityType}-entity-provider`
}
async connect(connection: EntityProviderConnection): Promise<void> {
this.connection = connection
}
async run(): Promise<void> {
if (!this.connection) {
throw new Error('connection not initialized')
}
await this.fullMutation()
}
async fullMutation() {
// TODO(@burmudar): remove - only temporary
if (this.disabled) {
console.log(`${this.getProviderName} is disabled`)
return
}
const results = await this.sourcegraph?.searchQuery(this.query)
console.log(`${results?.length} items matched query ${this.query}`)
const entities = this.entityParseFn(results ?? [], this.getProviderName())
await this.connection?.applyMutation({
type: 'full',
entities: entities,
})
}
}
export class GrpcEntityProvider extends BaseEntityProvider {
constructor(config: Config) {
super(config, 'grpc')
}
}
export class GraphQLEntityProvider extends BaseEntityProvider {
constructor(config: Config) {
super(config, 'graphql')
}
}
export class YamlFileEntityProvider extends BaseEntityProvider {
constructor(config: Config) {
super(config, 'file')
}
}

View File

@ -1,2 +0,0 @@
// Need an empty export to make it a module tsc complains about the empty file
export {}

View File

@ -1,16 +0,0 @@
import { describe, expect, test } from '@jest/globals'
import { createService, Config, SourcegraphService } from '../../client/SourcegraphClient'
const sgConf: Config = {
endpoint: 'https://scaletesting.sgdev.org',
token: process.env.SG_TOKEN ?? '',
}
describe('integration test against dotCom', async () => {
const sourcegraphService: SourcegraphService = await createService(sgConf)
test('check current user', async () => {
const username: string = await sourcegraphService.Users.currentUsername()
console.log(username)
expect(username).toBe('burmudar')
})
})

View File

@ -1,35 +0,0 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"target": "es2020",
"lib": ["esnext", "DOM", "DOM.Iterable"],
"sourceMap": true,
"sourceRoot": "src",
"baseUrl": "./src",
"paths": {
"@sourcegraph/*": ["../*"],
"*": ["types/*", "../../shared/src/types/*", "../../common/src/types/*", "*"],
},
"esModuleInterop": true,
"resolveJsonModule": true,
"strict": true,
"jsx": "react-jsx",
"declaration": true,
"outDir": "dist/types",
"rootDir": "./src",
},
"references": [
{
"path": "../build-config",
},
{
"path": "../http-client",
},
{
"path": "../shared",
},
],
"include": ["**/*", "**/*.d.ts"],
"exclude": ["node_modules", "../../node_modules", "dist", "**/*.test.ts", "scripts"],
}

View File

@ -1,12 +0,0 @@
const baseConfig = require('../../.eslintrc')
module.exports = {
extends: '../../.eslintrc.js',
parserOptions: {
...baseConfig.parserOptions,
project: [__dirname + '/tsconfig.json'],
},
rules: {
'no-console': 'off',
},
overrides: baseConfig.overrides,
}

View File

@ -1,3 +0,0 @@
dist
dev/
!dev/index.tsx

View File

@ -1,3 +0,0 @@
dist/
dev/*
!dev/*.tsx

View File

@ -1,61 +0,0 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_config")
load("@npm//:defs.bzl", "npm_link_all_packages")
load("//dev:defs.bzl", "ts_project")
npm_link_all_packages(name = "node_modules")
ts_config(
name = "tsconfig",
src = "tsconfig.json",
visibility = ["//client:__subpackages__"],
deps = [
"//:tsconfig",
"//client/build-config:tsconfig",
],
)
ts_project(
name = "backstage-frontend",
srcs = [
"src/components/ExampleComponent/ExampleComponent.tsx",
"src/components/ExampleComponent/index.ts",
"src/components/ExampleFetchComponent/ExampleFetchComponent.tsx",
"src/components/ExampleFetchComponent/index.ts",
"src/index.ts",
"src/plugin.ts",
"src/routes.ts",
"src/setupTests.ts",
],
tsconfig = ":tsconfig",
deps = [
":node_modules/@backstage/core-components",
":node_modules/@backstage/core-plugin-api",
":node_modules/@material-ui/core",
":node_modules/@material-ui/lab",
":node_modules/@testing-library/jest-dom",
":node_modules/cross-fetch",
":node_modules/react",
":node_modules/react-use",
"//:node_modules/@types/react", #keep
"//:node_modules/@types/testing-library__jest-dom",
],
)
ts_project(
name = "backstage-frontend_tests",
testonly = True,
srcs = [
"src/components/ExampleComponent/ExampleComponent.test.tsx",
"src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx",
"src/plugin.test.ts",
],
tsconfig = ":tsconfig",
deps = [
":backstage-frontend",
":node_modules/@backstage/test-utils",
":node_modules/@testing-library/react",
":node_modules/msw",
":node_modules/react",
"//:node_modules/@types/react",
],
)

View File

@ -1,17 +0,0 @@
# Sourcegraph Backstage Frontend (WIP)
Welcome to the Sourcegraph Backstage Frontend plugin!
_This plugin was created through the Backstage CLI_
## NOTE
This plugin is still very much in development as is a work in progress. For any questions please ask in #job-fair-backstage or dm @William Bezuidenhout
## Getting started
Your plugin has been added to the example app in this repository, meaning you'll be able to access it by running `yarn start` in the root directory, and then navigating to [/sourcegraph](http://localhost:3000/sourcegraph).
You can also serve the plugin in isolation by running `yarn start` in the plugin directory.
This method of serving the plugin provides quicker iteration speed and a faster startup and hot reloads.
It is only meant for local development, and the setup for it can be found inside the [/dev](./dev) directory.

View File

@ -1,8 +0,0 @@
// @ts-check
/** @type {import('@babel/core').TransformOptions} */
const config = {
extends: '../../babel.config.js',
}
module.exports = config

View File

@ -1,12 +0,0 @@
import React from 'react'
import { createDevApp } from '@backstage/dev-utils'
import { sourcegraphPlugin, SourcegraphPage } from '../src/plugin'
createDevApp()
.registerPlugin(sourcegraphPlugin)
.addPage({
element: <SourcegraphPage />,
title: 'Root Page',
path: '/william',
})
.render()

View File

@ -1,27 +0,0 @@
{
"name": "@sourcegraph/backstage-frontend",
"description": "The Sourcegraph frontend plugin for Backstage",
"version": "0.1.0",
"main": "index.js",
"types": "types/src/index.d.ts",
"module": "index.js",
"license": "Apache-2.0",
"private": true,
"publishConfig": {
"access": "public"
},
"backstage": {
"role": "frontend-library"
},
"dependencies": {
"@backstage/core-components": "^0.12.3",
"@backstage/core-plugin-api": "^1.3.0",
"@backstage/theme": "^0.2.16",
"@material-ui/core": "^4.9.13",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.57",
"react": "^17.0.0",
"react-dom": "^17.0.0",
"react-use": "^17.2.4"
}
}

View File

@ -1,57 +0,0 @@
{
"name": "@sourcegraph/backstage-frontend",
"version": "0.1.0",
"main": "dist/index.ts",
"types": "dist/types/index.d.ts",
"license": "Apache-2.0",
"private": true,
"publishConfig": {
"access": "public",
"main": "dist/index.esm.js",
"types": "dist/index.d.ts"
},
"backstage": {
"role": "frontend-plugin"
},
"scripts": {
"dist": "ts-node --transpile-only ./scripts/esbuild.ts && pnpm types && cp package.dist.json dist/package.json",
"types": "tsc -d -p tsconfig.json",
"format": "prettier -w true .",
"test": "jest"
},
"dependencies": {
"@backstage/core-components": "^0.12.3",
"@backstage/core-plugin-api": "^1.3.0",
"@backstage/theme": "^0.2.16",
"@material-ui/core": "^4.9.13",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.57",
"react": "^17.0.0",
"react-dom": "^17.0.0",
"react-use": "^17.2.4"
},
"peerDependencies": {
"react": "^16.13.1 || ^17.0.0"
},
"devDependencies": {
"@backstage/cli": "^0.22.1",
"@backstage/core-app-api": "^1.4.0",
"@backstage/dev-utils": "^1.0.11",
"@backstage/test-utils": "^1.2.4",
"@sourcegraph/build-config": "workspace:^0.0.1",
"@sourcegraph/tsconfig": "^4.0.1",
"@testing-library/jest-dom": "^5.10.1",
"@testing-library/react": "^12.1.3",
"@testing-library/user-event": "^14.0.0",
"@types/node": "*",
"babel-jest": "^28.1.3",
"babel-loader": "^9.1.0",
"cross-fetch": "^3.1.5",
"esbuild": "^0.17.8",
"esbuild-node-externals": "^1.6.0",
"msw": "^0.49.0"
},
"files": [
"dist"
]
}

View File

@ -1,48 +0,0 @@
import { existsSync } from 'fs'
import path from 'path'
import { nodeExternalsPlugin } from 'esbuild-node-externals'
import * as esbuild from 'esbuild'
import { rm } from 'shelljs'
import { stylePlugin, workerPlugin, buildTimerPlugin, WORKSPACES_PATH } from '@sourcegraph/build-config'
const PACKAGE_ROOT_PATH = path.resolve(WORKSPACES_PATH, 'backstage-frontend')
const DIST_PATH = path.resolve(PACKAGE_ROOT_PATH, 'dist')
async function build(): Promise<void> {
if (existsSync(DIST_PATH)) {
rm('-rf', DIST_PATH)
}
await esbuild.build({
entryPoints: [path.resolve(PACKAGE_ROOT_PATH, 'src', 'index.ts')],
bundle: true,
format: 'esm',
logLevel: 'error',
jsx: 'automatic',
external: ['@backstage/*', '@material-ui/*', 'react-use', 'react', 'react-dom'],
plugins: [stylePlugin, workerPlugin, buildTimerPlugin, nodeExternalsPlugin()],
// mainFields: ['browser', 'module', 'main'],
// platform: 'browser',
define: {
'process.env.IS_TEST': 'false',
global: 'window',
},
loader: {
'.yaml': 'text',
'.ttf': 'file',
'.png': 'file',
},
treeShaking: true,
target: 'esnext',
sourcemap: true,
outdir: DIST_PATH,
})
}
if (require.main == module) {
build()
.catch(error => console.error('Error:', error))
.finally(() => process.exit(0))
}

View File

@ -1,22 +0,0 @@
import React from 'react'
import { ExampleComponent } from './ExampleComponent'
import { rest } from 'msw'
import { setupServer } from 'msw/node'
import { screen } from '@testing-library/react'
import { setupRequestMockHandlers, renderInTestApp } from '@backstage/test-utils'
describe('ExampleComponent', () => {
const server = setupServer()
// Enable sane handlers for network requests
setupRequestMockHandlers(server)
// setup mock response
beforeEach(() => {
server.use(rest.get('/*', (_, res, ctx) => res(ctx.status(200), ctx.json({}))))
})
it('should render', async () => {
await renderInTestApp(<ExampleComponent />)
expect(screen.getByText('Welcome to Sourcgraph!')).toBeInTheDocument()
})
})

View File

@ -1,28 +0,0 @@
import React from 'react'
import { Typography, Grid } from '@material-ui/core'
import { InfoCard, Header, Page, Content, ContentHeader, HeaderLabel, SupportButton } from '@backstage/core-components'
import { ExampleFetchComponent } from '../ExampleFetchComponent'
export const ExampleComponent = () => (
<Page themeId="tool">
<Header title="Welcome to Sourcegraph!" subtitle="Optional subtitle">
<HeaderLabel label="Owner" value="Team X" />
<HeaderLabel label="Lifecycle" value="Alpha" />
</Header>
<Content>
<ContentHeader title="Plugin title">
<SupportButton>A description of your plugin goes here.</SupportButton>
</ContentHeader>
<Grid container spacing={3} direction="column">
<Grid item>
<InfoCard title="Information card">
<Typography variant="body1">All content should be wrapped in a card like this.</Typography>
</InfoCard>
</Grid>
<Grid item>
<ExampleFetchComponent />
</Grid>
</Grid>
</Content>
</Page>
)

View File

@ -1 +0,0 @@
export { ExampleComponent } from './ExampleComponent'

View File

@ -1,23 +0,0 @@
import React from 'react'
import { render, screen } from '@testing-library/react'
import { ExampleFetchComponent } from './ExampleFetchComponent'
import { rest } from 'msw'
import { setupServer } from 'msw/node'
import { setupRequestMockHandlers } from '@backstage/test-utils'
describe('ExampleFetchComponent', () => {
const server = setupServer()
// Enable sane handlers for network requests
setupRequestMockHandlers(server)
// setup mock response
beforeEach(() => {
server.use(
rest.get('https://randomuser.me/*', (_, res, ctx) => res(ctx.status(200), ctx.delay(2000), ctx.json({})))
)
})
it('should render', async () => {
await render(<ExampleFetchComponent />)
expect(await screen.findByTestId('progress')).toBeInTheDocument()
})
})

View File

@ -1,84 +0,0 @@
import React from 'react'
import { makeStyles } from '@material-ui/core/styles'
import { Table, TableColumn, Progress } from '@backstage/core-components'
import Alert from '@material-ui/lab/Alert'
import useAsync from 'react-use/lib/useAsync'
const useStyles = makeStyles({
avatar: {
height: 32,
width: 32,
borderRadius: '50%',
},
})
type User = {
gender: string // "male"
name: {
title: string // "Mr",
first: string // "Duane",
last: string // "Reed"
}
location: object // {street: {number: 5060, name: "Hickory Creek Dr"}, city: "Albany", state: "New South Wales",…}
email: string // "duane.reed@example.com"
login: object // {uuid: "4b785022-9a23-4ab9-8a23-cb3fb43969a9", username: "blackdog796", password: "patch",…}
dob: object // {date: "1983-06-22T12:30:23.016Z", age: 37}
registered: object // {date: "2006-06-13T18:48:28.037Z", age: 14}
phone: string // "07-2154-5651"
cell: string // "0405-592-879"
id: {
name: string // "TFN",
value: string // "796260432"
}
picture: { medium: string } // {medium: "https://randomuser.me/api/portraits/men/95.jpg",…}
nat: string // "AU"
}
type DenseTableProps = {
users: User[]
}
export const DenseTable = ({ users }: DenseTableProps) => {
const classes = useStyles()
const columns: TableColumn[] = [
{ title: 'Avatar', field: 'avatar' },
{ title: 'Name', field: 'name' },
{ title: 'Email', field: 'email' },
{ title: 'Nationality', field: 'nationality' },
]
const data = users.map(user => {
return {
avatar: <img src={user.picture.medium} className={classes.avatar} alt={user.name.first} />,
name: `${user.name.first} ${user.name.last}`,
email: user.email,
nationality: user.nat,
}
})
return (
<Table
title="Example User List (fetching data from randomuser.me)"
options={{ search: false, paging: false }}
columns={columns}
data={data}
/>
)
}
export const ExampleFetchComponent = () => {
const { value, loading, error } = useAsync(async (): Promise<User[]> => {
const response = await fetch('https://randomuser.me/api/?results=20')
const data = await response.json()
return data.results
}, [])
if (loading) {
return <Progress />
} else if (error) {
return <Alert severity="error">{error.message}</Alert>
}
return <DenseTable users={value || []} />
}

View File

@ -1 +0,0 @@
export { ExampleFetchComponent } from './ExampleFetchComponent'

View File

@ -1 +0,0 @@
export { sourcegraphPlugin, SourcegraphPage } from './plugin'

View File

@ -1,7 +0,0 @@
import { sourcegraphPlugin } from './plugin'
describe('sourcegraph', () => {
it('should export plugin', () => {
expect(sourcegraphPlugin).toBeDefined()
})
})

View File

@ -1,18 +0,0 @@
import { createPlugin, createRoutableExtension } from '@backstage/core-plugin-api'
import { rootRouteRef } from './routes'
export const sourcegraphPlugin = createPlugin({
id: 'sourcegraph',
routes: {
root: rootRouteRef,
},
})
export const SourcegraphPage = sourcegraphPlugin.provide(
createRoutableExtension({
name: 'SourcegraphPage',
component: () => import('./components/ExampleComponent').then(m => m.ExampleComponent),
mountPoint: rootRouteRef,
})
)

View File

@ -1,5 +0,0 @@
import { createRouteRef } from '@backstage/core-plugin-api'
export const rootRouteRef = createRouteRef({
id: 'sourcegraph',
})

View File

@ -1,2 +0,0 @@
import '@testing-library/jest-dom'
import 'cross-fetch/polyfill'

View File

@ -1,31 +0,0 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"target": "es2020",
"sourceMap": true,
"sourceRoot": "src",
"baseUrl": ".",
"paths": {
"@sourcegraph/*": ["../*"],
"*": ["types/*", "../../shared/src/types/*", "../../common/src/types/*", "*"],
},
"resolveJsonModule": true,
"jsx": "react",
"declaration": true,
"outDir": "dist/types",
"rootDir": ".",
},
"references": [
{
"path": "../build-config",
},
],
"include": ["**/*", ".*", "./src/**/*.json"],
"exclude": ["node_modules", "../../node_modules", "dist", "**/*.test.ts", "scripts"],
"ts-node": {
"moduleTypes": {
"scripts/**/*": "cjs",
},
},
}

27
client/web/BUILD.bazel generated
View File

@ -264,6 +264,8 @@ ts_project(
"src/components/externalServices/AddExternalServicesPage.tsx",
"src/components/externalServices/ExternalServiceCard.tsx",
"src/components/externalServices/ExternalServiceEditPage.tsx",
"src/components/externalServices/ExternalServiceEditingAppLimitInPlaceAlert.tsx",
"src/components/externalServices/ExternalServiceEditingAppLimitReachedAlert.tsx",
"src/components/externalServices/ExternalServiceEditingDisabledAlert.tsx",
"src/components/externalServices/ExternalServiceEditingTemporaryAlert.tsx",
"src/components/externalServices/ExternalServiceForm.tsx",
@ -278,6 +280,7 @@ ts_project(
"src/components/externalServices/backend.ts",
"src/components/externalServices/externalServices.tsx",
"src/components/externalServices/index.ts",
"src/components/externalServices/isAppLocalFileService.ts",
"src/components/fuzzyFinder/FuzzyActions.tsx",
"src/components/fuzzyFinder/FuzzyFiles.tsx",
"src/components/fuzzyFinder/FuzzyFinder.mocks.tsx",
@ -532,12 +535,20 @@ ts_project(
"src/enterprise/codeintel/configuration/components/EmptyPoliciesList.tsx",
"src/enterprise/codeintel/configuration/components/FlashMessage.tsx",
"src/enterprise/codeintel/configuration/components/IndexConfigurationSaveToolbar.tsx",
"src/enterprise/codeintel/configuration/components/InferenceScriptEditor.tsx",
"src/enterprise/codeintel/configuration/components/RepositoryPatternList.tsx",
"src/enterprise/codeintel/configuration/components/inference-form/CommandInput.tsx",
"src/enterprise/codeintel/configuration/components/inference-form/IndexJobLabel.tsx",
"src/enterprise/codeintel/configuration/components/inference-form/IndexJobNode.tsx",
"src/enterprise/codeintel/configuration/components/inference-form/InferenceForm.tsx",
"src/enterprise/codeintel/configuration/components/inference-form/auto-index-to-form-job.ts",
"src/enterprise/codeintel/configuration/components/inference-form/form-data-to-schema.ts",
"src/enterprise/codeintel/configuration/components/inference-form/types.ts",
"src/enterprise/codeintel/configuration/components/inference-script/InferenceScriptEditor.tsx",
"src/enterprise/codeintel/configuration/components/inference-script/InferenceScriptPreview.tsx",
"src/enterprise/codeintel/configuration/components/inference-script/backend.ts",
"src/enterprise/codeintel/configuration/hooks/queryPolicies.tsx",
"src/enterprise/codeintel/configuration/hooks/types.tsx",
"src/enterprise/codeintel/configuration/hooks/useDeletePolicies.tsx",
"src/enterprise/codeintel/configuration/hooks/useInferJobs.tsx",
"src/enterprise/codeintel/configuration/hooks/useInferenceScript.tsx",
"src/enterprise/codeintel/configuration/hooks/useInferredConfig.tsx",
"src/enterprise/codeintel/configuration/hooks/usePolicyConfigurationById.tsx",
@ -1282,6 +1293,7 @@ ts_project(
"src/settings/tokens/AccessTokenNode.tsx",
"src/setup-wizard/SetupWizard.tsx",
"src/setup-wizard/components/ProgressBar.tsx",
"src/setup-wizard/components/SyncRepositoriesStep.tsx",
"src/setup-wizard/components/remote-repositories-step/RemoteRepositoriesStep.tsx",
"src/setup-wizard/components/remote-repositories-step/components/CodeHostExternalServiceAlert.tsx",
"src/setup-wizard/components/remote-repositories-step/components/code-host-delete-modal/CodeHostDeleteModal.tsx",
@ -1526,6 +1538,7 @@ ts_project(
":graphql_operations",
":module_style_typings",
":node_modules/@sourcegraph/branded",
":node_modules/@sourcegraph/client-api", #keep
":node_modules/@sourcegraph/codeintellify",
":node_modules/@sourcegraph/common",
":node_modules/@sourcegraph/extension-api-types", #keep
@ -1538,6 +1551,7 @@ ts_project(
"//:node_modules/@codemirror/lang-json",
"//:node_modules/@codemirror/lang-markdown",
"//:node_modules/@codemirror/language",
"//:node_modules/@codemirror/legacy-modes",
"//:node_modules/@codemirror/search",
"//:node_modules/@codemirror/state",
"//:node_modules/@codemirror/view",
@ -1559,6 +1573,7 @@ ts_project(
"//:node_modules/@reach/visually-hidden",
"//:node_modules/@sentry/browser", #keep
"//:node_modules/@sourcegraph/extension-api-classes",
"//:node_modules/@storybook/client-api", #keep
"//:node_modules/@types/bloomfilter",
"//:node_modules/@types/chrome", #keep
"//:node_modules/@types/classnames",
@ -1674,6 +1689,10 @@ ts_project(
"src/enterprise/code-monitoring/components/actions/EmailAction.test.tsx",
"src/enterprise/code-monitoring/components/actions/SlackWebhookAction.test.tsx",
"src/enterprise/code-monitoring/components/actions/WebhookAction.test.tsx",
"src/enterprise/codeintel/configuration/components/inference-form/auto-index-to-schema.test.ts",
# TODO(bazel): should not be here. Caused by the issue in `rules_js`.
"src/enterprise/codeintel/configuration/schema.json", #keep
"src/enterprise/insights/components/creation-ui/code-insight-time-step-picker/get-interval-descrtiption-text/get-interval-description.text.test.ts",
"src/enterprise/insights/hooks/use-parallel-requests/use-prallel-requests.test.ts",
"src/enterprise/insights/pages/CodeInsightsRootPage.test.tsx",
@ -1768,6 +1787,8 @@ ts_project(
"//:node_modules/@types/react-dom",
"//:node_modules/@types/semver",
"//:node_modules/@types/sinon",
"//:node_modules/ajv",
"//:node_modules/ajv-formats",
"//:node_modules/date-fns",
"//:node_modules/delay",
"//:node_modules/history",
@ -1905,6 +1926,6 @@ build_test(
name = "webpack_test",
targets = [
":bundle",
":bundle-dev",
":bundle-enterprise",
],
)

View File

@ -20,9 +20,6 @@ ts_config(
ts_project(
name = "dev",
srcs = [
"esbuild/build.ts",
"esbuild/manifestPlugin.ts",
"esbuild/server.ts",
"mocks/mockEventLogger.ts",
"server/production.server.ts",
"utils/constants.ts",
@ -48,7 +45,6 @@ ts_project(
"//:node_modules/chalk",
"//:node_modules/compression",
"//:node_modules/connect-history-api-fallback",
"//:node_modules/esbuild",
"//:node_modules/express",
"//:node_modules/express-static-gzip",
"//:node_modules/http-proxy-middleware",
@ -57,7 +53,6 @@ ts_project(
"//:node_modules/signale",
"//:node_modules/webpack", #keep
"//client/web:node_modules/@sourcegraph/build-config",
"//client/web:node_modules/@sourcegraph/common",
"//client/web:web_lib", #keep
],
)

4
client/web/dev/esbuild/BUILD.bazel generated Normal file
View File

@ -0,0 +1,4 @@
# TODO(bazel): esbuild dev tools currently disabled in bazel
# See client/build-config/src/esbuild/BUILD.bazel
# gazelle:js disabled

View File

@ -21,7 +21,7 @@ import { useExternalServicesConnection } from './backend'
import { ExternalServiceEditingAppLimitAlert } from './ExternalServiceEditingAppLimitReachedAlert'
import { ExternalServiceEditingDisabledAlert } from './ExternalServiceEditingDisabledAlert'
import { ExternalServiceEditingTemporaryAlert } from './ExternalServiceEditingTemporaryAlert'
import { ExternalServiceNode } from './ExternalServiceNode.tsx'
import { ExternalServiceNode } from './ExternalServiceNode'
import { isAppLocalFileService } from './isAppLocalFileService'
interface Props extends TelemetryProps {

View File

@ -13,7 +13,6 @@ go_library(
"//internal/auth",
"//internal/codeintel/types",
"//internal/conf",
"//internal/conf/deploy",
"//internal/database",
"//internal/search/job/jobutil",
],

View File

@ -93,6 +93,7 @@ go_library(
"outbound_webhook_logs.go",
"outbound_webhooks.go",
"own.go",
"package_repo_filters.go",
"package_repos.go",
"parse_search_query.go",
"permissions_sync_jobs.go",
@ -213,6 +214,7 @@ go_library(
"//internal/binary",
"//internal/cloneurls",
"//internal/codeintel/dependencies",
"//internal/codeintel/dependencies/shared",
"//internal/codeintel/resolvers",
"//internal/conf",
"//internal/conf/conftypes",

View File

@ -22,6 +22,7 @@ go_library(
"//internal/database",
"//internal/env",
"//internal/lazyregexp",
"//internal/singleprogram/filepicker",
"//internal/types",
"//internal/version",
"//schema",

View File

@ -64,6 +64,10 @@ go_test(
"verify_email_test.go",
],
embed = [":userpasswd"],
tags = [
# requires localhost database
"requires-network",
],
deps = [
"//cmd/frontend/backend",
"//cmd/frontend/internal/session",

View File

@ -21,6 +21,7 @@ go_library(
"//internal/redispool",
"//internal/types",
"//lib/errors",
"@com_github_fatih_color//:color",
"@com_github_gomodule_redigo//redis",
"@com_github_inconshreveable_log15//:log15",
"@com_github_pkg_browser//:browser",

View File

@ -50,6 +50,8 @@ go_library(
"//internal/featureflag",
"//internal/gitserver",
"//internal/goroutine",
"//internal/grpc",
"//internal/grpc/defaults",
"//internal/httpserver",
"//internal/instrumentation",
"//internal/jsonc",
@ -82,6 +84,7 @@ go_library(
"@com_github_throttled_throttled_v2//:throttled",
"@com_github_throttled_throttled_v2//store/memstore",
"@com_github_throttled_throttled_v2//store/redigostore",
"@org_golang_google_grpc//:go_default_library",
],
)

View File

@ -46,12 +46,18 @@ go_test(
"html_test.go",
"language_test.go",
],
data = glob(["testdata/**"]),
embed = [":highlight"],
embedsrcs = [
"testdata/telemetry-raw.txt",
"testdata/telemetry.scip",
],
deps = [
"//internal/gosyntect",
"//lib/errors",
"@com_github_google_go_cmp//cmp",
"@com_github_grafana_regexp//:regexp",
"@com_github_hexops_autogold_v2//:autogold",
"@com_github_sourcegraph_scip//bindings/go/scip",
"@com_github_stretchr_testify//require",
"@org_golang_google_protobuf//proto",

View File

@ -78,8 +78,12 @@ go_library(
"@com_github_prometheus_client_golang//prometheus/promauto",
"@com_github_sourcegraph_log//:log",
"@com_github_sourcegraph_zoekt//:zoekt",
"@com_github_sourcegraph_zoekt//cmd/zoekt-sourcegraph-indexserver/protos/sourcegraph/zoekt/configuration/v1:configuration",
"@com_github_throttled_throttled_v2//:throttled",
"@io_opentelemetry_go_otel//attribute",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//codes",
"@org_golang_google_grpc//status",
],
)
@ -129,14 +133,17 @@ go_test(
"@com_github_derision_test_glock//:glock",
"@com_github_derision_test_go_mockgen//testutil/require",
"@com_github_google_go_cmp//cmp",
"@com_github_google_go_cmp//cmp/cmpopts",
"@com_github_gorilla_mux//:mux",
"@com_github_graph_gophers_graphql_go//errors",
"@com_github_inconshreveable_log15//:log15",
"@com_github_masterminds_semver//:semver",
"@com_github_sourcegraph_log//logtest",
"@com_github_sourcegraph_zoekt//:zoekt",
"@com_github_sourcegraph_zoekt//cmd/zoekt-sourcegraph-indexserver/protos/sourcegraph/zoekt/configuration/v1:configuration",
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
"@com_github_throttled_throttled_v2//store/memstore",
"@org_golang_google_protobuf//testing/protocmp",
],
)

View File

@ -2,7 +2,10 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "shared",
srcs = ["service.go"],
srcs = [
"debug.go",
"service.go",
],
importpath = "github.com/sourcegraph/sourcegraph/cmd/frontend/shared",
visibility = ["//visibility:public"],
deps = [

View File

@ -123,6 +123,9 @@ go_test(
# Test requires localhost database
"requires-network",
],
# This test loads coursier as a side effect, so we ensure the
# path is sandboxed properly.
env = {"COURSIER_CACHE_DIR": "/tmp"},
deps = [
"//internal/actor",
"//internal/api",

View File

@ -58,6 +58,9 @@ go_test(
name = "shared_test",
srcs = ["shared_test.go"],
embed = [":shared"],
# This test loads coursier as a side effect, so we ensure the
# path is sandboxed properly.
env = {"COURSIER_CACHE_DIR": "/tmp"},
deps = [
"//cmd/gitserver/server",
"//internal/api",

View File

@ -5723,8 +5723,8 @@ def go_dependencies():
name = "com_github_sourcegraph_zoekt",
build_file_proto_mode = "disable_global",
importpath = "github.com/sourcegraph/zoekt",
sum = "h1:XO7th5aa0YMebq14wz6HC8guKkz9pjvlW1QKIbXchZk=",
version = "v0.0.0-20230303172250-3b0248719b12",
sum = "h1:O834DoaXIyOiQ27/qrev1Pjd79njJru1Kqjwf59ahpg=",
version = "v0.0.0-20230308131753-939eb52f3486",
)
go_repository(

View File

@ -5,5 +5,5 @@ go_library(
srcs = ["ineffassign.go"],
importpath = "github.com/sourcegraph/sourcegraph/dev/linters/ineffassign",
visibility = ["//visibility:public"],
deps = ["@com_github_gordonklaus_ineffassign//pkg/ineffassign:go_default_library"],
deps = ["@com_github_gordonklaus_ineffassign//pkg/ineffassign"],
)

View File

@ -62,15 +62,15 @@ def mocha_test(name, tests, deps = [], args = [], data = [], env = {}, **kwargs)
"MOCHA_FILE": "$$XML_OUTPUT_FILE",
# TODO(bazel): e2e test environment
"TEST_USER_EMAIL": "test@sourcegraph.com"
"TEST_USER_PASSWORD": "supersecurepassword"
"SOURCEGRAPH_BASE_URL": "https://sourcegraph.test:3443"
"TEST_USER_EMAIL": "test@sourcegraph.com",
"TEST_USER_PASSWORD": "supersecurepassword",
"SOURCEGRAPH_BASE_URL": "https://sourcegraph.test:3443",
"GH_TOKEN": "fake-gh-token",
"SOURCEGRAPH_SUDO_TOKEN": "fake-sg-token",
"NO_CLEANUP": "true",
"KEEP_BROWSER": "true",
"DEVTOOLS": "true",
"BROWSER": "chrome"
"BROWSER": "chrome",
}),
tags = ["manual"],
**kwargs

View File

@ -5,25 +5,25 @@ rust_binary(
name = "syntect_server",
srcs = ["src/main.rs"],
aliases = aliases(),
deps = all_crate_deps(
normal = True,
) + ["//docker-images/syntax-highlighter/crates/sg-syntax:sg-syntax"],
proc_macro_deps = all_crate_deps(
proc_macro = True,
),
deps = all_crate_deps(
normal = True,
) + ["//docker-images/syntax-highlighter/crates/sg-syntax:sg-syntax"],
)
rust_test(
name = "unit_test",
crate = ":syntect_server",
aliases = aliases(
normal_dev = True,
proc_macro_dev = True,
),
crate = ":syntect_server",
proc_macro_deps = all_crate_deps(
proc_macro_dev = True,
),
deps = all_crate_deps(
normal_dev = True,
),
proc_macro_deps = all_crate_deps(
proc_macro_dev = True,
),
)

View File

@ -2,29 +2,29 @@ load("@crate_index//:defs.bzl", "aliases", "all_crate_deps")
load("@rules_rust//rust:defs.bzl", "rust_proc_macro", "rust_test")
rust_proc_macro(
name = "sg-macros",
srcs = ["src/lib.rs"],
aliases = aliases(),
deps = all_crate_deps(
normal = True,
),
proc_macro_deps = all_crate_deps(
proc_macro = True,
),
visibility = ["//docker-images/syntax-highlighter:__subpackages__"],
name = "sg-macros",
srcs = ["src/lib.rs"],
aliases = aliases(),
proc_macro_deps = all_crate_deps(
proc_macro = True,
),
visibility = ["//docker-images/syntax-highlighter:__subpackages__"],
deps = all_crate_deps(
normal = True,
),
)
rust_test(
name = "unit_test",
crate = ":sg-macros",
aliases = aliases(
normal_dev = True,
proc_macro_dev = True,
),
crate = ":sg-macros",
proc_macro_deps = all_crate_deps(
proc_macro_dev = True,
),
deps = all_crate_deps(
normal_dev = True,
),
proc_macro_deps = all_crate_deps(
proc_macro_dev = True,
),
)

View File

@ -4,32 +4,35 @@ load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
rust_library(
name = "sg-syntax",
srcs = glob(["src/*.rs"]),
compile_data = glob(["queries/**"], allow_empty=False),
aliases = aliases(),
deps = all_crate_deps(
normal = True,
compile_data = glob(
["queries/**"],
allow_empty = False,
),
proc_macro_deps = all_crate_deps(
proc_macro = True,
) + ["//docker-images/syntax-highlighter/crates/sg-macros:sg-macros"],
visibility = ["//docker-images/syntax-highlighter:__subpackages__"],
deps = all_crate_deps(
normal = True,
),
)
# This prevents bazel configure for generating buildfiles because it sees
# some go files in that folder.
# gazelle:exclude src/snapshots
rust_test(
name = "unit_test",
crate = ":sg-syntax",
data = glob(["src/snapshots/**"], allow_empty=False),
size = "small",
aliases = aliases(
normal_dev = True,
proc_macro_dev = True,
),
deps = all_crate_deps(
normal_dev = True,
crate = ":sg-syntax",
data = glob(
["src/snapshots/**"],
allow_empty = False,
),
proc_macro_deps = all_crate_deps(
proc_macro_dev = True,
),
size = "small",
env = {
"RUST_BACKTRACE": "1",
# NOTE: Outside of Bazel, insta relies on invoking `cargo` (via PATH)
@ -39,4 +42,10 @@ rust_test(
# so tests don't need `cargo` access at runtime.
"INSTA_WORKSPACE_ROOT": ".",
},
proc_macro_deps = all_crate_deps(
proc_macro_dev = True,
),
deps = all_crate_deps(
normal_dev = True,
),
)

View File

@ -0,0 +1,9 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "rbac",
srcs = ["permissions.go"],
importpath = "github.com/sourcegraph/sourcegraph/enterprise/cmd/frontend/internal/batches/rbac",
visibility = ["//enterprise/cmd/frontend:__subpackages__"],
deps = ["//internal/types"],
)

View File

@ -43,6 +43,7 @@ go_library(
"//cmd/frontend/graphqlbackend",
"//cmd/frontend/graphqlbackend/externallink",
"//cmd/frontend/graphqlbackend/graphqlutil",
"//enterprise/cmd/frontend/internal/batches/rbac",
"//enterprise/internal/batches/graphql",
"//enterprise/internal/batches/reconciler",
"//enterprise/internal/batches/rewirer",
@ -70,6 +71,7 @@ go_library(
"//internal/gitserver",
"//internal/gitserver/gitdomain",
"//internal/gqlutil",
"//internal/rbac",
"//internal/trace",
"//internal/types",
"//internal/usagestats",
@ -121,6 +123,7 @@ go_test(
"//cmd/frontend/globals",
"//cmd/frontend/graphqlbackend",
"//cmd/frontend/graphqlbackend/externallink",
"//enterprise/cmd/frontend/internal/batches/rbac",
"//enterprise/cmd/frontend/internal/batches/resolvers/apitest",
"//enterprise/internal/batches/graphql",
"//enterprise/internal/batches/search",
@ -148,6 +151,7 @@ go_test(
"//internal/gqlutil",
"//internal/httptestutil",
"//internal/observation",
"//internal/rbac",
"//internal/rcache",
"//internal/repos",
"//internal/repoupdater",

View File

@ -16,26 +16,36 @@ go_library(
"//enterprise/internal/own/codeowners",
"//enterprise/internal/own/codeowners/v1:codeowners",
"//enterprise/internal/own/types",
"//internal/actor",
"//internal/api",
"//internal/auth",
"//internal/database",
"//internal/deviceid",
"//internal/errcode",
"//internal/featureflag",
"//internal/gitserver",
"//internal/gqlutil",
"//internal/types",
"//internal/usagestats",
"//lib/errors",
"@com_github_graph_gophers_graphql_go//:graphql-go",
"@com_github_graph_gophers_graphql_go//relay",
"@com_github_sourcegraph_log//:log",
],
)
go_test(
name = "resolvers_test",
srcs = ["resolvers_test.go"],
srcs = [
"codeowners_resolvers_test.go",
"resolvers_test.go",
],
embed = [":resolvers"],
deps = [
":resolvers",
"//cmd/frontend/backend",
"//cmd/frontend/graphqlbackend",
"//enterprise/internal/database",
"//enterprise/internal/own",
"//enterprise/internal/own/codeowners",
"//enterprise/internal/own/codeowners/v1:codeowners",
"//internal/actor",
@ -43,8 +53,12 @@ go_test(
"//internal/authz",
"//internal/database",
"//internal/database/fakedb",
"//internal/featureflag",
"//internal/gitserver",
"//internal/types",
"//lib/errors",
"@com_github_google_go_cmp//cmp",
"@com_github_graph_gophers_graphql_go//relay",
"@com_github_sourcegraph_log//logtest",
],
)

View File

@ -11,6 +11,7 @@ go_library(
"crates_syncer.go",
"lsifuploadstore_expirer.go",
"metrics_reporter.go",
"package_filter_applicator.go",
"policies_repomatcher_job.go",
"sentinel_job.go",
"upload_backfiller.go",

View File

@ -118,7 +118,7 @@ func GeneratePipeline(c Config) (*bk.Pipeline, error) {
}))
// At this stage, we don't break builds because of a Bazel failure.
// TODO(JH) Disabled until we fix database isolation
// TODO(JH) Disabled until re-enabled with flag
// ops.Merge(BazelOperations(true))
// Now we set up conditional operations that only apply to pull requests.
@ -278,6 +278,7 @@ func GeneratePipeline(c Config) (*bk.Pipeline, error) {
triggerAsync(buildOptions)))
// At this stage, we don't break builds because of a Bazel failure.
// TODO(JH) disabled until I re-enable this with a flag
// ops.Merge(BazelOperations(true))
// Slow image builds

View File

@ -15,6 +15,7 @@ go_library(
"mock_repo_perms.go",
"mock_sync_state.go",
"org.go",
"rbac.go",
"repos.go",
"rsa.go",
"specs.go",
@ -42,6 +43,7 @@ go_library(
"//internal/extsvc/gitlab",
"//internal/gitserver",
"//internal/gitserver/gitdomain",
"//internal/rbac",
"//internal/repoupdater",
"//internal/repoupdater/protocol",
"//internal/timeutil",
@ -54,5 +56,6 @@ go_library(
"@com_github_sourcegraph_go_diff//diff",
"@com_github_sourcegraph_log//logtest",
"@com_github_stretchr_testify//require",
"@in_gopkg_yaml_v2//:yaml_v2",
],
)

View File

@ -33,7 +33,6 @@ go_library(
"//internal/workerutil/dbworker/store",
"//lib/codeintel/autoindex/config",
"//lib/errors",
"@com_github_derision_test_glock//:glock",
"@com_github_grafana_regexp//:regexp",
"@com_github_opentracing_opentracing_go//log",
"@com_github_sourcegraph_log//:log",
@ -48,6 +47,10 @@ go_test(
"service_test.go",
],
embed = [":autoindexing"],
tags = [
# requires localhost database
"requires-network",
],
deps = [
"//enterprise/internal/codeintel/autoindexing/internal/jobselector",
"//enterprise/internal/codeintel/autoindexing/internal/store",
@ -56,7 +59,6 @@ go_test(
"//enterprise/internal/codeintel/uploads/shared",
"//internal/api",
"//internal/codeintel/dependencies",
"//internal/database",
"//internal/gitserver/gitdomain",
"//internal/observation",
"//internal/repoupdater/protocol",

View File

@ -10,7 +10,6 @@ go_library(
"job_resetters.go",
"job_scheduler.go",
"job_summary_builder.go",
"metrics_janitor.go",
"metrics_resetter.go",
"utils.go",
],
@ -24,6 +23,7 @@ go_library(
"//enterprise/internal/codeintel/autoindexing/shared",
"//enterprise/internal/codeintel/policies",
"//enterprise/internal/codeintel/policies/shared",
"//enterprise/internal/codeintel/shared/background",
"//enterprise/internal/codeintel/shared/types",
"//enterprise/internal/codeintel/uploads/shared",
"//internal/actor",
@ -48,7 +48,6 @@ go_library(
"//internal/workerutil/dbworker/store",
"//lib/codeintel/precise",
"//lib/errors",
"@com_github_derision_test_glock//:glock",
"@com_github_grafana_regexp//:regexp",
"@com_github_keegancsmith_sqlf//:sqlf",
"@com_github_lib_pq//:pq",

View File

@ -16,6 +16,7 @@ go_library(
"//enterprise/internal/codeintel/autoindexing/internal/store",
"//enterprise/internal/codeintel/shared/types",
"//internal/codeintel/dependencies",
"//internal/database",
"//internal/errcode",
"//internal/metrics",
"//internal/observation",

View File

@ -17,6 +17,7 @@ go_library(
"//enterprise/internal/codeintel/autoindexing/internal/inference/libs",
"//enterprise/internal/codeintel/autoindexing/internal/inference/lua",
"//enterprise/internal/codeintel/autoindexing/internal/inference/luatypes",
"//enterprise/internal/paths",
"//internal/api",
"//internal/authz",
"//internal/codeintel/dependencies",
@ -33,7 +34,6 @@ go_library(
"//internal/ratelimit",
"//lib/codeintel/autoindex/config",
"//lib/errors",
"@com_github_grafana_regexp//:regexp",
"@com_github_opentracing_opentracing_go//log",
"@com_github_sourcegraph_log//:log",
"@com_github_yuin_gopher_lua//:gopher-lua",
@ -61,16 +61,17 @@ go_test(
embed = [":inference"],
deps = [
"//enterprise/internal/codeintel/autoindexing/internal/inference/libs",
"//enterprise/internal/paths",
"//internal/api",
"//internal/codeintel/dependencies",
"//internal/gitserver",
"//internal/gitserver/gitdomain",
"//internal/luasandbox",
"//internal/observation",
"//internal/ratelimit",
"//internal/unpack/unpacktest",
"//lib/codeintel/autoindex/config",
"@com_github_google_go_cmp//cmp",
"@com_github_grafana_regexp//:regexp",
"@org_golang_x_time//rate",
],
)

View File

@ -46,7 +46,6 @@ go_test(
"//enterprise/internal/codeintel/policies/internal/store",
"//enterprise/internal/codeintel/policies/shared",
"//enterprise/internal/codeintel/shared/types",
"//internal/database",
"//internal/gitserver/gitdomain",
"//internal/observation",
"//internal/timeutil",

View File

@ -4,7 +4,6 @@ go_library(
name = "background",
srcs = [
"job_graph_exporter.go",
"metrics.go",
"observabililty.go",
"ranking.go",
],
@ -12,13 +11,14 @@ go_library(
visibility = ["//enterprise:__subpackages__"],
deps = [
"//enterprise/internal/codeintel/ranking/internal/lsifstore",
"//enterprise/internal/codeintel/ranking/internal/shared",
"//enterprise/internal/codeintel/ranking/internal/store",
"//enterprise/internal/codeintel/shared/background",
"//enterprise/internal/codeintel/uploads/shared",
"//internal/conf",
"//internal/goroutine",
"//internal/observation",
"@com_github_prometheus_client_golang//prometheus",
"@com_github_sourcegraph_conc//pool",
"@com_github_sourcegraph_log//:log",
"@com_github_sourcegraph_scip//bindings/go/scip",
],

View File

@ -0,0 +1,9 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "shared",
srcs = ["keys.go"],
importpath = "github.com/sourcegraph/sourcegraph/enterprise/internal/codeintel/ranking/internal/shared",
visibility = ["//enterprise:__subpackages__"],
deps = ["//internal/conf"],
)

View File

@ -11,6 +11,7 @@ go_library(
importpath = "github.com/sourcegraph/sourcegraph/enterprise/internal/codeintel/ranking/internal/store",
visibility = ["//enterprise:__subpackages__"],
deps = [
"//enterprise/internal/codeintel/ranking/internal/shared",
"//enterprise/internal/codeintel/uploads/shared",
"//internal/api",
"//internal/database",
@ -40,6 +41,7 @@ go_test(
"requires-network",
],
deps = [
"//enterprise/internal/codeintel/ranking/internal/shared",
"//enterprise/internal/codeintel/shared/types",
"//enterprise/internal/codeintel/uploads/shared",
"//internal/api",

View File

@ -0,0 +1,17 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "background",
srcs = [
"janitor_job.go",
"pipeline_job.go",
],
importpath = "github.com/sourcegraph/sourcegraph/enterprise/internal/codeintel/shared/background",
visibility = ["//enterprise:__subpackages__"],
deps = [
"//internal/goroutine",
"//internal/metrics",
"//internal/observation",
"@com_github_prometheus_client_golang//prometheus",
],
)

View File

@ -12,7 +12,6 @@ go_library(
"job_resetters.go",
"job_worker_handler.go",
"metrics_expirer.go",
"metrics_janitors.go",
"metrics_resetter.go",
"observability.go",
"scip.go",
@ -22,6 +21,7 @@ go_library(
deps = [
"//enterprise/internal/codeintel/policies",
"//enterprise/internal/codeintel/policies/shared",
"//enterprise/internal/codeintel/shared/background",
"//enterprise/internal/codeintel/shared/types",
"//enterprise/internal/codeintel/uploads/internal/lsifstore",
"//enterprise/internal/codeintel/uploads/internal/store",
@ -34,7 +34,6 @@ go_library(
"//internal/goroutine",
"//internal/honey",
"//internal/memo",
"//internal/metrics",
"//internal/observation",
"//internal/timeutil",
"//internal/types",
@ -45,7 +44,6 @@ go_library(
"//lib/codeintel/pathexistence",
"//lib/codeintel/precise",
"//lib/errors",
"@com_github_derision_test_glock//:glock",
"@com_github_jackc_pgconn//:pgconn",
"@com_github_keegancsmith_sqlf//:sqlf",
"@com_github_opentracing_opentracing_go//log",
@ -71,6 +69,7 @@ go_test(
embed = [":background"],
deps = [
"//cmd/frontend/backend",
"//enterprise/internal/codeintel/autoindexing/shared",
"//enterprise/internal/codeintel/policies",
"//enterprise/internal/codeintel/policies/shared",
"//enterprise/internal/codeintel/shared/types",
@ -90,7 +89,6 @@ go_test(
"//internal/workerutil/dbworker/store",
"//lib/codeintel/precise",
"//lib/errors",
"@com_github_derision_test_glock//:glock",
"@com_github_google_go_cmp//cmp",
"@com_github_keegancsmith_sqlf//:sqlf",
"@com_github_sourcegraph_log//logtest",

View File

@ -6,6 +6,9 @@ go_test(
"commits_test.go",
"tree_test.go",
],
# This test loads coursier as a side effect, so we ensure the
# path is sandboxed properly.
env = {"COURSIER_CACHE_DIR": "/tmp"},
deps = [
"//enterprise/internal/authz/subrepoperms",
"//enterprise/internal/database",

View File

@ -6,7 +6,7 @@ go_library(
importpath = "github.com/sourcegraph/sourcegraph/enterprise/internal/insights",
visibility = ["//enterprise:__subpackages__"],
deps = [
"//cmd/frontend/enterprise",
"//cmd/frontend/graphqlbackend",
"//enterprise/internal/database",
"//internal/conf",
"//internal/conf/conftypes",

View File

@ -241,6 +241,7 @@ func TestReplace_Valid(t *testing.T) {
got, err := replacer.Replace(test.replacement)
test.want.Equal(t, got)
require.NoError(t, err)
})
}
}

View File

@ -3,6 +3,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "batches",
srcs = [
"empty_spec_id_migrator.go",
"external_fork_name_migrator.go",
"ssh_migrator.go",
],
@ -24,6 +25,7 @@ go_library(
go_test(
name = "batches_test",
srcs = [
"empty_spec_id_migrator_test.go",
"external_fork_name_migrator_test.go",
"ssh_migrator_test.go",
],
@ -36,6 +38,7 @@ go_test(
"//enterprise/internal/batches/sources/bitbucketcloud",
"//enterprise/internal/batches/store",
"//enterprise/internal/batches/testing",
"//enterprise/internal/batches/types",
"//internal/actor",
"//internal/api",
"//internal/database",

View File

@ -4,7 +4,6 @@ go_library(
name = "codeowners",
srcs = [
"file.go",
"find_owners.go",
"owner_types.go",
"parse.go",
"repr.go",
@ -13,10 +12,11 @@ go_library(
visibility = ["//:__subpackages__"],
deps = [
"//enterprise/internal/own/codeowners/v1:codeowners",
"//enterprise/internal/paths",
"//internal/api",
"//internal/lazyregexp",
"//internal/types",
"//lib/errors",
"@com_github_becheran_wildmatch_go//:wildmatch-go",
],
)

View File

@ -39,9 +39,12 @@ go_test(
"//internal/authz",
"//internal/database",
"//internal/gitserver",
"//internal/search",
"//internal/search/job",
"//internal/search/result",
"//internal/types",
"@com_github_hexops_autogold_v2//:autogold",
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
],
)

18
enterprise/internal/paths/BUILD.bazel generated Normal file
View File

@ -0,0 +1,18 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "paths",
srcs = ["match.go"],
importpath = "github.com/sourcegraph/sourcegraph/enterprise/internal/paths",
visibility = ["//enterprise:__subpackages__"],
deps = [
"//lib/errors",
"@com_github_becheran_wildmatch_go//:wildmatch-go",
],
)
go_test(
name = "paths_test",
srcs = ["match_test.go"],
embed = [":paths"],
)

View File

@ -48,6 +48,7 @@ go_test(
],
embed = [":scim"],
deps = [
"//internal/database",
"//internal/observation",
"//internal/types",
"@com_github_elimity_com_scim//:scim",

View File

@ -7,6 +7,7 @@ go_library(
visibility = ["//enterprise:__subpackages__"],
deps = [
"//enterprise/internal/own/search",
"//internal/search",
"//internal/search/job",
"//internal/search/job/jobutil",
],

View File

@ -9,6 +9,10 @@ go_library(
"service.go",
],
importpath = "github.com/sourcegraph/sourcegraph/internal/codeintel/dependencies",
tags = [
# requires localhost database
"requires-network",
],
visibility = ["//:__subpackages__"],
deps = [
"//internal/codeintel/dependencies/internal/background",
@ -19,6 +23,8 @@ go_library(
"//internal/goroutine",
"//internal/metrics",
"//internal/observation",
"//internal/packagefilters",
"//lib/errors",
"@com_github_opentracing_opentracing_go//log",
],
)

View File

@ -5,6 +5,7 @@ go_library(
srcs = [
"iface.go",
"job_cratesyncer.go",
"job_packages_filter.go",
"observability.go",
],
importpath = "github.com/sourcegraph/sourcegraph/internal/codeintel/dependencies/internal/background",
@ -13,6 +14,7 @@ go_library(
"//internal/actor",
"//internal/api",
"//internal/authz",
"//internal/codeintel/dependencies/internal/store",
"//internal/codeintel/dependencies/shared",
"//internal/conf/reposource",
"//internal/database",
@ -24,11 +26,13 @@ go_library(
"//internal/jsonc",
"//internal/metrics",
"//internal/observation",
"//internal/packagefilters",
"//internal/types",
"//lib/errors",
"//schema",
"@com_github_derision_test_glock//:glock",
"@com_github_json_iterator_go//:go",
"@com_github_prometheus_client_golang//prometheus",
],
)
@ -36,15 +40,22 @@ go_test(
name = "background_test",
srcs = [
"job_cratesyncer_test.go",
"job_packages_filter_test.go",
"mocks_test.go",
],
embed = [":background"],
tags = [
# requires localhost database
"requires-network",
],
deps = [
"//internal/api",
"//internal/authz",
"//internal/codeintel/dependencies/internal/store",
"//internal/codeintel/dependencies/shared",
"//internal/conf/reposource",
"//internal/database",
"//internal/database/dbtest",
"//internal/encryption",
"//internal/gitserver",
"//internal/gitserver/gitdomain",
@ -54,6 +65,8 @@ go_test(
"//lib/errors",
"//schema",
"@com_github_derision_test_glock//:glock",
"@com_github_google_go_cmp//cmp",
"@com_github_sourcegraph_log//logtest",
"@org_golang_x_exp//slices",
],
)

View File

@ -19,6 +19,7 @@ go_library(
"//internal/metrics",
"//internal/observation",
"//lib/errors",
"@com_github_jackc_pgconn//:pgconn",
"@com_github_keegancsmith_sqlf//:sqlf",
"@com_github_lib_pq//:pq",
"@com_github_opentracing_opentracing_go//log",

View File

@ -159,7 +159,7 @@ func newFromDSN(logger log.Logger, t testing.TB, templateNamespace string) *sql.
t.Cleanup(func() {
defer db.Close()
if t.Failed() {
if t.Failed() && os.Getenv("CI") != "true" {
t.Logf("DATABASE %s left intact for inspection", dbname)
return
}

View File

@ -25,6 +25,7 @@ go_library(
"//internal/metrics",
"//internal/oauthutil",
"//internal/ratelimit",
"//internal/timeutil",
"//internal/trace/ot",
"//lib/errors",
"//schema",

View File

@ -23,7 +23,6 @@ go_library(
"//internal/metrics",
"//internal/oauthutil",
"//internal/ratelimit",
"//internal/timeutil",
"//internal/trace/ot",
"//lib/errors",
"@com_github_golang_jwt_jwt_v4//:jwt",

View File

@ -65,6 +65,10 @@ go_test(
],
data = glob(["testdata/**"]),
embed = [":gitlab"],
tags = [
# requires localhost database
"requires-network",
],
deps = [
"//internal/conf",
"//internal/errcode",

Some files were not shown because too many files have changed in this diff Show More