mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-27 13:39:19 -05:00
refactor: sourcehut_builds ignore unused fields
(cherry picked from commit 1f6f909b2e
)
This commit is contained in:
parent
287253ff7d
commit
1c99c289f6
2 changed files with 45 additions and 46 deletions
|
@ -269,19 +269,13 @@ func (pc sourcehutConvertor) buildManifest(repo *api.Repository, commitID, gitRe
|
||||||
return []byte(msg), fmt.Errorf(msg+": %w", err)
|
return []byte(msg), fmt.Errorf(msg+": %w", err)
|
||||||
}
|
}
|
||||||
defer r.Close()
|
defer r.Close()
|
||||||
|
|
||||||
|
// reference: https://man.sr.ht/builds.sr.ht/manifest.md
|
||||||
var manifest struct {
|
var manifest struct {
|
||||||
Image yaml.Node `yaml:"image"`
|
|
||||||
Arch yaml.Node `yaml:"arch,omitempty"`
|
|
||||||
Packages yaml.Node `yaml:"packages,omitempty"`
|
|
||||||
Repositories yaml.Node `yaml:"repositories,omitempty"`
|
|
||||||
Artifacts yaml.Node `yaml:"artifacts,omitempty"`
|
|
||||||
Shell yaml.Node `yaml:"shell,omitempty"`
|
|
||||||
Sources []string `yaml:"sources"`
|
Sources []string `yaml:"sources"`
|
||||||
Tasks yaml.Node `yaml:"tasks"`
|
|
||||||
Triggers yaml.Node `yaml:"triggers,omitempty"`
|
|
||||||
Environment map[string]string `yaml:"environment"`
|
Environment map[string]string `yaml:"environment"`
|
||||||
Secrets yaml.Node `yaml:"secrets,omitempty"`
|
|
||||||
Oauth yaml.Node `yaml:"oauth,omitempty"`
|
Rest map[string]yaml.Node `yaml:",inline"`
|
||||||
}
|
}
|
||||||
if err := yaml.NewDecoder(r).Decode(&manifest); err != nil {
|
if err := yaml.NewDecoder(r).Decode(&manifest); err != nil {
|
||||||
msg := fmt.Sprintf("could not decode manifest %q", pc.meta.ManifestPath)
|
msg := fmt.Sprintf("could not decode manifest %q", pc.meta.ManifestPath)
|
||||||
|
|
|
@ -69,19 +69,21 @@ func TestSourcehutBuildsPayload(t *testing.T) {
|
||||||
pc.meta.ManifestPath = "simple.yml"
|
pc.meta.ManifestPath = "simple.yml"
|
||||||
pl, err := pc.Create(p)
|
pl, err := pc.Create(p)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, buildsVariables{
|
|
||||||
Manifest: `image: alpine/edge
|
assert.Equal(t, `sources:
|
||||||
sources:
|
|
||||||
- http://localhost:3000/testdata/repo.git#58771003157b81abc6bf41df0c5db4147a3e3c83
|
- http://localhost:3000/testdata/repo.git#58771003157b81abc6bf41df0c5db4147a3e3c83
|
||||||
tasks:
|
|
||||||
- say-hello: |
|
|
||||||
echo hello
|
|
||||||
- say-world: echo world
|
|
||||||
environment:
|
environment:
|
||||||
BUILD_SUBMITTER: forgejo
|
BUILD_SUBMITTER: forgejo
|
||||||
BUILD_SUBMITTER_URL: https://example.forgejo.org/
|
BUILD_SUBMITTER_URL: https://example.forgejo.org/
|
||||||
GIT_REF: refs/heads/test
|
GIT_REF: refs/heads/test
|
||||||
`,
|
image: alpine/edge
|
||||||
|
tasks:
|
||||||
|
- say-hello: |
|
||||||
|
echo hello
|
||||||
|
- say-world: echo world
|
||||||
|
`, pl.Variables.Manifest)
|
||||||
|
assert.Equal(t, buildsVariables{
|
||||||
|
Manifest: pl.Variables.Manifest, // the manifest correctness is checked above, for nicer diff on error
|
||||||
Note: "branch test created",
|
Note: "branch test created",
|
||||||
Tags: []string{"testdata/repo", "branch/test", "simple.yml"},
|
Tags: []string{"testdata/repo", "branch/test", "simple.yml"},
|
||||||
Secrets: true,
|
Secrets: true,
|
||||||
|
@ -100,19 +102,21 @@ environment:
|
||||||
pc.meta.ManifestPath = "simple.yml"
|
pc.meta.ManifestPath = "simple.yml"
|
||||||
pl, err := pc.Create(p)
|
pl, err := pc.Create(p)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, buildsVariables{
|
|
||||||
Manifest: `image: alpine/edge
|
assert.Equal(t, `sources:
|
||||||
sources:
|
|
||||||
- http://localhost:3000/testdata/repo.git#58771003157b81abc6bf41df0c5db4147a3e3c83
|
- http://localhost:3000/testdata/repo.git#58771003157b81abc6bf41df0c5db4147a3e3c83
|
||||||
tasks:
|
|
||||||
- say-hello: |
|
|
||||||
echo hello
|
|
||||||
- say-world: echo world
|
|
||||||
environment:
|
environment:
|
||||||
BUILD_SUBMITTER: forgejo
|
BUILD_SUBMITTER: forgejo
|
||||||
BUILD_SUBMITTER_URL: https://example.forgejo.org/
|
BUILD_SUBMITTER_URL: https://example.forgejo.org/
|
||||||
GIT_REF: refs/tags/v1.0.0
|
GIT_REF: refs/tags/v1.0.0
|
||||||
`,
|
image: alpine/edge
|
||||||
|
tasks:
|
||||||
|
- say-hello: |
|
||||||
|
echo hello
|
||||||
|
- say-world: echo world
|
||||||
|
`, pl.Variables.Manifest)
|
||||||
|
assert.Equal(t, buildsVariables{
|
||||||
|
Manifest: pl.Variables.Manifest, // the manifest correctness is checked above, for nicer diff on error
|
||||||
Note: "tag v1.0.0 created",
|
Note: "tag v1.0.0 created",
|
||||||
Tags: []string{"testdata/repo", "tag/v1.0.0", "simple.yml"},
|
Tags: []string{"testdata/repo", "tag/v1.0.0", "simple.yml"},
|
||||||
Secrets: true,
|
Secrets: true,
|
||||||
|
@ -151,19 +155,20 @@ environment:
|
||||||
pl, err := pc.Push(p)
|
pl, err := pc.Push(p)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, buildsVariables{
|
assert.Equal(t, `sources:
|
||||||
Manifest: `image: alpine/edge
|
|
||||||
sources:
|
|
||||||
- http://localhost:3000/testdata/repo.git#58771003157b81abc6bf41df0c5db4147a3e3c83
|
- http://localhost:3000/testdata/repo.git#58771003157b81abc6bf41df0c5db4147a3e3c83
|
||||||
tasks:
|
|
||||||
- say-hello: |
|
|
||||||
echo hello
|
|
||||||
- say-world: echo world
|
|
||||||
environment:
|
environment:
|
||||||
BUILD_SUBMITTER: forgejo
|
BUILD_SUBMITTER: forgejo
|
||||||
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
|
||||||
|
tasks:
|
||||||
|
- say-hello: |
|
||||||
|
echo hello
|
||||||
|
- say-world: echo world
|
||||||
|
`, pl.Variables.Manifest)
|
||||||
|
assert.Equal(t, buildsVariables{
|
||||||
|
Manifest: pl.Variables.Manifest, // the manifest correctness is checked above, for nicer diff on error
|
||||||
Note: "add simple",
|
Note: "add simple",
|
||||||
Tags: []string{"testdata/repo", "branch/main", "simple.yml"},
|
Tags: []string{"testdata/repo", "branch/main", "simple.yml"},
|
||||||
Secrets: true,
|
Secrets: true,
|
||||||
|
@ -187,13 +192,20 @@ environment:
|
||||||
pl, err := pc.Push(p)
|
pl, err := pc.Push(p)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, `image: archlinux
|
assert.Equal(t, `sources:
|
||||||
|
- http://localhost:3000/testdata/repo.git#b0404943256a1f5a50c3726f4378756b4c1e5704
|
||||||
|
environment:
|
||||||
|
BUILD_SUBMITTER: forgejo
|
||||||
|
BUILD_SUBMITTER_URL: https://example.forgejo.org/
|
||||||
|
GIT_REF: refs/heads/main
|
||||||
|
deploy: synapse@synapse-bt.org
|
||||||
|
image: archlinux
|
||||||
packages:
|
packages:
|
||||||
- nodejs
|
- nodejs
|
||||||
- npm
|
- npm
|
||||||
- rsync
|
- rsync
|
||||||
sources:
|
secrets:
|
||||||
- http://localhost:3000/testdata/repo.git#b0404943256a1f5a50c3726f4378756b4c1e5704
|
- 7ebab768-e5e4-4c9d-ba57-ec41a72c5665
|
||||||
tasks: []
|
tasks: []
|
||||||
triggers:
|
triggers:
|
||||||
- condition: failure
|
- condition: failure
|
||||||
|
@ -203,13 +215,6 @@ triggers:
|
||||||
- condition: always
|
- condition: always
|
||||||
action: webhook
|
action: webhook
|
||||||
url: https://hook.example.org
|
url: https://hook.example.org
|
||||||
environment:
|
|
||||||
BUILD_SUBMITTER: forgejo
|
|
||||||
BUILD_SUBMITTER_URL: https://example.forgejo.org/
|
|
||||||
GIT_REF: refs/heads/main
|
|
||||||
deploy: synapse@synapse-bt.org
|
|
||||||
secrets:
|
|
||||||
- 7ebab768-e5e4-4c9d-ba57-ec41a72c5665
|
|
||||||
`, pl.Variables.Manifest)
|
`, pl.Variables.Manifest)
|
||||||
assert.Equal(t, buildsVariables{
|
assert.Equal(t, buildsVariables{
|
||||||
Manifest: pl.Variables.Manifest, // the manifest correctness is checked above, for nicer diff on error
|
Manifest: pl.Variables.Manifest, // the manifest correctness is checked above, for nicer diff on error
|
||||||
|
|
Loading…
Reference in a new issue