MCPcopy
hub / github.com/cli/cli / fetch

Method fetch

pkg/cmd/pr/shared/templates.go:240–291  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

238}
239
240func (m *templateManager) fetch() error {
241 hasAPI, err := m.hasAPI()
242 if err != nil {
243 return err
244 }
245
246 if hasAPI {
247 lister := listIssueTemplates
248 if m.isPR {
249 lister = listPullRequestTemplates
250 }
251 templates, err := lister(m.httpClient, m.repo)
252 if err != nil {
253 return err
254 }
255 m.templates = templates
256 }
257
258 if !m.allowFS {
259 return nil
260 }
261
262 dir := m.rootDir
263 if dir == "" {
264 var err error
265 gitClient := &git.Client{}
266 dir, err = gitClient.ToplevelDir(context.Background())
267 if err != nil {
268 //nolint:nilerr // intentional, abort silently
269 return nil
270 }
271 }
272
273 filePattern := "ISSUE_TEMPLATE"
274 if m.isPR {
275 filePattern = "PULL_REQUEST_TEMPLATE"
276 }
277
278 if !hasAPI {
279 issueTemplates := githubtemplate.FindNonLegacy(dir, filePattern)
280 m.templates = make([]Template, len(issueTemplates))
281 for i, t := range issueTemplates {
282 m.templates[i] = &filesystemTemplate{path: t}
283 }
284 }
285
286 if legacyTemplate := githubtemplate.FindLegacy(dir, filePattern); legacyTemplate != "" {
287 m.legacyTemplate = &filesystemTemplate{path: legacyTemplate}
288 }
289
290 return nil
291}
292
293type filesystemTemplate struct {
294 path string

Callers 1

memoizedFetchMethod · 0.95

Calls 5

hasAPIMethod · 0.95
ToplevelDirMethod · 0.95
FindNonLegacyFunction · 0.92
FindLegacyFunction · 0.92
listerStruct · 0.85

Tested by

no test coverage detected