deleteFile deletes a file from a Git tree and returns any applicable errors. If an empty SHA is passed as an argument, errFileNotFound is returned.
(filename string, sha string)
| 174 | // deleteFile deletes a file from a Git tree and returns any applicable errors. |
| 175 | // If an empty SHA is passed as an argument, errFileNotFound is returned. |
| 176 | func (gh *Storage) deleteFile(filename string, sha string) error { |
| 177 | if err := gh.ensureClient(); err != nil { |
| 178 | return err |
| 179 | } |
| 180 | |
| 181 | if sha == "" { |
| 182 | return errFileNotFound |
| 183 | } |
| 184 | |
| 185 | log.Printf("github: deleting %s on branch '%s'", gh.fullPathName(filename), gh.Branch) |
| 186 | |
| 187 | _, _, err := gh.client.Repositories.DeleteFile( |
| 188 | context.Background(), |
| 189 | gh.RepositoryOwner, |
| 190 | gh.RepositoryName, |
| 191 | gh.fullPathName(filename), |
| 192 | &github.RepositoryContentFileOptions{ |
| 193 | Message: github.String(fmt.Sprintf("[checkup] delete %s [ci skip]", gh.fullPathName(filename))), |
| 194 | SHA: github.String(sha), |
| 195 | Branch: &gh.Branch, |
| 196 | Committer: &github.CommitAuthor{ |
| 197 | Name: &gh.CommitterName, |
| 198 | Email: &gh.CommitterEmail, |
| 199 | }, |
| 200 | }, |
| 201 | ) |
| 202 | if err != nil { |
| 203 | return err |
| 204 | } |
| 205 | |
| 206 | return nil |
| 207 | } |
| 208 | |
| 209 | // readIndex reads the index JSON from the Git repo into a map. |
| 210 | // It returns the populated map & the Git SHA associated with the contents. |