mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 15:51:43 +00:00
gerrit: Add support for repositoryPathPattern (#64102)
Most other code host connections we support have this property to control the generated name, but for some reason it was forgotten for Gerrit. This PR adds it, plus a few tests.  Test plan: Added tests, cloned a gerrit repo locally. ## Changelog Added support for the `repositoryPathPattern` setting for Gerrit code host connections.
This commit is contained in:
parent
3ff0ddf1cb
commit
d249b8f701
@ -116,6 +116,9 @@ func getRepoNameFromService(ctx context.Context, cloneURL string, svc *types.Ext
|
||||
case *schema.BitbucketCloudConnection:
|
||||
rs = reposource.BitbucketCloud{BitbucketCloudConnection: c}
|
||||
host = c.Url
|
||||
case *schema.GerritConnection:
|
||||
rs = reposource.Gerrit{GerritConnection: c}
|
||||
host = c.Url
|
||||
case *schema.AWSCodeCommitConnection:
|
||||
rs = reposource.AWS{AWSCodeCommitConnection: c}
|
||||
// AWS type does not have URL
|
||||
|
||||
@ -17,12 +17,20 @@ func TestReposourceCloneURLToRepoName(t *testing.T) {
|
||||
|
||||
externalServices := dbmocks.NewMockExternalServiceStore()
|
||||
externalServices.ListFunc.SetDefaultReturn(
|
||||
[]*types.ExternalService{{
|
||||
ID: 1,
|
||||
Kind: extsvc.KindGitHub,
|
||||
DisplayName: "GITHUB #1",
|
||||
Config: extsvc.NewUnencryptedConfig(`{"url": "https://github.example.com", "repositoryQuery": ["none"], "token": "abc"}`),
|
||||
}},
|
||||
[]*types.ExternalService{
|
||||
{
|
||||
ID: 1,
|
||||
Kind: extsvc.KindGitHub,
|
||||
DisplayName: "GITHUB #1",
|
||||
Config: extsvc.NewUnencryptedConfig(`{"url": "https://github.example.com", "repositoryQuery": ["none"], "token": "abc"}`),
|
||||
},
|
||||
{
|
||||
ID: 2,
|
||||
Kind: extsvc.KindGerrit,
|
||||
DisplayName: "GERRIT #1",
|
||||
Config: extsvc.NewUnencryptedConfig(`{"url": "https://gerrit.example.com"}`),
|
||||
},
|
||||
},
|
||||
nil,
|
||||
)
|
||||
|
||||
@ -54,6 +62,11 @@ func TestReposourceCloneURLToRepoName(t *testing.T) {
|
||||
cloneURL: "../../a/b/c.git",
|
||||
wantRepoName: api.RepoName("github.example.com/a/b/c"),
|
||||
},
|
||||
{
|
||||
name: "gerrit",
|
||||
cloneURL: "https://gerrit.example.com/a/repo.git",
|
||||
wantRepoName: api.RepoName("gerrit.example.com/repo"),
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
|
||||
@ -9,6 +9,7 @@ go_library(
|
||||
"bitbucketserver.go",
|
||||
"common.go",
|
||||
"custom.go",
|
||||
"gerrit.go",
|
||||
"github.go",
|
||||
"gitlab.go",
|
||||
"gitolite.go",
|
||||
@ -50,6 +51,7 @@ go_test(
|
||||
"bitbucketserver_test.go",
|
||||
"common_test.go",
|
||||
"custom_test.go",
|
||||
"gerrit_test.go",
|
||||
"github_test.go",
|
||||
"gitlab_test.go",
|
||||
"gitolite_test.go",
|
||||
|
||||
40
internal/conf/reposource/gerrit.go
Normal file
40
internal/conf/reposource/gerrit.go
Normal file
@ -0,0 +1,40 @@
|
||||
package reposource
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/schema"
|
||||
)
|
||||
|
||||
type Gerrit struct {
|
||||
*schema.GerritConnection
|
||||
}
|
||||
|
||||
var _ RepoSource = Gerrit{}
|
||||
|
||||
func (c Gerrit) CloneURLToRepoName(cloneURL string) (repoName api.RepoName, err error) {
|
||||
parsedCloneURL, baseURL, match, err := parseURLs(cloneURL, c.Url)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if !match {
|
||||
return "", nil
|
||||
}
|
||||
name := strings.TrimSuffix(parsedCloneURL.Path, ".git")
|
||||
name = strings.TrimPrefix(name, "/")
|
||||
// Gerrit clone URLs can contain `/a/` prefixes which means "authenticated clone".
|
||||
name = strings.TrimPrefix(name, "a/")
|
||||
return GerritRepoName(c.RepositoryPathPattern, baseURL.Hostname(), name), nil
|
||||
}
|
||||
|
||||
func GerritRepoName(repositoryPathPattern, host, name string) api.RepoName {
|
||||
if repositoryPathPattern == "" {
|
||||
repositoryPathPattern = "{host}/{name}"
|
||||
}
|
||||
|
||||
return api.RepoName(strings.NewReplacer(
|
||||
"{host}", host,
|
||||
"{name}", name,
|
||||
).Replace(repositoryPathPattern))
|
||||
}
|
||||
63
internal/conf/reposource/gerrit_test.go
Normal file
63
internal/conf/reposource/gerrit_test.go
Normal file
@ -0,0 +1,63 @@
|
||||
package reposource
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/schema"
|
||||
)
|
||||
|
||||
func TestGerrit_cloneURLToRepoName(t *testing.T) {
|
||||
tests := []struct {
|
||||
conn schema.GerritConnection
|
||||
urls []urlToRepoName
|
||||
}{{
|
||||
conn: schema.GerritConnection{
|
||||
Url: "https://gerrit.example.com",
|
||||
},
|
||||
urls: []urlToRepoName{
|
||||
{"git@gerrit.example.com:gorilla/mux.git", "gerrit.example.com/gorilla/mux"},
|
||||
{"git@gerrit.example.com:/gorilla/mux.git", "gerrit.example.com/gorilla/mux"},
|
||||
{"git+https://gerrit.example.com/gorilla/mux.git", "gerrit.example.com/gorilla/mux"},
|
||||
{"https://gerrit.example.com/gorilla/mux.git", "gerrit.example.com/gorilla/mux"},
|
||||
{"https://www.gerrit.example.com/gorilla/mux.git", "gerrit.example.com/gorilla/mux"},
|
||||
// Authenticated clone URL.
|
||||
{"https://www.gerrit.example.com/a/gorilla/mux.git", "gerrit.example.com/gorilla/mux"},
|
||||
{"https://oauth2:ACCESS_TOKEN@gerrit.example.com/gorilla/mux.git", "gerrit.example.com/gorilla/mux"},
|
||||
|
||||
{"git@asdf.com:gorilla/mux.git", ""},
|
||||
{"https://asdf.com/gorilla/mux.git", ""},
|
||||
{"https://oauth2:ACCESS_TOKEN@asdf.com/gorilla/mux.git", ""},
|
||||
},
|
||||
}, {
|
||||
conn: schema.GerritConnection{
|
||||
Url: "https://gerrit.example.com",
|
||||
RepositoryPathPattern: "prefix/{name}",
|
||||
},
|
||||
urls: []urlToRepoName{
|
||||
{"git@gerrit.example.com:gorilla/mux.git", "prefix/gorilla/mux"},
|
||||
{"git@gerrit.example.com:/gorilla/mux.git", "prefix/gorilla/mux"},
|
||||
{"git+https://gerrit.example.com/gorilla/mux.git", "prefix/gorilla/mux"},
|
||||
{"https://gerrit.example.com/gorilla/mux.git", "prefix/gorilla/mux"},
|
||||
{"https://www.gerrit.example.com/gorilla/mux.git", "prefix/gorilla/mux"},
|
||||
// Authenticated clone URL.
|
||||
{"https://www.gerrit.example.com/a/gorilla/mux.git", "prefix/gorilla/mux"},
|
||||
{"https://oauth2:ACCESS_TOKEN@gerrit.example.com/gorilla/mux.git", "prefix/gorilla/mux"},
|
||||
|
||||
{"git@asdf.com:gorilla/mux.git", ""},
|
||||
{"https://asdf.com/gorilla/mux.git", ""},
|
||||
{"https://oauth2:ACCESS_TOKEN@asdf.com/gorilla/mux.git", ""},
|
||||
},
|
||||
}}
|
||||
|
||||
for _, test := range tests {
|
||||
for _, u := range test.urls {
|
||||
repoName, err := Gerrit{&test.conn}.CloneURLToRepoName(u.cloneURL)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if u.repoName != string(repoName) {
|
||||
t.Errorf("expected %q but got %q for clone URL %q (connection: %+v)", u.repoName, repoName, u.cloneURL, test.conn)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -9,6 +9,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/api"
|
||||
"github.com/sourcegraph/sourcegraph/internal/conf/reposource"
|
||||
"github.com/sourcegraph/sourcegraph/internal/extsvc"
|
||||
"github.com/sourcegraph/sourcegraph/internal/extsvc/auth"
|
||||
"github.com/sourcegraph/sourcegraph/internal/extsvc/gerrit"
|
||||
@ -32,7 +33,8 @@ type GerritSource struct {
|
||||
// by this source. This takes precedence over allowedProjects.
|
||||
disallowedProjects map[string]struct{}
|
||||
// If true, the connection is configured to use SSH instead of HTTPS.
|
||||
ssh bool
|
||||
ssh bool
|
||||
repositoryPathPattern string
|
||||
}
|
||||
|
||||
// NewGerritSource returns a new GerritSource from the given external service.
|
||||
@ -79,14 +81,15 @@ func NewGerritSource(ctx context.Context, svc *types.ExternalService, cf *httpcl
|
||||
}
|
||||
|
||||
return &GerritSource{
|
||||
svc: svc,
|
||||
cli: cli,
|
||||
allowedProjects: allowedProjects,
|
||||
disallowedProjects: disallowedProjects,
|
||||
serviceID: extsvc.NormalizeBaseURL(cli.GetURL()).String(),
|
||||
perPage: 100,
|
||||
private: c.Authorization != nil,
|
||||
ssh: c.GitURLType == "ssh",
|
||||
svc: svc,
|
||||
cli: cli,
|
||||
allowedProjects: allowedProjects,
|
||||
disallowedProjects: disallowedProjects,
|
||||
serviceID: extsvc.NormalizeBaseURL(cli.GetURL()).String(),
|
||||
perPage: 100,
|
||||
private: c.Authorization != nil,
|
||||
ssh: c.GitURLType == "ssh",
|
||||
repositoryPathPattern: c.RepositoryPathPattern,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -173,10 +176,17 @@ func (s *GerritSource) makeRepo(p *gerrit.Project, instanceHTTPURL *url.URL, ssh
|
||||
cloneURL = p.SSHURLToRepo
|
||||
}
|
||||
|
||||
name := path.Join(u.Host, decodedName)
|
||||
return &types.Repo{
|
||||
Name: api.RepoName(name),
|
||||
URI: name,
|
||||
Name: reposource.GerritRepoName(
|
||||
s.repositoryPathPattern,
|
||||
u.Host,
|
||||
decodedName,
|
||||
),
|
||||
URI: string(reposource.GerritRepoName(
|
||||
"",
|
||||
u.Host,
|
||||
decodedName,
|
||||
)),
|
||||
Description: p.Description,
|
||||
Fork: p.Parent != "",
|
||||
ExternalRepo: api.ExternalRepoSpec{
|
||||
|
||||
@ -143,4 +143,27 @@ func TestGerritSource_ListRepos(t *testing.T) {
|
||||
|
||||
assert.Empty(t, repos)
|
||||
})
|
||||
|
||||
t.Run("repositoryPathPattern", func(t *testing.T) {
|
||||
cf, save := NewClientFactory(t, t.Name())
|
||||
defer save(t)
|
||||
|
||||
svc := typestest.MakeExternalService(t, extsvc.VariantGerrit, &schema.GerritConnection{
|
||||
Url: "https://gerrit.sgdev.org",
|
||||
Username: os.Getenv("GERRIT_USERNAME"),
|
||||
Password: os.Getenv("GERRIT_PASSWORD"),
|
||||
RepositoryPathPattern: "prefix/{name}",
|
||||
})
|
||||
|
||||
ctx := context.Background()
|
||||
src, err := NewGerritSource(ctx, svc, cf)
|
||||
require.NoError(t, err)
|
||||
|
||||
src.perPage = 25
|
||||
|
||||
repos, err := ListAll(ctx, src)
|
||||
require.NoError(t, err)
|
||||
|
||||
testutil.AssertGolden(t, "testdata/sources/GERRIT/"+t.Name(), Update(t.Name()), repos)
|
||||
})
|
||||
}
|
||||
|
||||
376
internal/repos/testdata/sources/GERRIT/TestGerritSource_ListRepos/repositoryPathPattern
vendored
Normal file
376
internal/repos/testdata/sources/GERRIT/TestGerritSource_ListRepos/repositoryPathPattern
vendored
Normal file
@ -0,0 +1,376 @@
|
||||
[
|
||||
{
|
||||
"ID": 0,
|
||||
"Name": "prefix/a/gabe/repo",
|
||||
"URI": "gerrit.sgdev.org/a/gabe/repo",
|
||||
"Description": "",
|
||||
"Fork": false,
|
||||
"Archived": false,
|
||||
"Private": false,
|
||||
"CreatedAt": "0001-01-01T00:00:00Z",
|
||||
"UpdatedAt": "0001-01-01T00:00:00Z",
|
||||
"DeletedAt": "0001-01-01T00:00:00Z",
|
||||
"ExternalRepo": {
|
||||
"ID": "a%2Fgabe%2Frepo",
|
||||
"ServiceType": "gerrit",
|
||||
"ServiceID": "https://gerrit.sgdev.org/"
|
||||
},
|
||||
"Sources": {
|
||||
"extsvc:gerrit:0": {
|
||||
"ID": "extsvc:gerrit:0",
|
||||
"CloneURL": "https://gerrit.sgdev.org/a/a/gabe/repo"
|
||||
}
|
||||
},
|
||||
"Metadata": {
|
||||
"description": "",
|
||||
"id": "a%2Fgabe%2Frepo",
|
||||
"name": "",
|
||||
"parent": "",
|
||||
"state": "ACTIVE",
|
||||
"branches": null,
|
||||
"labels": null,
|
||||
"http_url_to_repo": "https://gerrit.sgdev.org/a/a/gabe/repo",
|
||||
"ssh_url_to_repo": "ssh://gerrit-ssh.sgdev.org:29418/a/gabe/repo"
|
||||
}
|
||||
},
|
||||
{
|
||||
"ID": 0,
|
||||
"Name": "prefix/batch-changes-test-repo",
|
||||
"URI": "gerrit.sgdev.org/batch-changes-test-repo",
|
||||
"Description": "",
|
||||
"Fork": false,
|
||||
"Archived": false,
|
||||
"Private": false,
|
||||
"CreatedAt": "0001-01-01T00:00:00Z",
|
||||
"UpdatedAt": "0001-01-01T00:00:00Z",
|
||||
"DeletedAt": "0001-01-01T00:00:00Z",
|
||||
"ExternalRepo": {
|
||||
"ID": "batch-changes-test-repo",
|
||||
"ServiceType": "gerrit",
|
||||
"ServiceID": "https://gerrit.sgdev.org/"
|
||||
},
|
||||
"Sources": {
|
||||
"extsvc:gerrit:0": {
|
||||
"ID": "extsvc:gerrit:0",
|
||||
"CloneURL": "https://gerrit.sgdev.org/a/batch-changes-test-repo"
|
||||
}
|
||||
},
|
||||
"Metadata": {
|
||||
"description": "",
|
||||
"id": "batch-changes-test-repo",
|
||||
"name": "",
|
||||
"parent": "",
|
||||
"state": "ACTIVE",
|
||||
"branches": null,
|
||||
"labels": null,
|
||||
"http_url_to_repo": "https://gerrit.sgdev.org/a/batch-changes-test-repo",
|
||||
"ssh_url_to_repo": "ssh://gerrit-ssh.sgdev.org:29418/batch-changes-test-repo"
|
||||
}
|
||||
},
|
||||
{
|
||||
"ID": 0,
|
||||
"Name": "prefix/beatrix",
|
||||
"URI": "gerrit.sgdev.org/beatrix",
|
||||
"Description": "",
|
||||
"Fork": false,
|
||||
"Archived": false,
|
||||
"Private": false,
|
||||
"CreatedAt": "0001-01-01T00:00:00Z",
|
||||
"UpdatedAt": "0001-01-01T00:00:00Z",
|
||||
"DeletedAt": "0001-01-01T00:00:00Z",
|
||||
"ExternalRepo": {
|
||||
"ID": "beatrix",
|
||||
"ServiceType": "gerrit",
|
||||
"ServiceID": "https://gerrit.sgdev.org/"
|
||||
},
|
||||
"Sources": {
|
||||
"extsvc:gerrit:0": {
|
||||
"ID": "extsvc:gerrit:0",
|
||||
"CloneURL": "https://gerrit.sgdev.org/a/beatrix"
|
||||
}
|
||||
},
|
||||
"Metadata": {
|
||||
"description": "",
|
||||
"id": "beatrix",
|
||||
"name": "",
|
||||
"parent": "",
|
||||
"state": "ACTIVE",
|
||||
"branches": null,
|
||||
"labels": null,
|
||||
"http_url_to_repo": "https://gerrit.sgdev.org/a/beatrix",
|
||||
"ssh_url_to_repo": "ssh://gerrit-ssh.sgdev.org:29418/beatrix"
|
||||
}
|
||||
},
|
||||
{
|
||||
"ID": 0,
|
||||
"Name": "prefix/cbart-test",
|
||||
"URI": "gerrit.sgdev.org/cbart-test",
|
||||
"Description": "",
|
||||
"Fork": false,
|
||||
"Archived": false,
|
||||
"Private": false,
|
||||
"CreatedAt": "0001-01-01T00:00:00Z",
|
||||
"UpdatedAt": "0001-01-01T00:00:00Z",
|
||||
"DeletedAt": "0001-01-01T00:00:00Z",
|
||||
"ExternalRepo": {
|
||||
"ID": "cbart-test",
|
||||
"ServiceType": "gerrit",
|
||||
"ServiceID": "https://gerrit.sgdev.org/"
|
||||
},
|
||||
"Sources": {
|
||||
"extsvc:gerrit:0": {
|
||||
"ID": "extsvc:gerrit:0",
|
||||
"CloneURL": "https://gerrit.sgdev.org/a/cbart-test"
|
||||
}
|
||||
},
|
||||
"Metadata": {
|
||||
"description": "",
|
||||
"id": "cbart-test",
|
||||
"name": "",
|
||||
"parent": "",
|
||||
"state": "ACTIVE",
|
||||
"branches": null,
|
||||
"labels": null,
|
||||
"http_url_to_repo": "https://gerrit.sgdev.org/a/cbart-test",
|
||||
"ssh_url_to_repo": "ssh://gerrit-ssh.sgdev.org:29418/cbart-test"
|
||||
}
|
||||
},
|
||||
{
|
||||
"ID": 0,
|
||||
"Name": "prefix/gabe",
|
||||
"URI": "gerrit.sgdev.org/gabe",
|
||||
"Description": "",
|
||||
"Fork": false,
|
||||
"Archived": false,
|
||||
"Private": false,
|
||||
"CreatedAt": "0001-01-01T00:00:00Z",
|
||||
"UpdatedAt": "0001-01-01T00:00:00Z",
|
||||
"DeletedAt": "0001-01-01T00:00:00Z",
|
||||
"ExternalRepo": {
|
||||
"ID": "gabe",
|
||||
"ServiceType": "gerrit",
|
||||
"ServiceID": "https://gerrit.sgdev.org/"
|
||||
},
|
||||
"Sources": {
|
||||
"extsvc:gerrit:0": {
|
||||
"ID": "extsvc:gerrit:0",
|
||||
"CloneURL": "https://gerrit.sgdev.org/a/gabe"
|
||||
}
|
||||
},
|
||||
"Metadata": {
|
||||
"description": "",
|
||||
"id": "gabe",
|
||||
"name": "",
|
||||
"parent": "",
|
||||
"state": "ACTIVE",
|
||||
"branches": null,
|
||||
"labels": null,
|
||||
"http_url_to_repo": "https://gerrit.sgdev.org/a/gabe",
|
||||
"ssh_url_to_repo": "ssh://gerrit-ssh.sgdev.org:29418/gabe"
|
||||
}
|
||||
},
|
||||
{
|
||||
"ID": 0,
|
||||
"Name": "prefix/gabe/test",
|
||||
"URI": "gerrit.sgdev.org/gabe/test",
|
||||
"Description": "",
|
||||
"Fork": false,
|
||||
"Archived": false,
|
||||
"Private": false,
|
||||
"CreatedAt": "0001-01-01T00:00:00Z",
|
||||
"UpdatedAt": "0001-01-01T00:00:00Z",
|
||||
"DeletedAt": "0001-01-01T00:00:00Z",
|
||||
"ExternalRepo": {
|
||||
"ID": "gabe%2Ftest",
|
||||
"ServiceType": "gerrit",
|
||||
"ServiceID": "https://gerrit.sgdev.org/"
|
||||
},
|
||||
"Sources": {
|
||||
"extsvc:gerrit:0": {
|
||||
"ID": "extsvc:gerrit:0",
|
||||
"CloneURL": "https://gerrit.sgdev.org/a/gabe/test"
|
||||
}
|
||||
},
|
||||
"Metadata": {
|
||||
"description": "",
|
||||
"id": "gabe%2Ftest",
|
||||
"name": "",
|
||||
"parent": "",
|
||||
"state": "ACTIVE",
|
||||
"branches": null,
|
||||
"labels": null,
|
||||
"http_url_to_repo": "https://gerrit.sgdev.org/a/gabe/test",
|
||||
"ssh_url_to_repo": "ssh://gerrit-ssh.sgdev.org:29418/gabe/test"
|
||||
}
|
||||
},
|
||||
{
|
||||
"ID": 0,
|
||||
"Name": "prefix/idan-temp",
|
||||
"URI": "gerrit.sgdev.org/idan-temp",
|
||||
"Description": "",
|
||||
"Fork": false,
|
||||
"Archived": false,
|
||||
"Private": false,
|
||||
"CreatedAt": "0001-01-01T00:00:00Z",
|
||||
"UpdatedAt": "0001-01-01T00:00:00Z",
|
||||
"DeletedAt": "0001-01-01T00:00:00Z",
|
||||
"ExternalRepo": {
|
||||
"ID": "idan-temp",
|
||||
"ServiceType": "gerrit",
|
||||
"ServiceID": "https://gerrit.sgdev.org/"
|
||||
},
|
||||
"Sources": {
|
||||
"extsvc:gerrit:0": {
|
||||
"ID": "extsvc:gerrit:0",
|
||||
"CloneURL": "https://gerrit.sgdev.org/a/idan-temp"
|
||||
}
|
||||
},
|
||||
"Metadata": {
|
||||
"description": "",
|
||||
"id": "idan-temp",
|
||||
"name": "",
|
||||
"parent": "",
|
||||
"state": "ACTIVE",
|
||||
"branches": null,
|
||||
"labels": null,
|
||||
"http_url_to_repo": "https://gerrit.sgdev.org/a/idan-temp",
|
||||
"ssh_url_to_repo": "ssh://gerrit-ssh.sgdev.org:29418/idan-temp"
|
||||
}
|
||||
},
|
||||
{
|
||||
"ID": 0,
|
||||
"Name": "prefix/k8s-gerrit",
|
||||
"URI": "gerrit.sgdev.org/k8s-gerrit",
|
||||
"Description": "",
|
||||
"Fork": false,
|
||||
"Archived": false,
|
||||
"Private": false,
|
||||
"CreatedAt": "0001-01-01T00:00:00Z",
|
||||
"UpdatedAt": "0001-01-01T00:00:00Z",
|
||||
"DeletedAt": "0001-01-01T00:00:00Z",
|
||||
"ExternalRepo": {
|
||||
"ID": "k8s-gerrit",
|
||||
"ServiceType": "gerrit",
|
||||
"ServiceID": "https://gerrit.sgdev.org/"
|
||||
},
|
||||
"Sources": {
|
||||
"extsvc:gerrit:0": {
|
||||
"ID": "extsvc:gerrit:0",
|
||||
"CloneURL": "https://gerrit.sgdev.org/a/k8s-gerrit"
|
||||
}
|
||||
},
|
||||
"Metadata": {
|
||||
"description": "",
|
||||
"id": "k8s-gerrit",
|
||||
"name": "",
|
||||
"parent": "",
|
||||
"state": "ACTIVE",
|
||||
"branches": null,
|
||||
"labels": null,
|
||||
"http_url_to_repo": "https://gerrit.sgdev.org/a/k8s-gerrit",
|
||||
"ssh_url_to_repo": "ssh://gerrit-ssh.sgdev.org:29418/k8s-gerrit"
|
||||
}
|
||||
},
|
||||
{
|
||||
"ID": 0,
|
||||
"Name": "prefix/sourcegraph",
|
||||
"URI": "gerrit.sgdev.org/sourcegraph",
|
||||
"Description": "",
|
||||
"Fork": false,
|
||||
"Archived": false,
|
||||
"Private": false,
|
||||
"CreatedAt": "0001-01-01T00:00:00Z",
|
||||
"UpdatedAt": "0001-01-01T00:00:00Z",
|
||||
"DeletedAt": "0001-01-01T00:00:00Z",
|
||||
"ExternalRepo": {
|
||||
"ID": "sourcegraph",
|
||||
"ServiceType": "gerrit",
|
||||
"ServiceID": "https://gerrit.sgdev.org/"
|
||||
},
|
||||
"Sources": {
|
||||
"extsvc:gerrit:0": {
|
||||
"ID": "extsvc:gerrit:0",
|
||||
"CloneURL": "https://gerrit.sgdev.org/a/sourcegraph"
|
||||
}
|
||||
},
|
||||
"Metadata": {
|
||||
"description": "",
|
||||
"id": "sourcegraph",
|
||||
"name": "",
|
||||
"parent": "",
|
||||
"state": "ACTIVE",
|
||||
"branches": null,
|
||||
"labels": null,
|
||||
"http_url_to_repo": "https://gerrit.sgdev.org/a/sourcegraph",
|
||||
"ssh_url_to_repo": "ssh://gerrit-ssh.sgdev.org:29418/sourcegraph"
|
||||
}
|
||||
},
|
||||
{
|
||||
"ID": 0,
|
||||
"Name": "prefix/sourcegraph/create",
|
||||
"URI": "gerrit.sgdev.org/sourcegraph/create",
|
||||
"Description": "",
|
||||
"Fork": false,
|
||||
"Archived": false,
|
||||
"Private": false,
|
||||
"CreatedAt": "0001-01-01T00:00:00Z",
|
||||
"UpdatedAt": "0001-01-01T00:00:00Z",
|
||||
"DeletedAt": "0001-01-01T00:00:00Z",
|
||||
"ExternalRepo": {
|
||||
"ID": "sourcegraph%2Fcreate",
|
||||
"ServiceType": "gerrit",
|
||||
"ServiceID": "https://gerrit.sgdev.org/"
|
||||
},
|
||||
"Sources": {
|
||||
"extsvc:gerrit:0": {
|
||||
"ID": "extsvc:gerrit:0",
|
||||
"CloneURL": "https://gerrit.sgdev.org/a/sourcegraph/create"
|
||||
}
|
||||
},
|
||||
"Metadata": {
|
||||
"description": "",
|
||||
"id": "sourcegraph%2Fcreate",
|
||||
"name": "",
|
||||
"parent": "",
|
||||
"state": "ACTIVE",
|
||||
"branches": null,
|
||||
"labels": null,
|
||||
"http_url_to_repo": "https://gerrit.sgdev.org/a/sourcegraph/create",
|
||||
"ssh_url_to_repo": "ssh://gerrit-ssh.sgdev.org:29418/sourcegraph/create"
|
||||
}
|
||||
},
|
||||
{
|
||||
"ID": 0,
|
||||
"Name": "prefix/src-cli",
|
||||
"URI": "gerrit.sgdev.org/src-cli",
|
||||
"Description": "",
|
||||
"Fork": false,
|
||||
"Archived": false,
|
||||
"Private": false,
|
||||
"CreatedAt": "0001-01-01T00:00:00Z",
|
||||
"UpdatedAt": "0001-01-01T00:00:00Z",
|
||||
"DeletedAt": "0001-01-01T00:00:00Z",
|
||||
"ExternalRepo": {
|
||||
"ID": "src-cli",
|
||||
"ServiceType": "gerrit",
|
||||
"ServiceID": "https://gerrit.sgdev.org/"
|
||||
},
|
||||
"Sources": {
|
||||
"extsvc:gerrit:0": {
|
||||
"ID": "extsvc:gerrit:0",
|
||||
"CloneURL": "https://gerrit.sgdev.org/a/src-cli"
|
||||
}
|
||||
},
|
||||
"Metadata": {
|
||||
"description": "",
|
||||
"id": "src-cli",
|
||||
"name": "",
|
||||
"parent": "",
|
||||
"state": "ACTIVE",
|
||||
"branches": null,
|
||||
"labels": null,
|
||||
"http_url_to_repo": "https://gerrit.sgdev.org/a/src-cli",
|
||||
"ssh_url_to_repo": "ssh://gerrit-ssh.sgdev.org:29418/src-cli"
|
||||
}
|
||||
}
|
||||
]
|
||||
155
internal/repos/testdata/sources/TestGerritSource_ListRepos/repositoryPathPattern.yaml
vendored
Normal file
155
internal/repos/testdata/sources/TestGerritSource_ListRepos/repositoryPathPattern.yaml
vendored
Normal file
@ -0,0 +1,155 @@
|
||||
---
|
||||
version: 1
|
||||
interactions:
|
||||
- request:
|
||||
body: ""
|
||||
form: {}
|
||||
headers: {}
|
||||
url: https://gerrit.sgdev.org/ssh_info
|
||||
method: GET
|
||||
response:
|
||||
body: gerrit-ssh.sgdev.org 29418
|
||||
headers:
|
||||
Cache-Control:
|
||||
- no-cache, no-store, max-age=0, must-revalidate
|
||||
Cf-Cache-Status:
|
||||
- DYNAMIC
|
||||
Cf-Ray:
|
||||
- 8a9436e1dcd9bbba-WAW
|
||||
Content-Length:
|
||||
- "26"
|
||||
Content-Type:
|
||||
- text/plain;charset=utf-8
|
||||
Date:
|
||||
- Fri, 26 Jul 2024 11:57:49 GMT
|
||||
Expires:
|
||||
- Mon, 01 Jan 1990 00:00:00 GMT
|
||||
Pragma:
|
||||
- no-cache
|
||||
Server:
|
||||
- cloudflare
|
||||
Strict-Transport-Security:
|
||||
- max-age=15724800; includeSubDomains
|
||||
X-Frame-Options:
|
||||
- DENY
|
||||
status: 200 OK
|
||||
code: 200
|
||||
duration: ""
|
||||
- request:
|
||||
body: ""
|
||||
form: {}
|
||||
headers: {}
|
||||
url: https://gerrit.sgdev.org/a/projects/?S=0&n=25&type=CODE
|
||||
method: GET
|
||||
response:
|
||||
body: |
|
||||
)]}'
|
||||
{"a/gabe/repo":{"id":"a%2Fgabe%2Frepo","state":"ACTIVE"},"batch-changes-test-repo":{"id":"batch-changes-test-repo","state":"ACTIVE"},"beatrix":{"id":"beatrix","state":"ACTIVE"},"cbart-test":{"id":"cbart-test","state":"ACTIVE"},"gabe":{"id":"gabe","state":"ACTIVE"},"gabe/test":{"id":"gabe%2Ftest","state":"ACTIVE"},"idan-temp":{"id":"idan-temp","state":"ACTIVE"},"k8s-gerrit":{"id":"k8s-gerrit","state":"ACTIVE"},"sourcegraph":{"id":"sourcegraph","state":"ACTIVE"},"sourcegraph/create":{"id":"sourcegraph%2Fcreate","state":"ACTIVE"},"src-cli":{"id":"src-cli","state":"ACTIVE"}}
|
||||
headers:
|
||||
Cache-Control:
|
||||
- no-cache, no-store, max-age=0, must-revalidate
|
||||
Cf-Cache-Status:
|
||||
- DYNAMIC
|
||||
Cf-Ray:
|
||||
- 8a9436e2fe4ebbba-WAW
|
||||
Content-Disposition:
|
||||
- attachment
|
||||
Content-Type:
|
||||
- application/json;charset=utf-8
|
||||
Date:
|
||||
- Fri, 26 Jul 2024 11:57:50 GMT
|
||||
Expires:
|
||||
- Mon, 01 Jan 1990 00:00:00 GMT
|
||||
Pragma:
|
||||
- no-cache
|
||||
Server:
|
||||
- cloudflare
|
||||
Strict-Transport-Security:
|
||||
- max-age=15724800; includeSubDomains
|
||||
X-Content-Type-Options:
|
||||
- nosniff
|
||||
X-Frame-Options:
|
||||
- DENY
|
||||
status: 200 OK
|
||||
code: 200
|
||||
duration: ""
|
||||
- request:
|
||||
body: ""
|
||||
form: {}
|
||||
headers: {}
|
||||
url: https://gerrit.sgdev.org/a/projects/?S=25&n=25&type=CODE
|
||||
method: GET
|
||||
response:
|
||||
body: |
|
||||
)]}'
|
||||
{}
|
||||
headers:
|
||||
Cache-Control:
|
||||
- no-cache, no-store, max-age=0, must-revalidate
|
||||
Cf-Cache-Status:
|
||||
- DYNAMIC
|
||||
Cf-Ray:
|
||||
- 8a9436e43836bbba-WAW
|
||||
Content-Disposition:
|
||||
- attachment
|
||||
Content-Length:
|
||||
- "8"
|
||||
Content-Type:
|
||||
- application/json;charset=utf-8
|
||||
Date:
|
||||
- Fri, 26 Jul 2024 11:57:50 GMT
|
||||
Expires:
|
||||
- Mon, 01 Jan 1990 00:00:00 GMT
|
||||
Pragma:
|
||||
- no-cache
|
||||
Server:
|
||||
- cloudflare
|
||||
Strict-Transport-Security:
|
||||
- max-age=15724800; includeSubDomains
|
||||
X-Content-Type-Options:
|
||||
- nosniff
|
||||
X-Frame-Options:
|
||||
- DENY
|
||||
status: 200 OK
|
||||
code: 200
|
||||
duration: ""
|
||||
- request:
|
||||
body: ""
|
||||
form: {}
|
||||
headers: {}
|
||||
url: https://gerrit.sgdev.org/a/projects/?S=50&n=1
|
||||
method: GET
|
||||
response:
|
||||
body: |
|
||||
)]}'
|
||||
{}
|
||||
headers:
|
||||
Cache-Control:
|
||||
- no-cache, no-store, max-age=0, must-revalidate
|
||||
Cf-Cache-Status:
|
||||
- DYNAMIC
|
||||
Cf-Ray:
|
||||
- 8a9436e589e9bbba-WAW
|
||||
Content-Disposition:
|
||||
- attachment
|
||||
Content-Length:
|
||||
- "8"
|
||||
Content-Type:
|
||||
- application/json;charset=utf-8
|
||||
Date:
|
||||
- Fri, 26 Jul 2024 11:57:50 GMT
|
||||
Expires:
|
||||
- Mon, 01 Jan 1990 00:00:00 GMT
|
||||
Pragma:
|
||||
- no-cache
|
||||
Server:
|
||||
- cloudflare
|
||||
Strict-Transport-Security:
|
||||
- max-age=15724800; includeSubDomains
|
||||
X-Content-Type-Options:
|
||||
- nosniff
|
||||
X-Frame-Options:
|
||||
- DENY
|
||||
status: 200 OK
|
||||
code: 200
|
||||
duration: ""
|
||||
@ -62,6 +62,11 @@
|
||||
},
|
||||
"examples": [[{ "name": "docs" }, { "name": "php/php-src" }]]
|
||||
},
|
||||
"repositoryPathPattern": {
|
||||
"description": "The pattern used to generate the corresponding Sourcegraph repository name for a Gerrit repository. In the pattern, the variable \"{host}\" is replaced with the Gerrit host (such as gerrit.example.com), and \"{name}\" is replaced with the Gerrit repository's name (such as \"myrepo\").\n\nFor example, if your Gerrit URL is https://gerrit.example.com and your Sourcegraph URL is https://src.example.com, then a repositoryPathPattern of \"{host}/{name}\" would mean that a Gerrit repository at https://gerrit.example.com/myrepo is available on Sourcegraph at https://src.example.com/gerrit.example.com/myrepo.\n\nIt is important that the Sourcegraph repository name generated with this pattern be unique to this code host. If different code hosts generate repository names that collide, Sourcegraph's behavior is undefined.",
|
||||
"type": "string",
|
||||
"default": "{host}/{name}"
|
||||
},
|
||||
"authorization": {
|
||||
"title": "GerritAuthorization",
|
||||
"description": "If non-null, enforces Gerrit repository permissions. This requires that there is an item in the [site configuration json](https://sourcegraph.com/docs/admin/config/site_config#auth-providers) `auth.providers` field, of type \"gerrit\" with the same `url` field as specified in this `GerritConnection`.",
|
||||
|
||||
@ -1358,6 +1358,12 @@ type GerritConnection struct {
|
||||
Password string `json:"password"`
|
||||
// Projects description: An array of project strings specifying which Gerrit projects to mirror on Sourcegraph. If empty, all projects will be mirrored.
|
||||
Projects []string `json:"projects,omitempty"`
|
||||
// RepositoryPathPattern description: The pattern used to generate the corresponding Sourcegraph repository name for a Gerrit repository. In the pattern, the variable "{host}" is replaced with the Gerrit host (such as gerrit.example.com), and "{name}" is replaced with the Gerrit repository's name (such as "myrepo").
|
||||
//
|
||||
// For example, if your Gerrit URL is https://gerrit.example.com and your Sourcegraph URL is https://src.example.com, then a repositoryPathPattern of "{host}/{name}" would mean that a Gerrit repository at https://gerrit.example.com/myrepo is available on Sourcegraph at https://src.example.com/gerrit.example.com/myrepo.
|
||||
//
|
||||
// It is important that the Sourcegraph repository name generated with this pattern be unique to this code host. If different code hosts generate repository names that collide, Sourcegraph's behavior is undefined.
|
||||
RepositoryPathPattern string `json:"repositoryPathPattern,omitempty"`
|
||||
// Url description: URL of a Gerrit instance, such as https://gerrit.example.com.
|
||||
Url string `json:"url"`
|
||||
// Username description: A username for authentication with the Gerrit code host.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user