Skip to content

Commit

Permalink
feat: retain workflow order from config
Browse files Browse the repository at this point in the history
  • Loading branch information
dhth committed Aug 20, 2024
1 parent cd4c3c9 commit 7ac07ae
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
28 changes: 22 additions & 6 deletions cmd/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,39 @@ import (
)

func render(workflows []types.Workflow, config types.Config) error {
results := make([]gh.ResultData, len(workflows))
resultsMap := make(map[string]gh.ResultData)
resultChannel := make(chan gh.ResultData)
var results []gh.ResultData

for _, wf := range workflows {
go func(workflow types.Workflow) {
resultChannel <- gh.GetWorkflowRuns(config.GHClient, workflow)
}(wf)
}

for i := range workflows {
for range workflows {
r := <-resultChannel
results[i] = r
resultsMap[r.Workflow.ID] = r
}

sort.Slice(results, func(i, j int) bool {
return results[i].Workflow.Name < results[j].Workflow.Name
})
if config.CurrentRepo != nil {
var resultsList []gh.ResultData
for _, r := range resultsMap {
resultsList = append(resultsList, r)
}
// sort workflows alphabetically
sort.Slice(resultsList, func(i, j int) bool {
return resultsList[i].Workflow.Name < resultsList[j].Workflow.Name
})
results = resultsList
} else {
// sort workflows in the sequence of the config file
resultsInConfigDefinedOrder := make([]gh.ResultData, len(workflows))
for i, w := range workflows {
resultsInConfigDefinedOrder[i] = resultsMap[w.ID]
}
results = resultsInConfigDefinedOrder
}

output, err := ui.GetOutput(config, results)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/ui/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func getTabularOutput(config types.Config, results []gh.ResultData) string {
resultsDate := "(" + rr.CreatedAt.Time.Format(dateFormat) + ")"
var conclusion string
if !rr.CheckSuite.FinishedSuccessfully() {
conclusion = fmt.Sprintf(" %s ", rr.CheckSuite.ConclusionOrState())
conclusion = fmt.Sprintf(" %s", rr.CheckSuite.ConclusionOrState())
}
row = append(row, fmt.Sprintf("%s%s%s",
RightPadTrim(fmt.Sprintf("#%d", rr.RunNumber), runNumberPadding),
Expand Down

0 comments on commit 7ac07ae

Please sign in to comment.