-
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: allow opening failed workflows (#12)
- Loading branch information
Showing
14 changed files
with
164 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ permissions: | |
contents: read | ||
|
||
env: | ||
GO_VERSION: '1.23.4' | ||
GO_VERSION: '1.23.5' | ||
|
||
jobs: | ||
build: | ||
|
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 |
---|---|---|
|
@@ -13,7 +13,7 @@ permissions: | |
contents: read | ||
|
||
env: | ||
GO_VERSION: '1.23.4' | ||
GO_VERSION: '1.23.5' | ||
|
||
jobs: | ||
lint: | ||
|
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 |
---|---|---|
|
@@ -9,7 +9,7 @@ permissions: | |
id-token: write | ||
|
||
env: | ||
GO_VERSION: '1.23.4' | ||
GO_VERSION: '1.23.5' | ||
|
||
jobs: | ||
release: | ||
|
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 |
---|---|---|
|
@@ -14,7 +14,7 @@ permissions: | |
contents: read | ||
|
||
env: | ||
GO_VERSION: '1.23.4' | ||
GO_VERSION: '1.23.5' | ||
|
||
jobs: | ||
vulncheck: | ||
|
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
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,33 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/dhth/act3/internal/gh" | ||
"github.com/dhth/act3/internal/utils" | ||
) | ||
|
||
func openFailedWorkflows(results []gh.ResultData, goos string) { | ||
var urls []string | ||
for _, r := range results { | ||
if r.Err != nil { | ||
continue | ||
} | ||
|
||
for _, rr := range r.Result.Workflow.Runs.Nodes { | ||
if rr.CheckSuite.IsAFailure() { | ||
urls = append(urls, rr.URL) | ||
} | ||
} | ||
} | ||
|
||
if len(urls) == 0 { | ||
return | ||
} | ||
|
||
err := utils.OpenURLsInBrowser(urls, goos) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "error opening URLs: %s", err.Error()) | ||
} | ||
} |
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,46 @@ | ||
package cmd | ||
|
||
import ( | ||
"sort" | ||
|
||
"github.com/dhth/act3/internal/gh" | ||
"github.com/dhth/act3/internal/types" | ||
) | ||
|
||
func getResults(workflows []types.Workflow, config types.Config) []gh.ResultData { | ||
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 range workflows { | ||
r := <-resultChannel | ||
resultsMap[r.Workflow.ID] = r | ||
} | ||
|
||
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 | ||
} | ||
|
||
return results | ||
} |
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
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
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,17 @@ | ||
package utils | ||
|
||
import ( | ||
"os/exec" | ||
) | ||
|
||
func OpenURLsInBrowser(urls []string, goos string) error { | ||
var openCmd string | ||
switch goos { | ||
case "darwin": | ||
openCmd = "open" | ||
default: | ||
openCmd = "xdg-open" | ||
} | ||
c := exec.Command(openCmd, urls...) | ||
return c.Run() | ||
} |