MCPcopy Index your code
hub / github.com/nikivdev/go / runDiffDirect

Function runDiffDirect

cli/github/main.go:68–150  ·  view source on GitHub ↗
(ref string, extraArgs []string)

Source from the content-addressed store, hash-verified

66}
67
68func runDiffDirect(ref string, extraArgs []string) error {
69 ref = strings.TrimSpace(ref)
70 if ref == "" {
71 return fmt.Errorf("PR reference cannot be empty")
72 }
73
74 includeComments := true
75 for _, arg := range extraArgs {
76 if strings.TrimSpace(arg) == "--no-comments" {
77 includeComments = false
78 }
79 }
80
81 owner, repo, prNumber, err := parsePRRef(ref)
82 if err != nil {
83 return err
84 }
85
86 if _, err := exec.LookPath("gh"); err != nil {
87 return fmt.Errorf("gh CLI not found in PATH: %w", err)
88 }
89
90 repoFull := fmt.Sprintf("%s/%s", owner, repo)
91 prRef := fmt.Sprintf("%d", prNumber)
92
93 var out bytes.Buffer
94
95 out.WriteString(fmt.Sprintf("# Pull Request: %s#%d\n\n", repoFull, prNumber))
96
97 prInfo, err := getPRInfo(repoFull, prRef)
98 if err != nil {
99 return err
100 }
101
102 out.WriteString(fmt.Sprintf("## %s\n\n", prInfo.Title))
103 out.WriteString(fmt.Sprintf("**Author:** %s\n", prInfo.Author.Login))
104 out.WriteString(fmt.Sprintf("**State:** %s\n", prInfo.State))
105 out.WriteString(fmt.Sprintf("**Base:** %s ← **Head:** %s\n", prInfo.BaseRefName, prInfo.HeadRefName))
106 out.WriteString(fmt.Sprintf("**Stats:** +%d -%d across %d files\n\n", prInfo.Additions, prInfo.Deletions, prInfo.ChangedFiles))
107
108 if prInfo.Body != "" {
109 out.WriteString("## Description\n\n")
110 out.WriteString(prInfo.Body)
111 out.WriteString("\n\n")
112 }
113
114 if includeComments {
115 if comments, err := getPRComments(repoFull, prRef); err == nil && len(comments) > 0 {
116 out.WriteString("## Comments\n\n")
117 for i, c := range comments {
118 out.WriteString(fmt.Sprintf("### Comment %d by %s\n\n", i+1, c.Author.Login))
119 out.WriteString(c.Body)
120 out.WriteString("\n\n")
121 }
122 }
123
124 if reviews, err := getPRReviews(repoFull, prRef); err == nil && len(reviews) > 0 {
125 out.WriteString("## Reviews\n\n")

Callers 2

mainFunction · 0.85
runDiffFunction · 0.85

Calls 6

parsePRRefFunction · 0.85
getPRInfoFunction · 0.85
getPRCommentsFunction · 0.85
getPRReviewsFunction · 0.85
getPRDiffFunction · 0.85
StringMethod · 0.80

Tested by

no test coverage detected