mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-22 23:33:15 -05:00
Merge pull request '[v7.0/forgejo] [BUG] Fix SourceHut Builds webhook with triggers field' (#3881) from bp-v7.0/forgejo-0e479f3-1f6f909-c9f38e2-7b47cb4 into v7.0/forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3881 Reviewed-by: oliverpool <oliverpool@noreply.codeberg.org>
This commit is contained in:
commit
09b08bcf7c
13 changed files with 61 additions and 50 deletions
1
release-notes/8.0.0/fix/3864.md
Normal file
1
release-notes/8.0.0/fix/3864.md
Normal file
|
@ -0,0 +1 @@
|
|||
SourceHut Builds webhook would fail when the `triggers` field was used.
|
|
@ -269,19 +269,13 @@ func (pc sourcehutConvertor) buildManifest(repo *api.Repository, commitID, gitRe
|
|||
return []byte(msg), fmt.Errorf(msg+": %w", err)
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
// reference: https://man.sr.ht/builds.sr.ht/manifest.md
|
||||
var manifest struct {
|
||||
Image string `yaml:"image"`
|
||||
Arch string `yaml:"arch,omitempty"`
|
||||
Packages []string `yaml:"packages,omitempty"`
|
||||
Repositories map[string]string `yaml:"repositories,omitempty"`
|
||||
Artifacts []string `yaml:"artifacts,omitempty"`
|
||||
Shell bool `yaml:"shell,omitempty"`
|
||||
Sources []string `yaml:"sources"`
|
||||
Tasks []map[string]string `yaml:"tasks"`
|
||||
Triggers []string `yaml:"triggers,omitempty"`
|
||||
Environment map[string]string `yaml:"environment"`
|
||||
Secrets []string `yaml:"secrets,omitempty"`
|
||||
Oauth string `yaml:"oauth,omitempty"`
|
||||
Sources []string `yaml:"sources"`
|
||||
Environment map[string]string `yaml:"environment"`
|
||||
|
||||
Rest map[string]yaml.Node `yaml:",inline"`
|
||||
}
|
||||
if err := yaml.NewDecoder(r).Decode(&manifest); err != nil {
|
||||
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"
|
||||
pl, err := pc.Create(p)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, buildsVariables{
|
||||
Manifest: `image: alpine/edge
|
||||
sources:
|
||||
|
||||
assert.Equal(t, `sources:
|
||||
- http://localhost:3000/testdata/repo.git#58771003157b81abc6bf41df0c5db4147a3e3c83
|
||||
tasks:
|
||||
- say-hello: |
|
||||
echo hello
|
||||
- say-world: echo world
|
||||
environment:
|
||||
BUILD_SUBMITTER: forgejo
|
||||
BUILD_SUBMITTER_URL: https://example.forgejo.org/
|
||||
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",
|
||||
Tags: []string{"testdata/repo", "branch/test", "simple.yml"},
|
||||
Secrets: true,
|
||||
|
@ -100,19 +102,21 @@ environment:
|
|||
pc.meta.ManifestPath = "simple.yml"
|
||||
pl, err := pc.Create(p)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, buildsVariables{
|
||||
Manifest: `image: alpine/edge
|
||||
sources:
|
||||
|
||||
assert.Equal(t, `sources:
|
||||
- http://localhost:3000/testdata/repo.git#58771003157b81abc6bf41df0c5db4147a3e3c83
|
||||
tasks:
|
||||
- say-hello: |
|
||||
echo hello
|
||||
- say-world: echo world
|
||||
environment:
|
||||
BUILD_SUBMITTER: forgejo
|
||||
BUILD_SUBMITTER_URL: https://example.forgejo.org/
|
||||
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",
|
||||
Tags: []string{"testdata/repo", "tag/v1.0.0", "simple.yml"},
|
||||
Secrets: true,
|
||||
|
@ -151,19 +155,20 @@ environment:
|
|||
pl, err := pc.Push(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, buildsVariables{
|
||||
Manifest: `image: alpine/edge
|
||||
sources:
|
||||
assert.Equal(t, `sources:
|
||||
- http://localhost:3000/testdata/repo.git#58771003157b81abc6bf41df0c5db4147a3e3c83
|
||||
tasks:
|
||||
- say-hello: |
|
||||
echo hello
|
||||
- say-world: echo world
|
||||
environment:
|
||||
BUILD_SUBMITTER: forgejo
|
||||
BUILD_SUBMITTER_URL: https://example.forgejo.org/
|
||||
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",
|
||||
Tags: []string{"testdata/repo", "branch/main", "simple.yml"},
|
||||
Secrets: true,
|
||||
|
@ -175,7 +180,7 @@ environment:
|
|||
p := &api.PushPayload{
|
||||
Ref: "refs/heads/main",
|
||||
HeadCommit: &api.PayloadCommit{
|
||||
ID: "69b217caa89166a02b8cd368b64fb83a44720e14",
|
||||
ID: "b0404943256a1f5a50c3726f4378756b4c1e5704",
|
||||
Message: "replace simple with complex",
|
||||
},
|
||||
Repo: repo,
|
||||
|
@ -187,23 +192,32 @@ environment:
|
|||
pl, err := pc.Push(p)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, buildsVariables{
|
||||
Manifest: `image: archlinux
|
||||
packages:
|
||||
- nodejs
|
||||
- npm
|
||||
- rsync
|
||||
sources:
|
||||
- http://localhost:3000/testdata/repo.git#69b217caa89166a02b8cd368b64fb83a44720e14
|
||||
tasks: []
|
||||
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:
|
||||
- nodejs
|
||||
- npm
|
||||
- rsync
|
||||
secrets:
|
||||
- 7ebab768-e5e4-4c9d-ba57-ec41a72c5665
|
||||
`,
|
||||
tasks: []
|
||||
triggers:
|
||||
- condition: failure
|
||||
action: email
|
||||
to: Jim Jimson <jim@example.org>
|
||||
# report back the status
|
||||
- condition: always
|
||||
action: webhook
|
||||
url: https://hook.example.org
|
||||
`, pl.Variables.Manifest)
|
||||
assert.Equal(t, buildsVariables{
|
||||
Manifest: pl.Variables.Manifest, // the manifest correctness is checked above, for nicer diff on error
|
||||
Note: "replace simple with complex",
|
||||
Tags: []string{"testdata/repo", "branch/main", "complex.yaml"},
|
||||
Secrets: false,
|
||||
|
|
Binary file not shown.
|
@ -1 +0,0 @@
|
|||
x•NKjÃ0ìZ§xûBÑçɶ ”¬z<C2AC>ççQã[FQÚ?"=A3óѲmk#ÏüÒ*@š²L3&²)ú”'D$ #²Î’ƒæ<>Š½Ñ¼,#/³„8²Ov‰ƒzIN<Áu'¨‘[;—JŸ¥~á»Ð{þ#'Üe;.xëòƒÜ輋#[K¯Ö[kôy¯áßASq\DA›ìkƵÑïÚÎÔûúØ<C3BA>~P¯kÙÍÂVO<56>
|
BIN
services/webhook/sourcehut/testdata/repo.git/objects/99/fb389b232e5497f0dcdb1c1065eac1d10d3794
vendored
Normal file
BIN
services/webhook/sourcehut/testdata/repo.git/objects/99/fb389b232e5497f0dcdb1c1065eac1d10d3794
vendored
Normal file
Binary file not shown.
|
@ -0,0 +1,4 @@
|
|||
xU<>έnƒ0…w<E280A6>§°΄k
|
||||
λ lΡ4υz―0νΒ ¤„%fmί~@ΫύD²Ωωμc<(·Ε<C2B7>°%
mη]<5D>NjDΫΟR<CE9F>
|
||||
ζ“Aΰ†ι–<CEB9>ΓυΣ9X•x<E280A2>φ·¶u<>{¶θ;NΆ‹ΆΘ…’4(<28>GyΣ:Q‚©Oή?…/9δlhτ|Φ0<30>cΆύυΞ<CF85>l8¶*‘<>$?ΓΥdΠΤ»§<C2BB>**³<>>7™Α<E284A2>ΞΘ–XomµΫUJItmKqνΚΐrh<72>8>Ρω)<29>ΊΪ‹FΓ,®<>°†77,‘8ΐΛΑ
{:α0zZfy<66>‹ξaΩ)
|
||||
<EFBFBD>Ω5<EFBFBD><EFBFBD> Κ΄Ψυ„ώ<E2809E>狉7Ξ‘LΗά―¤)z
‹yivoQ78J}³θ‡¤
|
BIN
services/webhook/sourcehut/testdata/repo.git/objects/b0/404943256a1f5a50c3726f4378756b4c1e5704
vendored
Normal file
BIN
services/webhook/sourcehut/testdata/repo.git/objects/b0/404943256a1f5a50c3726f4378756b4c1e5704
vendored
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1 +0,0 @@
|
|||
x=ЋKnГ0D»Ц)ё`иkЙ@PdХ{P2™Ё°-AQ›їк]АYјЗIeЯsmэKoDђЖ)¤™µ‘ґ8Ѕp gg44вlЉИFQ±ССБп•”F9ѓВ<D193>жИV,“[ЈUЦО¤`~ф[iрVЪ•ЮњщчёРчєС4к+(Їф0Y)б$µ”"эМлФ lщ“Z-eѓу5чЛwПФ¦КёNЬюЩY»?V4Є&‚ЏМtпрИэC9ю=aШо№в™,PЎ
|
|
@ -1 +1 @@
|
|||
69b217caa89166a02b8cd368b64fb83a44720e14
|
||||
b0404943256a1f5a50c3726f4378756b4c1e5704
|
||||
|
|
Loading…
Reference in a new issue