-
Notifications
You must be signed in to change notification settings - Fork 28
/
get_webhook.go
40 lines (32 loc) · 966 Bytes
/
get_webhook.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// SPDX-License-Identifier: Apache-2.0
package hook
import (
"context"
api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/constants"
"github.com/go-vela/server/database/types"
)
// GetHookByWebhookID gets a single hook with a matching webhook id in the database.
func (e *engine) GetHookByWebhookID(ctx context.Context, webhookID int64) (*api.Hook, error) {
e.logger.Tracef("getting a hook with webhook id %d", webhookID)
// variable to store query results
h := new(types.Hook)
// send query to the database and store result in variable
err := e.client.
WithContext(ctx).
Table(constants.TableHook).
Preload("Repo").
Preload("Repo.Owner").
Preload("Build").
Where("webhook_id = ?", webhookID).
Take(h).
Error
if err != nil {
return nil, err
}
err = h.Repo.Decrypt(e.config.EncryptionKey)
if err != nil {
e.logger.Errorf("unable to decrypt repo for hook %d: %v", h.ID.Int64, err)
}
return h.ToAPI(), nil
}