Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ To check out this repository:
```shell
mkdir -p ${GOPATH}/src/knative.dev
cd ${GOPATH}/src/knative.dev
git clone git@github.com:${YOUR_GITHUB_USERNAME}/eventing-contrib.git
git clone git@github.com:${YOUR_GITHUB_USERNAME}/eventing-gitlab.git
cd eventing-contrib
git remote add upstream git@github.com:knative/eventing-contrib.git
git remote add upstream git@github.com:knative-extensions/eventing-gitlab.git
git remote set-url --push upstream no_push
```

Expand All @@ -60,7 +60,7 @@ of the sources _Github Source_, _AWS SQS Source_, _Camel Source_, _Kafka Source_
with:

```
ko apply -f <source_name>/config # e.g. github/config
ko apply -f ./config
```

These commands are idempotent, so you can run them at any time to update your
Expand Down
23 changes: 19 additions & 4 deletions config/300-gitlabsource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,22 @@ metadata:
# NOTE(antoineco): GitLab doesn't currently provide schemas for those events (gitlab-org/gitlab#208924)
registry.knative.dev/eventTypes: |
[
{
"type": "dev.knative.sources.gitlab.build",
"description": "Triggered on status change of a job."
},
{
"type": "dev.knative.sources.gitlab.deployment",
"description": "Triggered when a deployment starts, succeeds, fails, or is cancelled."
},
{
"type": "dev.knative.sources.gitlab.feature_flag",
"description": "Triggered when a feature flag is turned on or off.."
},
{
"type": "dev.knative.sources.gitlab.issue",
"description": "Triggered when a new issue is created or an existing issue was updated/closed/reopened."
},
{
"type": "dev.knative.sources.gitlab.job",
"description": "Triggered when a job starts, succeeds, fails, or is cancelled."
},
{
"type": "dev.knative.sources.gitlab.merge_request",
"description": "Triggered when a merge request is created/updated/merged/closed or a commit is added in the source branch."
Expand All @@ -54,13 +58,21 @@ metadata:
"type": "dev.knative.sources.gitlab.push",
"description": "Triggered when you push to the repository except when pushing tags."
},
{
"type": "dev.knative.sources.gitlab.release",
"description": "Triggered when a release is created, edited, or deleted."
},
{
"type": "dev.knative.sources.gitlab.tag_push",
"description": "Triggered when you create (or delete) tags to the repository."
},
{
"type": "dev.knative.sources.gitlab.wiki_page",
"description": "Triggered when a wiki page is created, updated or deleted."
},
{
"type": "dev.knative.sources.gitlab.resource_access_token",
"description": "Triggered when a project or group access token will expire in seven days."
}
]
spec:
Expand Down Expand Up @@ -103,14 +115,17 @@ spec:
- confidential_issues_events
- confidential_note_events
- deployment_events
- feature_flag_events
- issues_events
- job_events
- merge_requests_events
- note_events
- pipeline_events
- push_events
- releases_events
- tag_push_events
- wiki_page_events
- resource_access_token_events
minItems: 1
accessToken:
description: Access token for the GitLab API.
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ require (
github.com/hashicorp/golang-lru v1.0.2
github.com/kelseyhightower/envconfig v1.4.0
github.com/stretchr/testify v1.11.1
github.com/xanzy/go-gitlab v0.39.0
gitlab.com/gitlab-org/api/client-go v0.129.0
go.uber.org/zap v1.27.0
gopkg.in/go-playground/webhooks.v5 v5.15.0
k8s.io/api v0.33.4
k8s.io/apimachinery v0.33.4
k8s.io/client-go v0.33.4
Expand Down
19 changes: 2 additions & 17 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/go-containerregistry v0.20.3 h1:oNx7IdTI936V8CQRveCjaxOiegWwvM7kqkbXTpyiovI=
github.com/google/go-containerregistry v0.20.3/go.mod h1:w00pIgBRDVUDFM6bq+Qx8lwNWK+cxgCuX1vd3PIBDNI=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
Expand All @@ -90,13 +89,10 @@ github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc h1:GN2Lv3MGO7AS6PrR
github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc/go.mod h1:+JKpmjMGhpgPL+rXZ5nsZieVzvarn86asRlBg4uNGnk=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.1 h1:X5VWvz21y3gzm9Nw/kaUeku/1+uBhcekkmy4IkffJww=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.1/go.mod h1:Zanoh4+gvIgluNqcfMVTJueD4wSS5hT7zTt4Mrutd90=
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
github.com/hashicorp/go-retryablehttp v0.6.4/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU=
github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk=
github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c=
Expand Down Expand Up @@ -178,9 +174,7 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
Expand All @@ -191,11 +185,11 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/xanzy/go-gitlab v0.39.0 h1:7aiZ03fJfCdqoHFhsZq/SoVYp2lR91hfYWmiXLOU5Qo=
github.com/xanzy/go-gitlab v0.39.0/go.mod h1:sPLojNBn68fMUWSxIJtdVVIP8uSBYqesTfDUseX11Ug=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
gitlab.com/gitlab-org/api/client-go v0.129.0 h1:o9KLn6fezmxBQWYnQrnilwyuOjlx4206KP0bUn3HuBE=
gitlab.com/gitlab-org/api/client-go v0.129.0/go.mod h1:ZhSxLAWadqP6J9lMh40IAZOlOxBLPRh7yFOXR/bMJWM=
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.62.0 h1:Hf9xI/XLML9ElpiHVDNwvqI0hIFlzV8dgIr35kV1kRU=
Expand Down Expand Up @@ -258,9 +252,7 @@ golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.28.0 h1:gQBtGhjxykdjY9YhZpSlZIsbnaE2+PgjfLWUQTnoZ1U=
golang.org/x/mod v0.28.0/go.mod h1:yfB/L0NOf/kmEbXjzCPOx1iK1fRutOydrCMsqRhEBxI=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181108082009-03003ca0c849/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand All @@ -272,11 +264,9 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.44.0 h1:evd8IRDyfNBMBTTY5XRF1vaZlD+EmWx6x8PkhR04H/I=
golang.org/x/net v0.44.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY=
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.30.0 h1:dnDm7JmhM45NNpd8FDDeLhK6FwqbOf4MLCM9zb1BOHI=
golang.org/x/oauth2 v0.30.0/go.mod h1:B++QgG3ZKulg6sRPGD/mqlHQs5rB3Ml9erfeDY7xKlU=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -316,7 +306,6 @@ golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand All @@ -338,7 +327,6 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gomodules.xyz/jsonpatch/v2 v2.5.0 h1:JELs8RLM12qJGXU4u/TO3V25KW8GreMKl9pdkk14RM0=
gomodules.xyz/jsonpatch/v2 v2.5.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY=
google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto/googleapis/api v0.0.0-20250603155806-513f23925822 h1:oWVWY3NzT7KJppx2UKhKmzPq4SRe0LdCijVRwvGeikY=
google.golang.org/genproto/googleapis/api v0.0.0-20250603155806-513f23925822/go.mod h1:h3c4v36UTKzUiuaOKQ6gr3S+0hovBtUrXzTG/i3+XEc=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250603155806-513f23925822 h1:fc6jSaCT0vBduLYZHYrBBNY4dsWuvgyff9noRNDdBeE=
Expand All @@ -359,12 +347,9 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV
gopkg.in/evanphx/json-patch.v4 v4.12.0 h1:n6jtcsulIzXPJaxegRbvFNNrZDjbij7ny3gmSPG+6V4=
gopkg.in/evanphx/json-patch.v4 v4.12.0/go.mod h1:p8EYWUEYMpynmqDbY58zCKCFZw8pRWMG4EsWvDvM72M=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/go-playground/webhooks.v5 v5.15.0 h1:vnD8c5hN/w8qs0K3fQvIDAeYAHBnCclJHPnxNSJeBCw=
gopkg.in/go-playground/webhooks.v5 v5.15.0/go.mod h1:LZbya/qLVdbqDR1aKrGuWV6qbia2zCYSR5dpom2SInQ=
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
44 changes: 2 additions & 42 deletions pkg/adapter/receive_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import (
cloudevents "github.com/cloudevents/sdk-go/v2"
"go.uber.org/zap"

"gopkg.in/go-playground/webhooks.v5/gitlab"

sourcesv1alpha1 "knative.dev/eventing-gitlab/pkg/apis/sources/v1alpha1"
"knative.dev/eventing/pkg/adapter/v2"
"knative.dev/pkg/logging"
Expand Down Expand Up @@ -86,16 +84,13 @@ func (ra *gitLabReceiveAdapter) Start(ctx context.Context) error {
}

func (ra *gitLabReceiveAdapter) start(stopCh <-chan struct{}) error {
hook, err := gitlab.New(gitlab.Options.Secret(ra.secretToken))
if err != nil {
return fmt.Errorf("cannot create gitlab hook: %v", err)
}
wh := NewWebhookHandler(ra.secretToken, ra.handleEvent)

server := &http.Server{
ReadTimeout: 10 * time.Second,
ReadHeaderTimeout: 2 * time.Second,
Addr: ":" + ra.port,
Handler: ra.newRouter(hook),
Handler: wh,
}

var wg sync.WaitGroup
Expand Down Expand Up @@ -130,41 +125,6 @@ func gracefulShutdown(server *http.Server, logger *zap.SugaredLogger, stopCh <-c
}
}

func (ra *gitLabReceiveAdapter) newRouter(hook *gitlab.Webhook) *http.ServeMux {
router := http.NewServeMux()
router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
payload, err := hook.Parse(r,
gitlab.PushEvents,
gitlab.TagEvents,
gitlab.IssuesEvents,
gitlab.ConfidentialIssuesEvents,
gitlab.CommentEvents,
gitlab.MergeRequestEvents,
gitlab.WikiPageEvents,
gitlab.PipelineEvents,
gitlab.BuildEvents,
)
if err != nil {
ra.logger.Error("Hook parser error: ", err)
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(err.Error()))
return
}

if err := ra.handleEvent(payload, r.Header); err != nil {
ra.logger.Error("Event handler error: ", err)
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(err.Error()))
return
}

ra.logger.Debug("Event processed")
w.WriteHeader(http.StatusAccepted)
})

