github.com/mentimeter/morty@v1.2.2-0.20221012065510-5596adecd154/mortems/repo_files.go (about) 1 package mortems 2 3 import "github.com/google/go-github/v35/github" 4 5 type RepoFiles struct { 6 Files []*File 7 } 8 9 type File struct { 10 Path string 11 Mode string 12 Type string 13 Content string 14 } 15 16 func (r *RepoFiles) Size() int { 17 return len(r.Files) 18 } 19 20 func (r *RepoFiles) GetFile(path string) *File { 21 for _, file := range r.Files { 22 if file.GetPath() == path { 23 return file 24 } 25 } 26 27 return nil 28 } 29 30 func (r *RepoFiles) AddFile(path, content string) { 31 file := &File{ 32 Path: path, 33 Mode: "100644", 34 Type: "blob", 35 Content: content, 36 } 37 r.Files = append(r.Files, file) 38 } 39 40 func (r *RepoFiles) AddExecutableFile(path, content string) { 41 file := &File{ 42 Path: path, 43 Mode: "100755", 44 Type: "blob", 45 Content: content, 46 } 47 r.Files = append(r.Files, file) 48 } 49 50 func (r *RepoFiles) ToTreeEntries() []*github.TreeEntry { 51 var entries []*github.TreeEntry 52 53 for _, file := range r.Files { 54 entry := &github.TreeEntry{ 55 Path: github.String(file.Path), 56 Mode: github.String(file.Mode), 57 Type: github.String(file.Type), 58 Content: github.String(file.Content), 59 } 60 entries = append(entries, entry) 61 } 62 63 return entries 64 } 65 66 func (f *File) GetContent() string { 67 return f.Content 68 } 69 70 func (f *File) GetPath() string { 71 return f.Path 72 } 73 74 func (f *File) GetMode() string { 75 return f.Mode 76 } 77 78 func (f *File) GetType() string { 79 return f.Type 80 }