Пример #1
0
        public DingTalkResModel ConvertMD(HWCodeHookModel model, DingTalkConfig config)
        {
            var result = new DingTalkResModel();

            result.msgtype = "markdown";
            var md = new DingTalkResMarkdown();

            md.title = $"{model.repository.name}源代码提交";
            var mdSb = new StringBuilder();

            foreach (var commit in model.commits)
            {
                mdSb.AppendLine($"# {commit.message}{Environment.NewLine}");
                mdSb.AppendLine($"> [{commit.author.name} {commit.timestamp.AddHours(8)}](https://devcloud.huaweicloud.com/codehub/project/{config.Project}/codehub/{model.project_id}/{commit.id}/commitdetail){Environment.NewLine}");
                //if (commit.added != null && commit.added.Length > 0)
                //{
                //    mdSb.AppendLine($"> Added{Environment.NewLine}");
                //    foreach (var item in commit.added)
                //    {
                //        mdSb.AppendLine($"- [{item}](https://devcloud.huaweicloud.com/codehub/project/{config.Project}/codehub/{model.project_id}/file?ref={model.project.default_branch}&path={Uri.EscapeDataString(item)})");
                //    }
                //    mdSb.AppendLine($"{Environment.NewLine}");
                //}
                //if (commit.modified != null && commit.modified.Length > 0)
                //{
                //    mdSb.AppendLine($"> Modified{Environment.NewLine}");
                //    foreach (var item in commit.modified)
                //    {
                //        mdSb.AppendLine($"- [{item}](https://devcloud.huaweicloud.com/codehub/project/{config.Project}/codehub/{model.project_id}/file?ref={model.project.default_branch}&path={Uri.EscapeDataString(item)})");
                //    }
                //    mdSb.AppendLine($"{Environment.NewLine}");
                //}
                //if (commit.removed != null && commit.removed.Length > 0)
                //{
                //    mdSb.AppendLine($"> Removed{Environment.NewLine}");
                //    foreach (var item in commit.removed)
                //    {
                //        mdSb.AppendLine($"- [{item}](https://devcloud.huaweicloud.com/codehub/project/{config.Project}/codehub/{model.project_id}/file?ref={model.project.default_branch}&path={Uri.EscapeDataString(item)})");
                //    }
                //    mdSb.AppendLine($"{Environment.NewLine}");
                //}
            }
            mdSb.AppendLine($"> *Repository [{model.repository.name}](https://devcloud.huaweicloud.com/codehub/project/{config.Project}/codehub/{model.project_id}/home)*{Environment.NewLine}");
            mdSb.AppendLine($"> *Project [{model.project.name}](https://devcloud.huaweicloud.com/scrum/{config.Project}/home)*{Environment.NewLine}");
            md.text         = mdSb.ToString();
            result.markdown = md;
            return(result);
        }
        public async Task <string> SendFileMessage([FromBody] FileSendModel fileSendModel)
        {
            DingTalkConfig dingTalkConfig = new DingTalkConfig();
            var            msgModel       = new FileMsgModel()
            {
                agentid = dingTalkConfig.AgentId,
                file    = new file
                {
                    media_id = fileSendModel.Media_Id
                },
                touser      = fileSendModel.UserId,
                messageType = MessageType.File
            };

            return(await dtManager.SendMessage(msgModel));
        }
Пример #3
0
        public async Task <NewErrorModel> SendFileMessageNew([FromBody] FileSendModel fileSendModel)
        {
            DingTalkConfig dingTalkConfig = new DingTalkConfig();
            var            msgModel       = new FileMsgModel()
            {
                agentid = dingTalkConfig.AgentId,
                file    = new file
                {
                    media_id = fileSendModel.Media_Id
                },
                touser      = fileSendModel.UserId,
                messageType = MessageType.File
            };

            return(new NewErrorModel()
            {
                data = await dtManager.SendMessage(msgModel),
                error = new Error(0, "推送成功!", "")
                {
                },
            });
        }