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

Function ReadContent

pkg/cmd/issue/artifact/shared/content.go:24–45  ·  view source on GitHub ↗

ReadContent reads an artifact's new content from the file at path, following a symlink, or from stdin when path is "-". It also returns the directory the content's references to attached files resolve against, which is empty for stdin, as cmdutil.ReadMarkdownBodyFile gives it. Artifact content must

(path string, stdin io.ReadCloser)

Source from the content-addressed store, hash-verified

22// doesn't name path, so a caller can say which artifact failed in its own
23// words.
24func ReadContent(path string, stdin io.ReadCloser) (content, dir string, err error) {
25 what := "file"
26 if path == "-" {
27 what = "input"
28 }
29
30 content, dir, err = cmdutil.ReadMarkdownBodyFile(path, stdin)
31 if err != nil {
32 if pathErr, ok := errors.AsType[*fs.PathError](err); ok && pathErr.Path == path {
33 return "", "", pathErr.Err
34 }
35 return "", "", err
36 }
37
38 if strings.TrimSpace(content) == "" {
39 return "", "", fmt.Errorf("%s is empty", what)
40 }
41 if gistShared.IsBinaryContents([]byte(content)) {
42 return "", "", fmt.Errorf("binary %s not supported", what)
43 }
44 return content, dir, nil
45}
46
47// IsShortcutFile reports whether path is an Internet Shortcut file, which
48// artifact commands read as a link. Like Windows, it goes by the .url

Callers 3

readSourceFunction · 0.92
readContentFunction · 0.92
TestReadContentFunction · 0.85

Calls 2

ReadMarkdownBodyFileFunction · 0.92
ErrorfMethod · 0.65

Tested by 1

TestReadContentFunction · 0.68