1package types
2
3import (
4 "encoding/json"
5
6 "github.com/bluekeyes/go-gitdiff/gitdiff"
7 "github.com/go-git/go-git/v5/plumbing/object"
8)
9
10type RepoIndexResponse struct {
11 IsEmpty bool `json:"is_empty"`
12 Ref string `json:"ref,omitempty"`
13 Readme string `json:"readme,omitempty"`
14 ReadmeFileName string `json:"readme_file_name,omitempty"`
15 Commits []*object.Commit `json:"commits,omitempty"`
16 Description string `json:"description,omitempty"`
17 Files []NiceTree `json:"files,omitempty"`
18 Branches []Branch `json:"branches,omitempty"`
19 Tags []*TagReference `json:"tags,omitempty"`
20 TotalCommits int `json:"total_commits,omitempty"`
21}
22
23type RepoLogResponse struct {
24 Commits []*object.Commit `json:"commits,omitempty"`
25 Ref string `json:"ref,omitempty"`
26 Description string `json:"description,omitempty"`
27 Log bool `json:"log,omitempty"`
28 Total int `json:"total,omitempty"`
29 Page int `json:"page,omitempty"`
30 PerPage int `json:"per_page,omitempty"`
31}
32
33type RepoCommitResponse struct {
34 Ref string `json:"ref,omitempty"`
35 Diff *NiceDiff `json:"diff,omitempty"`
36}
37
38type RepoFormatPatchResponse struct {
39 Rev1 string `json:"rev1,omitempty"`
40 Rev2 string `json:"rev2,omitempty"`
41 FormatPatch []FormatPatch `json:"format_patch,omitempty"`
42 FormatPatchRaw string `json:"patch,omitempty"`
43 CombinedPatch []*gitdiff.File `json:"combined_patch,omitempty"`
44 CombinedPatchRaw string `json:"combined_patch_raw,omitempty"`
45}
46
47type RepoTreeResponse struct {
48 Ref string `json:"ref,omitempty"`
49 Parent string `json:"parent,omitempty"`
50 Description string `json:"description,omitempty"`
51 DotDot string `json:"dotdot,omitempty"`
52 Files []NiceTree `json:"files,omitempty"`
53 ReadmeFileName string `json:"readme_filename,omitempty"`
54 Readme string `json:"readme_contents,omitempty"`
55}
56
57type TagReference struct {
58 Reference
59 Tag *object.Tag `json:"tag,omitempty"`
60 Message string `json:"message,omitempty"`
61}
62
63type Reference struct {
64 Name string `json:"name"`
65 Hash string `json:"hash"`
66}
67
68type Branch struct {
69 Reference `json:"reference"`
70 Commit *object.Commit `json:"commit,omitempty"`
71 IsDefault bool `json:"is_default,omitempty"`
72}
73
74func (b *Branch) UnmarshalJSON(data []byte) error {
75 aux := &struct {
76 Reference `json:"reference"`
77 Commit *object.Commit `json:"commit,omitempty"`
78 IsDefault bool `json:"is_default,omitempty"`
79 MispelledIsDefault bool `json:"is_deafult,omitempty"` // mispelled name
80 }{}
81
82 if err := json.Unmarshal(data, aux); err != nil {
83 return err
84 }
85
86 b.Reference = aux.Reference
87 b.Commit = aux.Commit
88 b.IsDefault = aux.IsDefault || aux.MispelledIsDefault // whichever was set
89
90 return nil
91}
92
93type RepoTagsResponse struct {
94 Tags []*TagReference `json:"tags,omitempty"`
95}
96
97type RepoBranchesResponse struct {
98 Branches []Branch `json:"branches,omitempty"`
99}
100
101type RepoBranchResponse struct {
102 Branch Branch
103}
104
105type RepoDefaultBranchResponse struct {
106 Branch string `json:"branch,omitempty"`
107}
108
109type RepoBlobResponse struct {
110 Contents string `json:"contents,omitempty"`
111 Ref string `json:"ref,omitempty"`
112 Path string `json:"path,omitempty"`
113 IsBinary bool `json:"is_binary,omitempty"`
114
115 Lines int `json:"lines,omitempty"`
116 SizeHint uint64 `json:"size_hint,omitempty"`
117}
118
119type ForkStatus int
120
121const (
122 UpToDate ForkStatus = 0
123 FastForwardable = 1
124 Conflict = 2
125 MissingBranch = 3
126)
127
128type ForkInfo struct {
129 IsFork bool
130 Status ForkStatus
131}
132
133type AncestorCheckResponse struct {
134 Status ForkStatus `json:"status"`
135}
136
137type RepoLanguageDetails struct {
138 Name string
139 Percentage float32
140 Color string
141}
142
143type RepoLanguageResponse struct {
144 // Language: File count
145 Languages map[string]int64 `json:"languages"`
146}