From 5dec0bce18539d35bf052027bff33d27cea83f9c Mon Sep 17 00:00:00 2001 From: eyedeekay Date: Mon, 5 May 2025 18:22:30 -0400 Subject: [PATCH] Add support for repository actions --- pkg/api/cache.go | 1 + pkg/api/github.go | 59 ++++++++++++++++++++++++++++++++ pkg/cmd/generate.go | 7 ++++ pkg/generator/html.go | 71 +++++++++++++++++++++++++++++++++++++++ pkg/generator/markdown.go | 11 ++++++ pkg/types/types.go | 36 ++++++++++++++------ 6 files changed, 175 insertions(+), 10 deletions(-) diff --git a/pkg/api/cache.go b/pkg/api/cache.go index fedd73d..4dff61b 100644 --- a/pkg/api/cache.go +++ b/pkg/api/cache.go @@ -32,6 +32,7 @@ func NewCache(config *types.Config) *Cache { gob.Register([]types.PullRequest{}) gob.Register([]types.Issue{}) gob.Register([]types.Discussion{}) + gob.Register([]types.WorkflowRun{}) cache := &Cache{ items: make(map[string]CacheItem), diff --git a/pkg/api/github.go b/pkg/api/github.go index 6fd542e..fa0754f 100644 --- a/pkg/api/github.go +++ b/pkg/api/github.go @@ -221,6 +221,42 @@ func (g *GitHubClient) GetDiscussions(ctx context.Context, owner, repo string) ( return []types.Discussion{}, nil } +// GetWorkflowRuns fetches recent workflow runs for a repository +func (g *GitHubClient) GetWorkflowRuns(ctx context.Context, owner, repo string) ([]types.WorkflowRun, error) { + var allRuns []types.WorkflowRun + cacheKey := fmt.Sprintf("workflow_runs_%s_%s", owner, repo) + + // Try to get from cache first + if cachedRuns, found := g.cache.Get(cacheKey); found { + if g.config.Verbose { + log.Printf("Using cached workflow runs for %s/%s", owner, repo) + } + return cachedRuns.([]types.WorkflowRun), nil + } + + if g.config.Verbose { + log.Printf("Fetching workflow runs for %s/%s", owner, repo) + } + + opts := &github.ListWorkflowRunsOptions{ + ListOptions: github.ListOptions{PerPage: 10}, // Limit to 10 most recent runs + } + + runs, _, err := g.client.Actions.ListRepositoryWorkflowRuns(ctx, owner, repo, opts) + if err != nil { + return nil, fmt.Errorf("error fetching workflow runs: %w", err) + } + + for _, run := range runs.WorkflowRuns { + allRuns = append(allRuns, convertWorkflowRun(run)) + } + + // Cache the results + g.cache.Set(cacheKey, allRuns) + + return allRuns, nil +} + // Helper functions to convert GitHub API types to our domain types func convertRepository(repo *github.Repository) types.Repository { r := types.Repository{ @@ -294,3 +330,26 @@ func convertIssue(issue *github.Issue) types.Issue { return i } + +// Helper function to convert GitHub API types to our domain types +func convertWorkflowRun(run *github.WorkflowRun) types.WorkflowRun { + workflowRun := types.WorkflowRun{ + ID: run.GetID(), + Name: run.GetName(), + URL: run.GetHTMLURL(), + Status: run.GetStatus(), + Conclusion: run.GetConclusion(), + RunNumber: run.GetRunNumber(), + Branch: run.GetHeadBranch(), + } + + if run.CreatedAt != nil { + workflowRun.CreatedAt = run.CreatedAt.Time + } + + if run.UpdatedAt != nil { + workflowRun.UpdatedAt = run.UpdatedAt.Time + } + + return workflowRun +} diff --git a/pkg/cmd/generate.go b/pkg/cmd/generate.go index 101a608..3aa6e40 100644 --- a/pkg/cmd/generate.go +++ b/pkg/cmd/generate.go @@ -136,10 +136,17 @@ func runGenerate() error { log.Printf("Error fetching discussions for %s/%s: %v", owner, repoName, err) } + // Fetch workflow runs + workflowRuns, err := githubClient.GetWorkflowRuns(ctx, owner, repoName) + if err != nil { + log.Printf("Error fetching workflow runs for %s/%s: %v", owner, repoName, err) + } + // Update the repository with the fetched data repo.PullRequests = pullRequests repo.Issues = issues repo.Discussions = discussions + repo.WorkflowRuns = workflowRuns // Send the updated repository to the channel reposChan <- repo diff --git a/pkg/generator/html.go b/pkg/generator/html.go index fd75333..fdf0415 100644 --- a/pkg/generator/html.go +++ b/pkg/generator/html.go @@ -39,6 +39,7 @@ func NewHTMLGenerator(config *types.Config) (*HTMLGenerator, error) { {{.TotalPRs}} open pull requests {{.TotalIssues}} open issues {{.TotalDiscussions}} recent discussions + {{.TotalWorkflowRuns}} recent workflow runs

Generated on {{.GeneratedAt.Format "January 2, 2006 at 15:04"}}

@@ -57,6 +58,7 @@ func NewHTMLGenerator(config *types.Config) (*HTMLGenerator, error) { {{len .PullRequests}} PRs {{len .Issues}} issues {{len .Discussions}} discussions + {{len .WorkflowRuns}} workflows
@@ -162,6 +164,51 @@ func NewHTMLGenerator(config *types.Config) (*HTMLGenerator, error) {
{{end}} + {{if .WorkflowRuns}} +
+ + +
+ + + + + + + + + + + + {{range .WorkflowRuns}} + + + + + + + + {{end}} + +
WorkflowBranchStatusRun #Created
{{.Name}}{{.Branch}} + {{if eq .Status "completed"}} + {{if eq .Conclusion "success"}}✅ Success{{end}} + {{if eq .Conclusion "failure"}}❌ Failure{{end}} + {{if eq .Conclusion "cancelled"}}⚪ Cancelled{{end}} + {{if eq .Conclusion "skipped"}}⏭️ Skipped{{end}} + {{if eq .Conclusion "timed_out"}}⏱️ Timed Out{{end}} + {{if eq .Conclusion ""}}⚪ {{.Status}}{{end}} + {{else}} + {{if eq .Status "in_progress"}}🔄 In Progress{{end}} + {{if eq .Status "queued"}}⏳ Queued{{end}} + {{if eq .Status ""}}⚪ Unknown{{end}} + {{end}} + {{.RunNumber}}{{.CreatedAt.Format "2006-01-02 15:04"}}
+
+
+ {{end}}