Skip to content

Commit 488f305

Browse files
author
欧俊
committed
优化
1 parent b9d4649 commit 488f305

7 files changed

Lines changed: 64 additions & 79 deletions

File tree

src/azure.devops.notify.dingtalk.robots/AzureDevOps/Deployment.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
namespace azure.devops.notify.dingtalk.robots.AzureDevOps
1+
using Newtonsoft.Json;
2+
using System.Collections.Generic;
3+
4+
namespace azure.devops.notify.dingtalk.robots.AzureDevOps
25
{
36
public class Deployment
47
{
5-
public ReleaseDefinition ReleaseDefinition { get; set; }
8+
public NameLinks ReleaseDefinition { get; set; }
9+
public NameLinks Release { get; set; }
610
public string DeploymentStatus { get; set; }
711

812
public By RequestedFor { get; set; }

src/azure.devops.notify.dingtalk.robots/AzureDevOps/ReleaseDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace azure.devops.notify.dingtalk.robots.AzureDevOps
55
{
6-
public class ReleaseDefinition
6+
public class NameLinks
77
{
88
public string Name { get; set; }
99
[JsonProperty("_links")]

src/azure.devops.notify.dingtalk.robots/AzureDevOps/RequestedFor.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/azure.devops.notify.dingtalk.robots/AzureDevOps/WebHooksRequestResourceRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ public class WebHooksRequestResourceRequest
44
{
55
public int Id { get; set; }
66
public string Url { get; set; }
7-
public RequestedFor RequestedFor { get; set; }
7+
public By RequestedFor { get; set; }
88
}
99
}

src/azure.devops.notify.dingtalk.robots/Controllers/WebHookController.cs

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -61,55 +61,23 @@ public WebHookController(IDingTalkService dingTalkService, ILogger<WebHookContro
6161
[HttpPost]
6262
public async Task<IActionResult> ReleaseUpdated([FromBody] WebHooksRequestDeployCreatedResource request)
6363
{
64-
/*
65-
{
66-
"id": "487c2c58-a83c-44c1-8732-3c99975defb2",
67-
"eventType": "ms.vss-release.deployment-approval-pending-event",
68-
"publisherId": "rm",
69-
"message": {
70-
"text": "阶段 prod 上的发布 2109011 尚待 预先部署 审批。",
71-
"html": "阶段 <a href='https://team.lujing.tech/NewSoftCollection/XXXProject/_release?_a=environment-summary&definitionId=45&definitionEnvironmentId=361'>prod</a> 上的发布 <a href='https://team.lujing.tech/NewSoftCollection/XXXProject/_release?releaseId=17455&_a=release-summary'>2109011</a> 尚待 预先部署 审批。",
72-
"markdown": "[prod](https://team.lujing.tech/NewSoftCollection/XXXProject/_release?_a=environment-summary&definitionId=45&definitionEnvironmentId=361)上的发布 [2109011](https://team.lujing.tech/NewSoftCollection/XXXProject/_release?releaseId=17455&_a=release-summary)尚待 预先部署 审批"
73-
},
74-
"detailedMessage": {
75-
"text": "阶段 prod 上的发布 2109011 尚待 预先部署 审批。\r\n待定位置: 杜建鹏\r\n待定开始时间: 03-September-2021 01:52:24 PM (UTC)",
76-
"html": "阶段 <a href='https://team.lujing.tech/NewSoftCollection/XXXProject/_release?_a=environment-summary&definitionId=45&definitionEnvironmentId=361'>prod</a> 上的发布 <a href='https://team.lujing.tech/NewSoftCollection/XXXProject/_release?releaseId=17455&_a=release-summary'>2109011</a> 尚待 预先部署 审批。<br>待定位置: 杜建鹏<br>待定开始时间: 03-September-2021 01:52:24 PM (UTC)",
77-
"markdown": "阶段 [prod](https://team.lujing.tech/NewSoftCollection/XXXProject/_release?_a=environment-summary&definitionId=45&definitionEnvironmentId=361) 上的发布 [2109011](https://team.lujing.tech/NewSoftCollection/XXXProject/_release?releaseId=17455&_a=release-summary) 尚待 预先部署 审批。\r\n待定位置: 杜建鹏\r\n待定开始时间: 03-September-2021 01:52:24 PM (UTC)"
78-
},
79-
"resource": "由于大小限制,历史记录中不会显示资源详细信息",
80-
"resourceVersion": "3.0-preview.1",
81-
"resourceContainers": {
82-
"collection": {
83-
"id": "196f1fb9-5cca-476e-bf6b-1bfc354d09c7",
84-
"baseUrl": "https://team.lujing.tech/NewSoftCollection/"
85-
},
86-
"server": {
87-
"id": "93ebc1b4-e4e0-4d53-8037-4905cd8a4cb6",
88-
"baseUrl": "https://team.lujing.tech/"
89-
},
90-
"project": {
91-
"id": "4993cbb2-cf7e-4796-9844-9a36b1aec4b3",
92-
"baseUrl": "https://team.lujing.tech/NewSoftCollection/"
93-
}
94-
},
95-
"createdDate": "2021-09-03T13:52:32.171Z"
96-
}*/
97-
9864
string html = request.Resource?.Deployment?.ReleaseDefinition?.GetWebUrl;
9965
string repository = request.Resource?.Deployment?.ReleaseDefinition?.Name;
10066

10167
StringBuilder stringBuilder = new();
102-
stringBuilder.AppendLine($"#### [# {repository} 触发自动部署]({html})");
68+
stringBuilder.AppendLine($"#### [#{request.Resource?.Deployment?.Release?.Name} {repository} 触发自动部署]({html})");
10369
stringBuilder.AppendLine();
10470
stringBuilder.AppendLine("---");
71+
stringBuilder.AppendLine($"> 发起: @{request.Resource?.Deployment?.RequestedFor?.DisplayName}");
72+
stringBuilder.AppendLine("> ");
10573
stringBuilder.AppendLine($"> 阶段: {request.Resource?.Environment?.Name}");
10674
stringBuilder.AppendLine("> ");
10775
stringBuilder.AppendLine($"> 状态: {request.Resource?.Environment?.Status}");
10876
stringBuilder.AppendLine("> ");
10977

11078
stringBuilder.AppendLine("---");
11179
stringBuilder.AppendLine();
112-
stringBuilder.AppendLine(request.DetailedMessage.MarkDown);
80+
stringBuilder.AppendLine(request.Message.MarkDown);
11381
await _dingTalkService.MarkdownAsync("CICD", "CD", $"{repository} 触发自动部署", stringBuilder.ToString());
11482
return Ok();
11583
}

src/azure.devops.notify.dingtalk.robots/Infrastructure/IDingTalkService.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace azure.devops.notify.dingtalk.robots.Infrastructure
1212
{
1313
public interface IDingTalkService
1414
{
15-
Task MarkdownAsync(string type, string workItemType, string title, string content, bool atAll = false);
15+
Task MarkdownAsync(string type, string workItemType, string title, string content);
1616
[Obsolete("效果不是太好,会在钉钉内部打开侧边,不适合")]
1717
void ActionCard(string title, string content, string workItemUrl);
1818
}
@@ -90,9 +90,8 @@ public void ActionCard(string title, string content, string workItemUrl)
9090
/// <param name="workItemType"></param>
9191
/// <param name="title"></param>
9292
/// <param name="content"></param>
93-
/// <param name="atAll"></param>
9493
/// <returns></returns>
95-
public async Task MarkdownAsync(string type, string workItemType, string title, string content, bool atAll = false)
94+
public async Task MarkdownAsync(string type, string workItemType, string title, string content)
9695
{
9796
var timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
9897
foreach (var g in _appSettings.Robots.Where(t => t.Types.Any(x => x.Type == type && (!x.WorkItemTypes.Any() || x.WorkItemTypes.Contains(workItemType)))).Distinct())

src/azure.devops.notify.dingtalk.robots/appsettings.Development.json

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,68 @@
66
"Microsoft.Hosting.Lifetime": "Information"
77
}
88
},
9+
"workItemCustomNodes": [
10+
{
11+
"key": "Microsoft.VSTS.Common.Activity",
12+
"name": "活动"
13+
},
14+
{
15+
"key": "Microsoft.VSTS.Scheduling.StartDate",
16+
"name": "开始开发"
17+
},
18+
{
19+
"key": "Custom.923ac41b-2afe-42f9-94d2-e27b33027806",
20+
"name": "预计提测",
21+
"format": "yyyy-MM-dd"
22+
},
23+
{
24+
"key": "Custom.7651019e-320a-4988-b86f-a5cdef9a150a",
25+
"name": "预计发布",
26+
"format": "yyyy-MM-dd"
27+
},
28+
{
29+
"key": "Custom.1a3c1040-7ba2-44f4-b5de-e8c78dd2021e",
30+
"name": "实际发布",
31+
"format": "yyyy-MM-dd"
32+
},
33+
{
34+
"key": "Microsoft.VSTS.Common.AcceptanceCriteria",
35+
"name": "验收条件"
36+
}
37+
],
938
"robots": [
1039
{
1140
"Name": "DevOps通知群",
1241
"access_token": "xxx",
1342
"secret": "xxx",
14-
"Type": [ "PR", "Task" ],
15-
"AtOnly": true,
16-
"UserMappings": [
43+
"Types": [
1744
{
18-
"devops": "ABC",
19-
"dingtalk": "18000000001"
45+
"Type": "PR",
46+
"WorkItemTypes": []
2047
},
2148
{
22-
"devops": "BCD",
23-
"dingtalk": "18000000003"
49+
"Type": "CICD",
50+
"WorkItemTypes": [
51+
"CD"
52+
]
2453
},
2554
{
26-
"devops": "DEF",
27-
"dingtalk": "18000000002"
55+
"Type": "Task",
56+
"WorkItemTypes": [
57+
"用户情景",
58+
"Bug",
59+
"任务"
60+
]
61+
}
62+
],
63+
"AtOnly": true,
64+
"UserMappings": [
65+
{
66+
"devops": "AAA",
67+
"dingtalk": "18600000000"
2868
}
2969
]
3070
}
3171
],
32-
"DefaultUserMappings": [
33-
{
34-
"devops": "ABC",
35-
"dingtalk": "18000000001"
36-
},
37-
{
38-
"devops": "BCD",
39-
"dingtalk": "18000000003"
40-
},
41-
{
42-
"devops": "DEF",
43-
"dingtalk": "18000000002"
44-
}
45-
]
72+
"DefaultUserMappings": []
4673
}

0 commit comments

Comments
 (0)