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

Function restoreVersion

pkg/cmd/issue/artifact/edit/edit.go:231–254  ·  view source on GitHub ↗

restoreVersion saves the name and body of version opts.RestoreVersion as a new version. They are sent as the API returned them, so the server checks them like any other edit. Every save adds a version to the edit history, even when nothing changed, so nothing is saved when the artifact already match

(opts *EditOptions, c client.ArtifactClient, repo ghrepo.Interface, current *client.ArtifactWithVersions, result shared.Result, action string)

Source from the content-addressed store, hash-verified

229// even when nothing changed, so nothing is saved when the artifact already
230// matches the version.
231func restoreVersion(opts *EditOptions, c client.ArtifactClient, repo ghrepo.Interface, current *client.ArtifactWithVersions, result shared.Result, action string) error {
232 v, err := shared.FindVersion(current, opts.RestoreVersion)
233 if err != nil {
234 return err
235 }
236 // FindVersion returns nil for the current version, which the artifact
237 // matches.
238 if v == nil || (v.Name == current.Name && v.Body == current.Body) {
239 message := fmt.Sprintf("Artifact %d (%s) on %s#%d already matches version %d", opts.ArtifactNumber, result.Name, ghrepo.FullName(repo), opts.IssueNumber, opts.RestoreVersion)
240 shared.PrintUnchanged(opts.IO, result, message, fmt.Sprintf("already matches version %d", opts.RestoreVersion))
241 return nil
242 }
243
244 updated, err := c.Update(repo, opts.IssueNumber, opts.ArtifactNumber, &v.Name, &v.Body)
245 if err != nil {
246 shared.PrintFailure(opts.IO, result, action, err)
247 return cmdutil.SilentError
248 }
249
250 result.Name = text.RemoveExcessiveWhitespace(updated.Name)
251 message := fmt.Sprintf("Restored artifact %d (%s) to version %d on %s#%d", opts.ArtifactNumber, result.Name, opts.RestoreVersion, ghrepo.FullName(repo), opts.IssueNumber)
252 shared.PrintSuccess(opts.IO, "restored", result, opts.IO.ColorScheme().SuccessIcon(), message)
253 return nil
254}
255
256// readContent returns the new content from --body or --body-file, or nil
257// when neither was given, and the directory a --body-file's references

Callers 1

editRunFunction · 0.85

Calls 9

FindVersionFunction · 0.92
FullNameFunction · 0.92
PrintUnchangedFunction · 0.92
PrintFailureFunction · 0.92
PrintSuccessFunction · 0.92
SuccessIconMethod · 0.80
ColorSchemeMethod · 0.80
UpdateMethod · 0.65

Tested by

no test coverage detected