Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
976bd332
Commit
976bd332
authored
Jun 24, 2025
by
johnnyjoy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: fix linter
parent
d6a75bba
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
11 additions
and
14 deletions
+11
-14
webhook.go
plugin/webhook/webhook.go
+9
-9
webhook_service.proto
proto/api/v1/webhook_service.proto
+0
-1
webhook_service.pb.go
proto/gen/api/v1/webhook_service.pb.go
+1
-2
memo_service.go
server/router/api/v1/memo_service.go
+1
-1
resource_name.go
server/router/api/v1/resource_name.go
+0
-1
No files found.
plugin/webhook/webhook.go
View file @
976bd332
...
...
@@ -20,7 +20,7 @@ var (
type
WebhookRequestPayload
struct
{
// The target URL for the webhook request.
U
rl
string
`json:"url"`
U
RL
string
`json:"url"`
// The type of activity that triggered this webhook.
ActivityType
string
`json:"activityType"`
// The resource name of the creator. Format: users/{user}
...
...
@@ -33,12 +33,12 @@ type WebhookRequestPayload struct {
func
Post
(
requestPayload
*
WebhookRequestPayload
)
error
{
body
,
err
:=
json
.
Marshal
(
requestPayload
)
if
err
!=
nil
{
return
errors
.
Wrapf
(
err
,
"failed to marshal webhook request to %s"
,
requestPayload
.
U
rl
)
return
errors
.
Wrapf
(
err
,
"failed to marshal webhook request to %s"
,
requestPayload
.
U
RL
)
}
req
,
err
:=
http
.
NewRequest
(
"POST"
,
requestPayload
.
U
rl
,
bytes
.
NewBuffer
(
body
))
req
,
err
:=
http
.
NewRequest
(
"POST"
,
requestPayload
.
U
RL
,
bytes
.
NewBuffer
(
body
))
if
err
!=
nil
{
return
errors
.
Wrapf
(
err
,
"failed to construct webhook request to %s"
,
requestPayload
.
U
rl
)
return
errors
.
Wrapf
(
err
,
"failed to construct webhook request to %s"
,
requestPayload
.
U
RL
)
}
req
.
Header
.
Set
(
"Content-Type"
,
"application/json"
)
...
...
@@ -47,17 +47,17 @@ func Post(requestPayload *WebhookRequestPayload) error {
}
resp
,
err
:=
client
.
Do
(
req
)
if
err
!=
nil
{
return
errors
.
Wrapf
(
err
,
"failed to post webhook to %s"
,
requestPayload
.
U
rl
)
return
errors
.
Wrapf
(
err
,
"failed to post webhook to %s"
,
requestPayload
.
U
RL
)
}
b
,
err
:=
io
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
return
errors
.
Wrapf
(
err
,
"failed to read webhook response from %s"
,
requestPayload
.
U
rl
)
return
errors
.
Wrapf
(
err
,
"failed to read webhook response from %s"
,
requestPayload
.
U
RL
)
}
defer
resp
.
Body
.
Close
()
if
resp
.
StatusCode
<
200
||
resp
.
StatusCode
>
299
{
return
errors
.
Errorf
(
"failed to post webhook %s, status code: %d, response body: %s"
,
requestPayload
.
U
rl
,
resp
.
StatusCode
,
b
)
return
errors
.
Errorf
(
"failed to post webhook %s, status code: %d, response body: %s"
,
requestPayload
.
U
RL
,
resp
.
StatusCode
,
b
)
}
response
:=
&
struct
{
...
...
@@ -65,7 +65,7 @@ func Post(requestPayload *WebhookRequestPayload) error {
Message
string
`json:"message"`
}{}
if
err
:=
json
.
Unmarshal
(
b
,
response
);
err
!=
nil
{
return
errors
.
Wrapf
(
err
,
"failed to unmarshal webhook response from %s"
,
requestPayload
.
U
rl
)
return
errors
.
Wrapf
(
err
,
"failed to unmarshal webhook response from %s"
,
requestPayload
.
U
RL
)
}
if
response
.
Code
!=
0
{
...
...
@@ -82,7 +82,7 @@ func PostAsync(requestPayload *WebhookRequestPayload) {
if
err
:=
Post
(
requestPayload
);
err
!=
nil
{
// Since we're in a goroutine, we can only log the error
slog
.
Warn
(
"Failed to dispatch webhook asynchronously"
,
slog
.
String
(
"url"
,
requestPayload
.
U
rl
),
slog
.
String
(
"url"
,
requestPayload
.
U
RL
),
slog
.
String
(
"activityType"
,
requestPayload
.
ActivityType
),
slog
.
Any
(
"err"
,
err
))
}
...
...
proto/api/v1/webhook_service.proto
View file @
976bd332
...
...
@@ -2,7 +2,6 @@ syntax = "proto3";
package
memos
.
api.v1
;
import
"api/v1/memo_service.proto"
;
import
"google/api/annotations.proto"
;
import
"google/api/client.proto"
;
import
"google/api/field_behavior.proto"
;
...
...
proto/gen/api/v1/webhook_service.pb.go
View file @
976bd332
...
...
@@ -393,7 +393,7 @@ var File_api_v1_webhook_service_proto protoreflect.FileDescriptor
const
file_api_v1_webhook_service_proto_rawDesc
=
""
+
"
\n
"
+
"
\x1c
api/v1/webhook_service.proto
\x12\f
memos.api.v1
\x1a\x1
9
api/v1/memo_service.proto
\x1a\x1
c
google/api/annotations.proto
\x1a\x17
google/api/client.proto
\x1a\x1f
google/api/field_behavior.proto
\x1a\x19
google/api/resource.proto
\x1a\x1b
google/protobuf/empty.proto
\x1a
google/protobuf/field_mask.proto
\"\xb0\x01\n
"
+
"
\x1c
api/v1/webhook_service.proto
\x12\f
memos.api.v1
\x1a\x1c
google/api/annotations.proto
\x1a\x17
google/api/client.proto
\x1a\x1f
google/api/field_behavior.proto
\x1a\x19
google/api/resource.proto
\x1a\x1b
google/protobuf/empty.proto
\x1a
google/protobuf/field_mask.proto
\"\xb0\x01\n
"
+
"
\a
Webhook
\x12\x17\n
"
+
"
\x04
name
\x18\x01
\x01
(
\t
B
\x03\xe0
A
\b
R
\x04
name
\x12
&
\n
"
+
"
\f
display_name
\x18\x02
\x01
(
\t
B
\x03\xe0
A
\x02
R
\v
displayName
\x12\x15\n
"
+
...
...
@@ -477,7 +477,6 @@ func file_api_v1_webhook_service_proto_init() {
if
File_api_v1_webhook_service_proto
!=
nil
{
return
}
file_api_v1_memo_service_proto_init
()
type
x
struct
{}
out
:=
protoimpl
.
TypeBuilder
{
File
:
protoimpl
.
DescBuilder
{
...
...
server/router/api/v1/memo_service.go
View file @
976bd332
...
...
@@ -698,7 +698,7 @@ func (s *APIV1Service) dispatchMemoRelatedWebhook(ctx context.Context, memo *v1p
return
errors
.
Wrap
(
err
,
"failed to convert memo to webhook payload"
)
}
payload
.
ActivityType
=
activityType
payload
.
U
rl
=
hook
.
Url
payload
.
U
RL
=
hook
.
Url
// Use asynchronous webhook dispatch
webhook
.
PostAsync
(
payload
)
...
...
server/router/api/v1/resource_name.go
View file @
976bd332
...
...
@@ -146,7 +146,6 @@ func ExtractActivityIDFromName(name string) (int32, error) {
}
// ExtractWebhookIDFromName returns the webhook ID from a resource name.
// Expected format: users/{user}/webhooks/{webhook}
func
ExtractWebhookIDFromName
(
name
string
)
(
string
,
error
)
{
tokens
,
err
:=
GetNameParentTokens
(
name
,
UserNamePrefix
,
WebhookNamePrefix
)
if
err
!=
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment