| 35 | } |
| 36 | |
| 37 | func (g *GithubPRReader) Run(ctx context.Context, sharedState *types.AgentSharedState, params types.ActionParams) (types.ActionResult, error) { |
| 38 | result := struct { |
| 39 | Repository string `json:"repository"` |
| 40 | Owner string `json:"owner"` |
| 41 | PRNumber int `json:"pr_number"` |
| 42 | }{} |
| 43 | err := params.Unmarshal(&result) |
| 44 | if err != nil { |
| 45 | return types.ActionResult{}, err |
| 46 | } |
| 47 | |
| 48 | if g.repository != "" && g.owner != "" { |
| 49 | result.Repository = g.repository |
| 50 | result.Owner = g.owner |
| 51 | } |
| 52 | |
| 53 | pr, _, err := g.client.PullRequests.Get(ctx, result.Owner, result.Repository, result.PRNumber) |
| 54 | if err != nil { |
| 55 | return types.ActionResult{Result: fmt.Sprintf("Error fetching pull request: %s", err.Error())}, err |
| 56 | } |
| 57 | if pr == nil { |
| 58 | return types.ActionResult{Result: fmt.Sprintf("No pull request found")}, nil |
| 59 | } |
| 60 | |
| 61 | // Get the list of changed files |
| 62 | files, _, err := g.client.PullRequests.ListFiles(ctx, result.Owner, result.Repository, result.PRNumber, &github.ListOptions{}) |
| 63 | if err != nil { |
| 64 | return types.ActionResult{Result: fmt.Sprintf("Error fetching pull request files: %s", err.Error())}, err |
| 65 | } |
| 66 | |
| 67 | // Get CI status information |
| 68 | ciStatus := "\n\nCI Status:\n" |
| 69 | |
| 70 | // Get PR status checks |
| 71 | checkRuns, _, err := g.client.Checks.ListCheckRunsForRef(ctx, result.Owner, result.Repository, pr.GetHead().GetSHA(), &github.ListCheckRunsOptions{}) |
| 72 | if err == nil && checkRuns != nil { |
| 73 | ciStatus += fmt.Sprintf("\nPR Status Checks:\n") |
| 74 | ciStatus += fmt.Sprintf("Total Checks: %d\n", checkRuns.GetTotal()) |
| 75 | for _, check := range checkRuns.CheckRuns { |
| 76 | ciStatus += fmt.Sprintf("- %s: %s (%s)\n", |
| 77 | check.GetName(), |
| 78 | check.GetConclusion(), |
| 79 | check.GetStatus()) |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | // Build the file changes summary with patches |
| 84 | fileChanges := "\n\nFile Changes:\n" |
| 85 | for _, file := range files { |
| 86 | fileChanges += fmt.Sprintf("\n--- %s\n+++ %s\n", file.GetFilename(), file.GetFilename()) |
| 87 | if g.showFullDiff && file.GetPatch() != "" { |
| 88 | fileChanges += file.GetPatch() |
| 89 | } |
| 90 | fileChanges += fmt.Sprintf("\n(%d additions, %d deletions)\n", file.GetAdditions(), file.GetDeletions()) |
| 91 | } |
| 92 | |
| 93 | return types.ActionResult{ |
| 94 | Result: fmt.Sprintf( |