fix(gist): only include files that have changed in request

There was some issues when sending the full list of files, some of them would be truncated.
This commit is contained in:
Lucas 2025-10-30 05:49:52 +01:00
parent f8651f5e44
commit c98c435800
No known key found for this signature in database

View file

@ -214,11 +214,12 @@ func editRun(opts *EditOptions) error {
// Remove a file from the gist
if opts.RemoveFilename != "" {
err := removeFile(gistToUpdate, opts.RemoveFilename)
files, err := getFilesToRemove(gistToUpdate, opts.RemoveFilename)
if err != nil {
return err
}
gistToUpdate.Files = files
return updateGist(apiClient, host, gistToUpdate)
}
@ -339,6 +340,12 @@ func editRun(opts *EditOptions) error {
return nil
}
updatedFiles := make(map[string]*gistFileToUpdate, len(filesToUpdate))
for filename := range filesToUpdate {
updatedFiles[filename] = gistToUpdate.Files[filename]
}
gistToUpdate.Files = updatedFiles
return updateGist(apiClient, host, gistToUpdate)
}
@ -396,11 +403,13 @@ func getFilesToAdd(file string, content []byte) (map[string]*gistFileToUpdate, e
}, nil
}
func removeFile(gist gistToUpdate, filename string) error {
func getFilesToRemove(gist gistToUpdate, filename string) (map[string]*gistFileToUpdate, error) {
if _, found := gist.Files[filename]; !found {
return fmt.Errorf("gist has no file %q", filename)
return nil, fmt.Errorf("gist has no file %q", filename)
}
gist.Files[filename] = nil
return nil
return map[string]*gistFileToUpdate{
filename: nil,
}, nil
}