CreateTree creates a new tree in a repository. If both a tree and a nested path modifying that tree are specified, it will overwrite the contents of that tree with the new path contents and write a new tree out. When baseTree is provided, entries are merged with that tree: paths not mentioned in en
(ctx context.Context, owner, repo, baseTree string, entries []*TreeEntry)
| 144 | // |
| 145 | //meta:operation POST /repos/{owner}/{repo}/git/trees |
| 146 | func (s *GitService) CreateTree(ctx context.Context, owner, repo, baseTree string, entries []*TreeEntry) (*Tree, *Response, error) { |
| 147 | u := fmt.Sprintf("repos/%v/%v/git/trees", owner, repo) |
| 148 | |
| 149 | newEntries := make([]any, 0, len(entries)) |
| 150 | for _, entry := range entries { |
| 151 | if entry.Content == nil && entry.SHA == nil { |
| 152 | newEntries = append(newEntries, treeEntryWithFileDelete{ |
| 153 | Path: entry.Path, |
| 154 | Mode: entry.Mode, |
| 155 | Type: entry.Type, |
| 156 | Size: entry.Size, |
| 157 | URL: entry.URL, |
| 158 | }) |
| 159 | continue |
| 160 | } |
| 161 | newEntries = append(newEntries, entry) |
| 162 | } |
| 163 | |
| 164 | body := &createTree{ |
| 165 | BaseTree: baseTree, |
| 166 | Entries: newEntries, |
| 167 | } |
| 168 | req, err := s.client.NewRequest(ctx, "POST", u, body) |
| 169 | if err != nil { |
| 170 | return nil, nil, err |
| 171 | } |
| 172 | |
| 173 | var t *Tree |
| 174 | resp, err := s.client.Do(req, &t) |
| 175 | if err != nil { |
| 176 | return nil, resp, err |
| 177 | } |
| 178 | |
| 179 | return t, resp, nil |
| 180 | } |