generated from padok-team/yatas-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(*): add the table of categories/completions per test to the report.
- Loading branch information
1 parent
b0038c3
commit 8e8e738
Showing
5 changed files
with
236 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"github.com/jomei/notionapi" | ||
"github.com/stangirard/yatas/plugins/commons" | ||
) | ||
|
||
func addCategoriesTable(client *notionapi.Client, blockID notionapi.BlockID, test commons.Tests) { | ||
updateRequest := updatePageRequestWithCategories(test) | ||
blocks, err := client.Block.AppendChildren(context.Background(), blockID, &updateRequest) | ||
if err != nil { | ||
log.Printf("Error while triing to add categories table ... %v", err) | ||
} else { | ||
log.Printf("New blocks added ... %v", blocks) | ||
} | ||
} | ||
|
||
func addTitleTable(client *notionapi.Client, blockID notionapi.BlockID, test commons.Tests) { | ||
updateRequest := updatePageRequestWithTitle(test) | ||
blocks, err := client.Block.AppendChildren(context.Background(), blockID, &updateRequest) | ||
if err != nil { | ||
log.Printf("Error while triing to add a title ... %v", err) | ||
} else { | ||
log.Printf("New Title added ... %v", blocks) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package main | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/jomei/notionapi" | ||
"github.com/stangirard/yatas/plugins/commons" | ||
) | ||
|
||
func CalculatePercent(success int, failure int) string { | ||
total := success + failure | ||
if total == 0 { | ||
return "0" | ||
} | ||
return strconv.Itoa((success * 100) / total) | ||
} | ||
|
||
func contains(s []string, e string) bool { | ||
for _, a := range s { | ||
if a == e { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
func createCategoriesBlock(test commons.Tests) notionapi.Block { | ||
// Find the categories | ||
categories := []string{} | ||
categoriesSuccess := map[string]int{} | ||
categoriesFailure := map[string]int{} | ||
for _, check := range test.Checks { | ||
for _, category := range check.Categories { | ||
if !contains(categories, category) { | ||
categories = append(categories, category) | ||
categoriesSuccess[category] = 0 | ||
categoriesFailure[category] = 0 | ||
} | ||
if check.Status == "OK" { | ||
categoriesSuccess[category]++ | ||
} else { | ||
categoriesFailure[category]++ | ||
} | ||
} | ||
} | ||
// Calculate the completion scores | ||
scores := []string{} | ||
for _, category := range categories { | ||
scores = append(scores, CalculatePercent(categoriesSuccess[category], categoriesFailure[category])+" %") | ||
} | ||
// Write the categories | ||
block := createCategorieTable(categories, scores) | ||
return block | ||
} | ||
|
||
func createCategorieTable(categories, scores []string) notionapi.Block { | ||
table := notionapi.TableBlock{ | ||
BasicBlock: notionapi.BasicBlock{ | ||
Type: notionapi.BlockType("table"), | ||
Object: notionapi.ObjectType("block"), | ||
}, | ||
Table: notionapi.Table{ | ||
TableWidth: 2, | ||
HasColumnHeader: true, | ||
Children: createCategorieTableRows(categories, scores), | ||
}, | ||
} | ||
return table | ||
} | ||
|
||
func createCategorieTableRows(categories, scores []string) []notionapi.Block { | ||
rows := []notionapi.Block{} | ||
rows = append(rows, createCategorieTableHeader()) | ||
for key, category := range categories { | ||
score := scores[key] | ||
r := createCategorieTableRow(category, score) | ||
rows = append(rows, r) | ||
} | ||
return rows | ||
} | ||
|
||
func createCategorieTableHeader() notionapi.TableRowBlock { | ||
category := notionapi.Text{ | ||
Content: "Category", | ||
} | ||
completion := notionapi.Text{ | ||
Content: "Completion", | ||
} | ||
row := notionapi.TableRowBlock{ | ||
BasicBlock: notionapi.BasicBlock{ | ||
Type: notionapi.BlockType("table_row"), | ||
Object: notionapi.ObjectType("block"), | ||
}, | ||
TableRow: notionapi.TableRow{ | ||
Cells: [][]notionapi.RichText{ | ||
{{Text: &category}}, | ||
{{Text: &completion}}, | ||
}, | ||
}, | ||
} | ||
return row | ||
} | ||
|
||
func createCategorieTableRow(category, score string) notionapi.TableRowBlock { | ||
cat := notionapi.Text{ | ||
Content: category, | ||
} | ||
completion := notionapi.Text{ | ||
Content: score, | ||
} | ||
row := notionapi.TableRowBlock{ | ||
BasicBlock: notionapi.BasicBlock{ | ||
Type: notionapi.BlockType("table_row"), | ||
Object: notionapi.ObjectType("block"), | ||
}, | ||
TableRow: notionapi.TableRow{ | ||
Cells: [][]notionapi.RichText{ | ||
{{Text: &cat}}, | ||
{{Text: &completion}}, | ||
}, | ||
}, | ||
} | ||
return row | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/jomei/notionapi" | ||
"github.com/stangirard/yatas/plugins/commons" | ||
) | ||
|
||
func updatePageRequestWithTitle(test commons.Tests) notionapi.AppendBlockChildrenRequest { | ||
categoryTitle := notionapi.Text{ | ||
Content: test.Account, | ||
} | ||
request := notionapi.AppendBlockChildrenRequest{ | ||
Children: []notionapi.Block{ | ||
notionapi.DividerBlock{ | ||
BasicBlock: notionapi.BasicBlock{ | ||
Type: notionapi.BlockType("divider"), | ||
Object: notionapi.ObjectType("block"), | ||
}, | ||
Divider: notionapi.Divider{}, | ||
}, | ||
notionapi.Heading2Block{ | ||
BasicBlock: notionapi.BasicBlock{ | ||
Type: notionapi.BlockType("heading_2"), | ||
Object: notionapi.ObjectType("block"), | ||
}, | ||
Heading2: notionapi.Heading{ | ||
RichText: []notionapi.RichText{ | ||
{ | ||
Text: &categoryTitle, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
return request | ||
} | ||
|
||
func updatePageRequestWithCategories(test commons.Tests) notionapi.AppendBlockChildrenRequest { | ||
categoryTitle := notionapi.Text{ | ||
Content: "Categories", | ||
} | ||
categoriesBlock := createCategoriesBlock(test) | ||
request := notionapi.AppendBlockChildrenRequest{ | ||
Children: []notionapi.Block{ | ||
notionapi.Heading2Block{ | ||
BasicBlock: notionapi.BasicBlock{ | ||
Type: notionapi.BlockType("heading_2"), | ||
Object: notionapi.ObjectType("block"), | ||
}, | ||
Heading2: notionapi.Heading{ | ||
RichText: []notionapi.RichText{ | ||
{ | ||
Text: &categoryTitle, | ||
}, | ||
}, | ||
}, | ||
}, | ||
categoriesBlock, | ||
}, | ||
} | ||
return request | ||
} |