MCPcopy Create free account
hub / github.com/cli/cli / diffRun

Function diffRun

pkg/cmd/pr/diff/diff.go:127–210  ·  view source on GitHub ↗
(opts *DiffOptions)

Source from the content-addressed store, hash-verified

125}
126
127func diffRun(opts *DiffOptions) error {
128 findOptions := shared.FindOptions{
129 Selector: opts.SelectorArg,
130 Fields: []string{"number"},
131 }
132
133 if opts.BrowserMode {
134 findOptions.Fields = []string{"url"}
135 }
136
137 pr, baseRepo, err := opts.Finder.Find(findOptions)
138 if err != nil {
139 return err
140 }
141
142 if opts.BrowserMode {
143 openUrl := fmt.Sprintf("%s/files", pr.URL)
144 if opts.IO.IsStdoutTTY() {
145 fmt.Fprintf(opts.IO.ErrOut, "Opening %s in your browser.\n", text.DisplayURL(openUrl))
146 }
147 return opts.Browser.Browse(openUrl)
148 }
149
150 httpClient, err := opts.HttpClient()
151 if err != nil {
152 return err
153 }
154
155 if opts.NameOnly {
156 opts.Patch = false
157 }
158
159 diffReadCloser, err := fetchDiff(httpClient, baseRepo, pr.Number, opts.Patch)
160 if err != nil {
161 return fmt.Errorf("could not find pull request diff: %w", err)
162 }
163 defer diffReadCloser.Close()
164
165 var diff io.Reader = diffReadCloser
166 if len(opts.Exclude) > 0 {
167 filtered, err := filterDiff(diff, opts.Exclude)
168 if err != nil {
169 return err
170 }
171 diff = filtered
172 }
173 // A terminal shows escape sequences inert through ContentOut; piped output is
174 // faithful, so a diff carrying escape sequences is refused rather than silently
175 // altered. --allow-escape-sequences streams raw on both. The colored path
176 // always neutralizes, since it is terminal-bound.
177 if opts.AllowEscapeSequences {
178 opts.IO.SetContentSanitization(false)
179 }
180
181 if err := opts.IO.StartPager(); err == nil {
182 defer opts.IO.StopPager()
183 } else {
184 fmt.Fprintf(opts.IO.ErrOut, "failed to start pager: %v\n", err)

Callers 2

NewCmdDiffFunction · 0.85
Test_diffRunFunction · 0.85

Calls 15

DisplayURLFunction · 0.92
ContainsEscapeSequenceFunction · 0.92
fetchDiffFunction · 0.85
filterDiffFunction · 0.85
changedFilesNamesFunction · 0.85
colorDiffLinesFunction · 0.85
sanitizedReaderFunction · 0.85
IsStdoutTTYMethod · 0.80
StartPagerMethod · 0.80
StopPagerMethod · 0.80
FindMethod · 0.65

Tested by 1

Test_diffRunFunction · 0.68