|
4 | 4 | package template |
5 | 5 |
|
6 | 6 | import ( |
| 7 | + "context" |
7 | 8 | "fmt" |
8 | 9 | "io" |
9 | 10 | "path" |
@@ -42,31 +43,31 @@ func Unmarshal(filename string, content []byte) (*api.IssueTemplate, error) { |
42 | 43 | } |
43 | 44 |
|
44 | 45 | // UnmarshalFromEntry parses out a valid template from the blob in entry |
45 | | -func UnmarshalFromEntry(entry *git.TreeEntry, dir string) (*api.IssueTemplate, error) { |
46 | | - return unmarshalFromEntry(entry, path.Join(dir, entry.Name())) // Filepaths in Git are ALWAYS '/' separated do not use filepath here |
| 46 | +func UnmarshalFromEntry(ctx context.Context, entry *git.TreeEntry, dir string) (*api.IssueTemplate, error) { |
| 47 | + return unmarshalFromEntry(ctx, entry, path.Join(dir, entry.Name())) // Filepaths in Git are ALWAYS '/' separated do not use filepath here |
47 | 48 | } |
48 | 49 |
|
49 | 50 | // UnmarshalFromCommit parses out a valid template from the commit |
50 | | -func UnmarshalFromCommit(commit *git.Commit, filename string) (*api.IssueTemplate, error) { |
| 51 | +func UnmarshalFromCommit(ctx context.Context, commit *git.Commit, filename string) (*api.IssueTemplate, error) { |
51 | 52 | entry, err := commit.GetTreeEntryByPath(filename) |
52 | 53 | if err != nil { |
53 | 54 | return nil, fmt.Errorf("get entry for %q: %w", filename, err) |
54 | 55 | } |
55 | | - return unmarshalFromEntry(entry, filename) |
| 56 | + return unmarshalFromEntry(ctx, entry, filename) |
56 | 57 | } |
57 | 58 |
|
58 | 59 | // UnmarshalFromRepo parses out a valid template from the head commit of the branch |
59 | | -func UnmarshalFromRepo(repo *git.Repository, branch, filename string) (*api.IssueTemplate, error) { |
| 60 | +func UnmarshalFromRepo(ctx context.Context, repo *git.Repository, branch, filename string) (*api.IssueTemplate, error) { |
60 | 61 | commit, err := repo.GetBranchCommit(branch) |
61 | 62 | if err != nil { |
62 | 63 | return nil, fmt.Errorf("get commit on branch %q: %w", branch, err) |
63 | 64 | } |
64 | 65 |
|
65 | | - return UnmarshalFromCommit(commit, filename) |
| 66 | + return UnmarshalFromCommit(ctx, commit, filename) |
66 | 67 | } |
67 | 68 |
|
68 | | -func unmarshalFromEntry(entry *git.TreeEntry, filename string) (*api.IssueTemplate, error) { |
69 | | - if size := entry.Blob().Size(); size > setting.UI.MaxDisplayFileSize { |
| 69 | +func unmarshalFromEntry(ctx context.Context, entry *git.TreeEntry, filename string) (*api.IssueTemplate, error) { |
| 70 | + if size := entry.Blob().Size(ctx); size > setting.UI.MaxDisplayFileSize { |
70 | 71 | return nil, fmt.Errorf("too large: %v > MaxDisplayFileSize", size) |
71 | 72 | } |
72 | 73 |
|
|
0 commit comments