Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change dingtalk notification link so it could be opened in browser #3992

Merged
merged 8 commits into from
Feb 12, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ limitations under the License.

package instantmessage

import (
"fmt"
"net/url"
)

type DingDingMessage struct {
MsgType string `json:"msgtype"`
MarkDown *DingDingMarkDown `json:"markdown"`
Expand Down Expand Up @@ -54,6 +59,11 @@ const (
)

func (w *Service) sendDingDingMessage(uri, title, content, actionURL string, atMobiles []string, isAtAll bool) error {
// reference: https://open.dingtalk.com/document/orgapp/message-link-description
dingtalkRedirectURL := fmt.Sprintf("dingtalk://dingtalkclient/page/link?url=%s&pc_slide=false",
url.QueryEscape(actionURL),
)

message := &DingDingMessage{
MsgType: DingDingMsgType,
ActionCard: &DingDingActionCard{
Expand All @@ -64,7 +74,7 @@ func (w *Service) sendDingDingMessage(uri, title, content, actionURL string, atM
Buttons: []*DingDingButton{
{
Title: "点击查看更多信息",
ActionURL: actionURL,
ActionURL: dingtalkRedirectURL,
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ func (w *Service) sendNotification(title, content string, notify *models.NotifyC
if notify.WebHookType == setting.NotifyWebHookTypeDingDing || notify.WebHookType == setting.NotifyWebHookTypeWechatWork {
switch webhookNotify.TaskType {
case config.WorkflowTaskTypeWorkflow:
link = fmt.Sprintf("%s/v1/projects/detail/%s/pipelines/custom/%s?display_name=%s", configbase.SystemAddress(), webhookNotify.ProjectName, webhookNotify.WorkflowName, url.PathEscape(webhookNotify.WorkflowDisplayName))
link = fmt.Sprintf("%s/v1/projects/detail/%s/pipelines/custom/%s/%d?display_name=%s", configbase.SystemAddress(), webhookNotify.ProjectName, webhookNotify.WorkflowName, webhookNotify.TaskID, url.PathEscape(webhookNotify.WorkflowDisplayName))
case config.WorkflowTaskTypeScanning:
segs := strings.Split(webhookNotify.WorkflowName, "-")
link = fmt.Sprintf("%s/v1/projects/detail/%s/scanner/detail/%s/task/%d?id=%s", configbase.SystemAddress(), webhookNotify.ProjectName, url.PathEscape(webhookNotify.WorkflowDisplayName), webhookNotify.TaskID, segs[len(segs)-1])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ func sendDingDingMessage(productName, workflowName, workflowDisplayName string,
url.PathEscape(workflowDisplayName),
)

// reference: https://open.dingtalk.com/document/orgapp/message-link-description
dingtalkRedirectURL := fmt.Sprintf("dingtalk://dingtalkclient/page/link?url=%s&pc_slide=false",
url.QueryEscape(actionURL),
)

messageReq := instantmessage.DingDingMessage{
MsgType: instantmessage.DingDingMsgType,
ActionCard: &instantmessage.DingDingActionCard{
Expand All @@ -278,7 +283,7 @@ func sendDingDingMessage(productName, workflowName, workflowDisplayName string,
Buttons: []*instantmessage.DingDingButton{
{
Title: "点击查看更多信息",
ActionURL: actionURL,
ActionURL: dingtalkRedirectURL,
},
},
},
Expand Down