return router
}

func (ra *gitLabReceiveAdapter) handleEvent(payload interface{}, header http.Header) error {
eventHeader := header.Get(glHeaderEvent)
eventType := gitlabEventHeaderToEventType(eventHeader)
Expand Down
60 changes: 26 additions & 34 deletions pkg/adapter/receive_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"io"
"net/http"
"net/http/httptest"
Expand All @@ -31,7 +32,7 @@ import (
cloudevents "github.com/cloudevents/sdk-go/v2"
"go.uber.org/zap"

"gopkg.in/go-playground/webhooks.v5/gitlab"
gitlab "gitlab.com/gitlab-org/api/client-go"

"knative.dev/eventing-gitlab/pkg/apis/sources/v1alpha1"
"knative.dev/eventing/pkg/adapter/v2"
Expand Down Expand Up @@ -60,64 +61,59 @@ type testCase struct {
payload interface{}

// eventType is the GitLab event type
eventType gitlab.Event
eventType gitlab.EventType
}

var testCases = []testCase{
{
name: "valid comment",
payload: gitlab.CommentEventPayload{},
eventType: gitlab.CommentEvents,
statusCode: 202,
}, {
name: "valid issues",
payload: gitlab.IssueEventPayload{},
eventType: gitlab.IssuesEvents,
payload: gitlab.IssueEvent{},
eventType: gitlab.EventTypeIssue,
statusCode: 202,
}, {
name: "valid push",
payload: gitlab.PushEventPayload{},
eventType: gitlab.PushEvents,
payload: gitlab.PushEvent{},
eventType: gitlab.EventTypePush,
statusCode: 202,
}, {
name: "valid tag event",
payload: gitlab.TagEventPayload{},
eventType: gitlab.TagEvents,
payload: gitlab.TagEvent{},
eventType: gitlab.EventTypeTagPush,
statusCode: 202,
}, {
name: "valid confidential issue event",
payload: gitlab.ConfidentialIssueEventPayload{},
eventType: gitlab.ConfidentialIssuesEvents,
payload: gitlab.IssueEvent{},
eventType: gitlab.EventTypeIssue,
statusCode: 202,
}, {
name: "valid merge request event",
payload: gitlab.MergeRequestEventPayload{},
eventType: gitlab.MergeRequestEvents,
payload: gitlab.MergeEvent{},
eventType: gitlab.EventTypeMergeRequest,
statusCode: 202,
}, {
name: "valid wiki page event",
payload: gitlab.WikiPageEventPayload{},
eventType: gitlab.WikiPageEvents,
payload: gitlab.WikiPageEvent{},
eventType: gitlab.EventTypeWikiPage,
statusCode: 202,
}, {
name: "valid pipeline event",
payload: gitlab.PipelineEventPayload{},
eventType: gitlab.PipelineEvents,
payload: gitlab.PipelineEvent{},
eventType: gitlab.EventTypePipeline,
statusCode: 202,
}, {
name: "valid build event",
payload: gitlab.BuildEventPayload{},
eventType: gitlab.BuildEvents,
payload: gitlab.BuildEvent{},
eventType: gitlab.EventTypeBuild,
statusCode: 202,
}, {
name: "invalid nil payload",
payload: nil,
eventType: gitlab.Event("Invalid Hook"),
wantErr: gitlab.ErrEventNotFound,
payload: []byte("{\"key\": \"value\""),
eventType: gitlab.EventTypeBuild,
wantErr: ErrCouldNotParseWebhookEvent,
statusCode: 400,
}, {
name: "invalid empty eventType",
wantErr: gitlab.ErrMissingGitLabEventHeader,
wantErr: ErrMissingGitLabEventHeader,
statusCode: 400,
},
}
Expand All @@ -144,12 +140,8 @@ func TestServer(t *testing.T) {
for _, tc := range testCases {
ce := adaptertest.NewTestClient()
ra := newTestAdapter(t, ce)
hook, err := gitlab.New(gitlab.Options.Secret(ra.secretToken))
if err != nil {
t.Error(err)
}
router := ra.newRouter(hook)
server := httptest.NewServer(router)
hook := NewWebhookHandler(ra.secretToken, ra.handleEvent)
server := httptest.NewServer(hook)
defer server.Close()

t.Run(tc.name, tc.runner(t, server.URL, ce))
Expand Down Expand Up @@ -231,7 +223,7 @@ func (tc *testCase) validateAcceptedPayload(t *testing.T, ce *adaptertest.TestCl

func (tc *testCase) validateResponse(t *testing.T, body string) {
if tc.wantErr != nil {
assert.EqualError(t, tc.wantErr, body)
assert.ErrorContains(t, errors.New(body), tc.wantErr.Error())
return
}
assert.Empty(t, body)
Expand Down
Loading
Loading