summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorEarl Warren <earl-warren@noreply.codeberg.org>2024-05-24 02:16:22 +0200
committerEarl Warren <earl-warren@noreply.codeberg.org>2024-05-24 02:16:22 +0200
commit32222d7d0a4fe9c77992c50546a2e89401fb6616 (patch)
tree499d25cb6201477a093cc0b248cdaa7c178984d8 /services
parentMerge pull request 'Update module github.com/jhillyerd/enmime to v1.2.0' (#37... (diff)
parentadd release-notes (diff)
downloadforgejo-32222d7d0a4fe9c77992c50546a2e89401fb6616.tar.xz
forgejo-32222d7d0a4fe9c77992c50546a2e89401fb6616.zip
Merge pull request '[BUG] Fix SourceHut Builds webhook with triggers field' (#3864) from oliverpool/forgejo:sourcehut_trigger into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3864 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Diffstat (limited to 'services')
-rw-r--r--services/webhook/sourcehut/builds.go18
-rw-r--r--services/webhook/sourcehut/builds_test.go84
-rw-r--r--services/webhook/sourcehut/testdata/repo.git/objects/01/16b5e2279b70e5f5b98240e8896331248f4463bin54 -> 0 bytes
-rw-r--r--services/webhook/sourcehut/testdata/repo.git/objects/56/f276169b9766f805e5198fe7fb6698153fdb031
-rw-r--r--services/webhook/sourcehut/testdata/repo.git/objects/99/fb389b232e5497f0dcdb1c1065eac1d10d3794bin0 -> 57 bytes
-rw-r--r--services/webhook/sourcehut/testdata/repo.git/objects/a5/4082fdb8e55055382725f10a81bb4dc2b130294
-rw-r--r--services/webhook/sourcehut/testdata/repo.git/objects/b0/404943256a1f5a50c3726f4378756b4c1e5704bin0 -> 160 bytes
-rw-r--r--services/webhook/sourcehut/testdata/repo.git/objects/bd/d74dba3f34542e480d56c2a91c9e2463180d3cbin130 -> 0 bytes
-rw-r--r--services/webhook/sourcehut/testdata/repo.git/objects/c2/30778a03511f546f532e79c8c14917c260e750bin84 -> 0 bytes
-rw-r--r--services/webhook/sourcehut/testdata/repo.git/objects/c9/fa8be8c6f230e9529f8e546a3e6a354cbaf313bin56 -> 0 bytes
-rw-r--r--services/webhook/sourcehut/testdata/repo.git/objects/cb/80b2628b69c86b6baea464e5f9fc28405fde4b1
-rw-r--r--services/webhook/sourcehut/testdata/repo.git/refs/heads/main2
12 files changed, 60 insertions, 50 deletions
diff --git a/services/webhook/sourcehut/builds.go b/services/webhook/sourcehut/builds.go
index e7501110a2..7b7ace15bb 100644
--- a/services/webhook/sourcehut/builds.go
+++ b/services/webhook/sourcehut/builds.go
@@ -264,19 +264,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)
diff --git a/services/webhook/sourcehut/builds_test.go b/services/webhook/sourcehut/builds_test.go
index 9ab018df72..64c6081076 100644
--- a/services/webhook/sourcehut/builds_test.go
+++ b/services/webhook/sourcehut/builds_test.go
@@ -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,
diff --git a/services/webhook/sourcehut/testdata/repo.git/objects/01/16b5e2279b70e5f5b98240e8896331248f4463 b/services/webhook/sourcehut/testdata/repo.git/objects/01/16b5e2279b70e5f5b98240e8896331248f4463
deleted file mode 100644
index c06eb842be..0000000000
--- a/services/webhook/sourcehut/testdata/repo.git/objects/01/16b5e2279b70e5f5b98240e8896331248f4463
+++ /dev/null
Binary files differ
diff --git a/services/webhook/sourcehut/testdata/repo.git/objects/56/f276169b9766f805e5198fe7fb6698153fdb03 b/services/webhook/sourcehut/testdata/repo.git/objects/56/f276169b9766f805e5198fe7fb6698153fdb03
deleted file mode 100644
index dca1d23ce9..0000000000
--- a/services/webhook/sourcehut/testdata/repo.git/objects/56/f276169b9766f805e5198fe7fb6698153fdb03
+++ /dev/null
@@ -1 +0,0 @@
-xNKj0ZxBɶzQ[FQ?"=A3Ѳmk#*@L3&)'D$#Β 搊Ѽ,#/8OvzIN<u'[;J~{#'e;.x輋#[K[kyASq\DAkƵ؝~PkVO \ No newline at end of file
diff --git a/services/webhook/sourcehut/testdata/repo.git/objects/99/fb389b232e5497f0dcdb1c1065eac1d10d3794 b/services/webhook/sourcehut/testdata/repo.git/objects/99/fb389b232e5497f0dcdb1c1065eac1d10d3794
new file mode 100644
index 0000000000..43dd885510
--- /dev/null
+++ b/services/webhook/sourcehut/testdata/repo.git/objects/99/fb389b232e5497f0dcdb1c1065eac1d10d3794
Binary files differ
diff --git a/services/webhook/sourcehut/testdata/repo.git/objects/a5/4082fdb8e55055382725f10a81bb4dc2b13029 b/services/webhook/sourcehut/testdata/repo.git/objects/a5/4082fdb8e55055382725f10a81bb4dc2b13029
new file mode 100644
index 0000000000..071f79e851
--- /dev/null
+++ b/services/webhook/sourcehut/testdata/repo.git/objects/a5/4082fdb8e55055382725f10a81bb4dc2b13029
@@ -0,0 +1,4 @@
+xUn0 wk
+l4z0 %fm~@Dc<(ŝ% m]NjDR
+A閌9Xxu{;Nȅ4(Gy:QO?/9 lh|0cΌl8*$?dԻ**>7ȖXomUJItmKqrh8>)ҺڋF,77,8 {:0zZfya)
+5 ʴ狉7ΑLܯ)z yivoQ78J}臤 \ No newline at end of file
diff --git a/services/webhook/sourcehut/testdata/repo.git/objects/b0/404943256a1f5a50c3726f4378756b4c1e5704 b/services/webhook/sourcehut/testdata/repo.git/objects/b0/404943256a1f5a50c3726f4378756b4c1e5704
new file mode 100644
index 0000000000..a2cff639dc
--- /dev/null
+++ b/services/webhook/sourcehut/testdata/repo.git/objects/b0/404943256a1f5a50c3726f4378756b4c1e5704
Binary files differ
diff --git a/services/webhook/sourcehut/testdata/repo.git/objects/bd/d74dba3f34542e480d56c2a91c9e2463180d3c b/services/webhook/sourcehut/testdata/repo.git/objects/bd/d74dba3f34542e480d56c2a91c9e2463180d3c
deleted file mode 100644
index 639f5c4784..0000000000
--- a/services/webhook/sourcehut/testdata/repo.git/objects/bd/d74dba3f34542e480d56c2a91c9e2463180d3c
+++ /dev/null
Binary files differ
diff --git a/services/webhook/sourcehut/testdata/repo.git/objects/c2/30778a03511f546f532e79c8c14917c260e750 b/services/webhook/sourcehut/testdata/repo.git/objects/c2/30778a03511f546f532e79c8c14917c260e750
deleted file mode 100644
index 4a952fb0b2..0000000000
--- a/services/webhook/sourcehut/testdata/repo.git/objects/c2/30778a03511f546f532e79c8c14917c260e750
+++ /dev/null
Binary files differ
diff --git a/services/webhook/sourcehut/testdata/repo.git/objects/c9/fa8be8c6f230e9529f8e546a3e6a354cbaf313 b/services/webhook/sourcehut/testdata/repo.git/objects/c9/fa8be8c6f230e9529f8e546a3e6a354cbaf313
deleted file mode 100644
index 291f0a422c..0000000000
--- a/services/webhook/sourcehut/testdata/repo.git/objects/c9/fa8be8c6f230e9529f8e546a3e6a354cbaf313
+++ /dev/null
Binary files differ
diff --git a/services/webhook/sourcehut/testdata/repo.git/objects/cb/80b2628b69c86b6baea464e5f9fc28405fde4b b/services/webhook/sourcehut/testdata/repo.git/objects/cb/80b2628b69c86b6baea464e5f9fc28405fde4b
deleted file mode 100644
index 891ace4651..0000000000
--- a/services/webhook/sourcehut/testdata/repo.git/objects/cb/80b2628b69c86b6baea464e5f9fc28405fde4b
+++ /dev/null
@@ -1 +0,0 @@
-x=Kn0 D)`k@Pd{P2-AQ] YIesmKoD)8p gg44lFQF9˜V,[UΤ`~[iVڕ 4+(0Y)$"ԠlZ-e5wԦʸNY?V4&tC9=a ,P \ No newline at end of file
diff --git a/services/webhook/sourcehut/testdata/repo.git/refs/heads/main b/services/webhook/sourcehut/testdata/repo.git/refs/heads/main
index 4e693a7464..a7ab41949f 100644
--- a/services/webhook/sourcehut/testdata/repo.git/refs/heads/main
+++ b/services/webhook/sourcehut/testdata/repo.git/refs/heads/main
@@ -1 +1 @@
-69b217caa89166a02b8cd368b64fb83a44720e14
+b0404943256a1f5a50c3726f4378756b4c1e5704