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

Function writeExportDir

script/ghmock/export.go:100–145  ·  view source on GitHub ↗
(st *state, dir string, runs []runRecord, entries []loggedRequest, responses responseSet)

Source from the content-addressed store, hash-verified

98}
99
100func writeExportDir(st *state, dir string, runs []runRecord, entries []loggedRequest, responses responseSet) error {
101 if err := prepareExportDir(dir); err != nil {
102 return err
103 }
104 files := []struct {
105 name string
106 write func(io.Writer) error
107 }{
108 {"README.md", func(w io.Writer) error {
109 _, err := io.WriteString(w, exportReadme())
110 return err
111 }},
112 {"report.txt", func(w io.Writer) error { return writeExportReport(w, runs) }},
113 {"runs.jsonl", func(w io.Writer) error { return writeJSONL(w, runs) }},
114 {"requests.jsonl", func(w io.Writer) error { return writeJSONL(w, entries) }},
115 {"responses.json", func(w io.Writer) error {
116 data, err := json.MarshalIndent(responses, "", " ")
117 if err != nil {
118 return err
119 }
120 _, err = w.Write(append(data, '\n'))
121 return err
122 }},
123 }
124 for _, f := range files {
125 if err := writeFile(filepath.Join(dir, f.name), f.write); err != nil {
126 return err
127 }
128 }
129 if _, err := os.Stat(filepath.Join(st.dir, "git")); err == nil {
130 if err := copyGitTree(filepath.Join(st.dir, "git"), filepath.Join(dir, "git")); err != nil {
131 return fmt.Errorf("exporting Git fixtures and workspaces: %w", err)
132 }
133 } else if !errors.Is(err, fs.ErrNotExist) {
134 return err
135 }
136 if _, err := os.Stat(filepath.Join(st.dir, "config")); err == nil {
137 if err := copyConfigTree(filepath.Join(st.dir, "config"), filepath.Join(dir, "config")); err != nil {
138 return fmt.Errorf("exporting configuration fixtures: %w", err)
139 }
140 } else if !errors.Is(err, fs.ErrNotExist) {
141 return err
142 }
143
144 return nil
145}
146
147// prepareExportDir creates dir, or checks that it's empty, so an export never
148// mixes with other files.

Callers 1

cmdExportFunction · 0.85

Calls 10

prepareExportDirFunction · 0.85
exportReadmeFunction · 0.85
writeExportReportFunction · 0.85
writeJSONLFunction · 0.85
copyGitTreeFunction · 0.85
copyConfigTreeFunction · 0.85
JoinMethod · 0.80
writeFileFunction · 0.70
WriteMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected