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

Method fetch

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

Source from the content-addressed store, hash-verified

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