MCPcopy Index your code
hub / github.com/bluekeyes/patch2pr / parse

Function parse

cmd/patch2pr/main.go:166–199  ·  view source on GitHub ↗
(patchFile string)

Source from the content-addressed store, hash-verified

164}
165
166func parse(patchFile string) ([]Patch, error) {
167 var r io.ReadCloser
168 if patchFile == "-" {
169 r = os.Stdin
170 } else {
171 f, err := os.Open(patchFile)
172 if err != nil {
173 return nil, fmt.Errorf("open patch file failed: %w", err)
174 }
175 r = f
176 }
177 defer closeQuitely(r)
178
179 mbr := mboxMessageReader{r: r}
180
181 var patches []Patch
182 for mbr.Next() {
183 files, preamble, err := gitdiff.Parse(&mbr)
184 if err != nil {
185 return nil, fmt.Errorf("parsing patch failed: %w", err)
186 }
187
188 var header *gitdiff.PatchHeader
189 if len(preamble) > 0 {
190 header, err = gitdiff.ParsePatchHeader(preamble)
191 if err != nil {
192 fmt.Fprintf(os.Stderr, "warning: invalid patch header: %v", err)
193 }
194 }
195
196 patches = append(patches, Patch{patchFile, files, header})
197 }
198 return patches, nil
199}
200
201func execute(ctx context.Context, client *github.Client, patchFiles []string, opts *Options) (*Result, error) {
202 targetRepo := *opts.Repository

Callers 1

executeFunction · 0.85

Calls 2

NextMethod · 0.95
closeQuitelyFunction · 0.85

Tested by

no test coverage detected