generated from padok-team/yatas-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckTable.go
89 lines (84 loc) · 1.85 KB
/
CheckTable.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"github.com/jomei/notionapi"
"github.com/stangirard/yatas/plugins/commons"
)
func createCheckTable(check commons.Check) notionapi.Block {
table := notionapi.TableBlock{
BasicBlock: notionapi.BasicBlock{
Type: notionapi.BlockType("table"),
Object: notionapi.ObjectType("block"),
},
Table: notionapi.Table{
TableWidth: 3,
HasColumnHeader: true,
Children: createRowsTable(check.Results),
},
}
return table
}
func createRowsTable(results []commons.Result) []notionapi.Block {
rows := []notionapi.Block{}
rows = append(rows, createHeaderRowTable())
for _, result := range results {
r := createRowTable(result)
rows = append(rows, r)
}
return rows
}
func createHeaderRowTable() notionapi.TableRowBlock {
id := notionapi.Text{
Content: "ID",
}
status := notionapi.Text{
Content: "Status",
}
message := notionapi.Text{
Content: "Message",
}
row := notionapi.TableRowBlock{
BasicBlock: notionapi.BasicBlock{
Type: notionapi.BlockType("table_row"),
Object: notionapi.ObjectType("block"),
},
TableRow: notionapi.TableRow{
Cells: [][]notionapi.RichText{
{{Text: &id}},
{{Text: &status}},
{{Text: &message}},
},
},
}
return row
}
func createRowTable(res commons.Result) notionapi.TableRowBlock {
emojiStatus := ""
if res.Status == "FAIL" {
emojiStatus = "❌"
} else {
emojiStatus = "✅"
}
id := notionapi.Text{
Content: res.ResourceID,
}
status := notionapi.Text{
Content: emojiStatus,
}
message := notionapi.Text{
Content: res.Message,
}
row := notionapi.TableRowBlock{
BasicBlock: notionapi.BasicBlock{
Type: notionapi.BlockType("table_row"),
Object: notionapi.ObjectType("block"),
},
TableRow: notionapi.TableRow{
Cells: [][]notionapi.RichText{
{{Text: &id}},
{{Text: &status}},
{{Text: &message}},
},
},
}
return row
}