(ctx *snap.Context)
| 1171 | } |
| 1172 | |
| 1173 | func runPRDiff(ctx *snap.Context) error { |
| 1174 | if ctx.NArgs() < 1 { |
| 1175 | fmt.Fprintf(ctx.Stderr(), "Usage: %s prDiff <github-pr-url> [--no-comments]\n", commandName) |
| 1176 | return fmt.Errorf("expected at least 1 argument, got %d", ctx.NArgs()) |
| 1177 | } |
| 1178 | |
| 1179 | ref := strings.TrimSpace(ctx.Arg(0)) |
| 1180 | if ref == "" { |
| 1181 | return fmt.Errorf("pull request URL cannot be empty") |
| 1182 | } |
| 1183 | |
| 1184 | includeComments := true |
| 1185 | for i := 1; i < ctx.NArgs(); i++ { |
| 1186 | arg := strings.TrimSpace(ctx.Arg(i)) |
| 1187 | if arg == "--no-comments" { |
| 1188 | includeComments = false |
| 1189 | } |
| 1190 | } |
| 1191 | |
| 1192 | owner, repo, prNumber, err := parsePullRequestRef(ref) |
| 1193 | if err != nil { |
| 1194 | return err |
| 1195 | } |
| 1196 | |
| 1197 | if _, err := exec.LookPath("gh"); err != nil { |
| 1198 | return fmt.Errorf("gh CLI not found in PATH: %w", err) |
| 1199 | } |
| 1200 | |
| 1201 | repoFull := fmt.Sprintf("%s/%s", owner, repo) |
| 1202 | prRef := fmt.Sprintf("%d", prNumber) |
| 1203 | |
| 1204 | var out bytes.Buffer |
| 1205 | |
| 1206 | out.WriteString(fmt.Sprintf("# Pull Request: %s#%d\n\n", repoFull, prNumber)) |
| 1207 | |
| 1208 | viewCmd := exec.Command("gh", "pr", "view", prRef, "--repo", repoFull, "--json", "title,body,author,state,baseRefName,headRefName,additions,deletions,changedFiles") |
| 1209 | viewOutput, err := viewCmd.Output() |
| 1210 | if err != nil { |
| 1211 | return fmt.Errorf("gh pr view: %w", err) |
| 1212 | } |
| 1213 | |
| 1214 | var prInfo struct { |
| 1215 | Title string `json:"title"` |
| 1216 | Body string `json:"body"` |
| 1217 | Author struct{ Login string } `json:"author"` |
| 1218 | State string `json:"state"` |
| 1219 | BaseRefName string `json:"baseRefName"` |
| 1220 | HeadRefName string `json:"headRefName"` |
| 1221 | Additions int `json:"additions"` |
| 1222 | Deletions int `json:"deletions"` |
| 1223 | ChangedFiles int `json:"changedFiles"` |
| 1224 | } |
| 1225 | |
| 1226 | if err := json.Unmarshal(viewOutput, &prInfo); err != nil { |
| 1227 | return fmt.Errorf("parse pr info: %w", err) |
| 1228 | } |
| 1229 | |
| 1230 | out.WriteString(fmt.Sprintf("## %s\n\n", prInfo.Title)) |
no test coverage detected