mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-01-10 23:52:16 +01:00
sourcehut: use ssh sources URL when appropriate
Co-authored-by: Jordan Anderson <jordan@jba.io>
This commit is contained in:
parent
6e13ac4d5f
commit
3bea06f906
2 changed files with 59 additions and 3 deletions
|
@ -289,16 +289,21 @@ func adjustManifest(repo *api.Repository, commitID, gitRef string, r io.Reader,
|
||||||
manifest.Environment["BUILD_SUBMITTER_URL"] = setting.AppURL
|
manifest.Environment["BUILD_SUBMITTER_URL"] = setting.AppURL
|
||||||
manifest.Environment["GIT_REF"] = gitRef
|
manifest.Environment["GIT_REF"] = gitRef
|
||||||
|
|
||||||
source := repo.CloneURL + "#" + commitID
|
|
||||||
found := false
|
found := false
|
||||||
for i, s := range manifest.Sources {
|
for i, s := range manifest.Sources {
|
||||||
if s == repo.CloneURL {
|
if s == repo.CloneURL || s == repo.SSHURL {
|
||||||
manifest.Sources[i] = source
|
manifest.Sources[i] = s + "#" + commitID
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !found {
|
if !found {
|
||||||
|
source := repo.CloneURL
|
||||||
|
if repo.Private || setting.Repository.DisableHTTPGit {
|
||||||
|
// default to ssh for private repos or when git clone is disabled over http
|
||||||
|
source = repo.SSHURL
|
||||||
|
}
|
||||||
|
source += "#" + commitID
|
||||||
manifest.Sources = append(manifest.Sources, source)
|
manifest.Sources = append(manifest.Sources, source)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -460,6 +460,57 @@ environment:
|
||||||
BUILD_SUBMITTER_URL: https://example.forgejo.org/
|
BUILD_SUBMITTER_URL: https://example.forgejo.org/
|
||||||
GIT_REF: refs/heads/main
|
GIT_REF: refs/heads/main
|
||||||
image: alpine/edge
|
image: alpine/edge
|
||||||
|
tasks:
|
||||||
|
- hello: echo world
|
||||||
|
`, string(manifest))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("with ssh source", func(t *testing.T) {
|
||||||
|
repo := &api.Repository{
|
||||||
|
CloneURL: "http://localhost:3000/testdata/repo.git",
|
||||||
|
SSHURL: "git@localhost:testdata/repo.git",
|
||||||
|
}
|
||||||
|
|
||||||
|
manifest, err := adjustManifest(repo, "58771003157b81abc6bf41df0c5db4147a3e3c83", "refs/heads/main", strings.NewReader(`image: alpine/edge
|
||||||
|
sources:
|
||||||
|
- git@localhost:testdata/repo.git
|
||||||
|
- http://other.example.conm/repo.git
|
||||||
|
tasks:
|
||||||
|
- hello: echo world`), ".build.yml")
|
||||||
|
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, `sources:
|
||||||
|
- git@localhost:testdata/repo.git#58771003157b81abc6bf41df0c5db4147a3e3c83
|
||||||
|
- http://other.example.conm/repo.git
|
||||||
|
environment:
|
||||||
|
BUILD_SUBMITTER: forgejo
|
||||||
|
BUILD_SUBMITTER_URL: https://example.forgejo.org/
|
||||||
|
GIT_REF: refs/heads/main
|
||||||
|
image: alpine/edge
|
||||||
|
tasks:
|
||||||
|
- hello: echo world
|
||||||
|
`, string(manifest))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("private without source", func(t *testing.T) {
|
||||||
|
repo := &api.Repository{
|
||||||
|
CloneURL: "http://localhost:3000/testdata/repo.git",
|
||||||
|
SSHURL: "git@localhost:testdata/repo.git",
|
||||||
|
Private: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
manifest, err := adjustManifest(repo, "58771003157b81abc6bf41df0c5db4147a3e3c83", "refs/heads/main", strings.NewReader(`image: alpine/edge
|
||||||
|
tasks:
|
||||||
|
- hello: echo world`), ".build.yml")
|
||||||
|
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, `sources:
|
||||||
|
- git@localhost:testdata/repo.git#58771003157b81abc6bf41df0c5db4147a3e3c83
|
||||||
|
environment:
|
||||||
|
BUILD_SUBMITTER: forgejo
|
||||||
|
BUILD_SUBMITTER_URL: https://example.forgejo.org/
|
||||||
|
GIT_REF: refs/heads/main
|
||||||
|
image: alpine/edge
|
||||||
tasks:
|
tasks:
|
||||||
- hello: echo world
|
- hello: echo world
|
||||||
`, string(manifest))
|
`, string(manifest))
|
||||||
|
|
Loading…
Reference in a new issue