88 graphql "github.com/shurcooL/githubv4"
99
1010 "github.com/gitploy-io/gitploy/ent"
11+ "github.com/gitploy-io/gitploy/pkg/e"
1112 "github.com/gitploy-io/gitploy/vo"
1213)
1314
@@ -72,12 +73,15 @@ func (g *Github) GetCommit(ctx context.Context, u *ent.User, r *ent.Repo, sha st
7273 GetCommit (ctx , r .Namespace , r .Name , sha )
7374 // Github returns Unprocessable entity if the commit is not found.
7475 if res .StatusCode == http .StatusNotFound || res .StatusCode == http .StatusUnprocessableEntity {
75- return nil , & vo.RefNotFoundError {
76- Ref : sha ,
77- }
78- }
79- if err != nil {
80- return nil , err
76+ return nil , e .NewError (
77+ e .ErrorCodeRefNotFound ,
78+ err ,
79+ )
80+ } else if err != nil {
81+ return nil , e .NewError (
82+ e .ErrorCodeInternalError ,
83+ err ,
84+ )
8185 }
8286
8387 return mapGithubCommitToCommit (cm ), nil
@@ -93,7 +97,10 @@ func (g *Github) ListCommitStatuses(ctx context.Context, u *ent.User, r *ent.Rep
9397 PerPage : 100 ,
9498 })
9599 if err != nil {
96- return nil , err
100+ return nil , e .NewError (
101+ e .ErrorCodeInternalError ,
102+ err ,
103+ )
97104 }
98105
99106 for _ , rs := range cs .Statuses {
@@ -108,12 +115,15 @@ func (g *Github) ListCommitStatuses(ctx context.Context, u *ent.User, r *ent.Rep
108115 })
109116 // check-runs secures the commit is exist.
110117 if res .StatusCode == http .StatusUnprocessableEntity {
111- return nil , & vo.RefNotFoundError {
112- Ref : sha ,
113- }
114- }
115- if err != nil {
116- return nil , err
118+ return nil , e .NewError (
119+ e .ErrorCodeRefNotFound ,
120+ err ,
121+ )
122+ } else if err != nil {
123+ return nil , e .NewError (
124+ e .ErrorCodeInternalError ,
125+ err ,
126+ )
117127 }
118128
119129 for _ , c := range result .CheckRuns {
@@ -133,7 +143,10 @@ func (g *Github) ListBranches(ctx context.Context, u *ent.User, r *ent.Repo, pag
133143 },
134144 })
135145 if err != nil {
136- return nil , err
146+ return nil , e .NewError (
147+ e .ErrorCodeInternalError ,
148+ err ,
149+ )
137150 }
138151
139152 branches := []* vo.Branch {}
@@ -149,12 +162,15 @@ func (g *Github) GetBranch(ctx context.Context, u *ent.User, r *ent.Repo, branch
149162 Repositories .
150163 GetBranch (ctx , r .Namespace , r .Name , branch )
151164 if res .StatusCode == http .StatusNotFound {
152- return nil , & vo.RefNotFoundError {
153- Ref : branch ,
154- }
155- }
156- if err != nil {
157- return nil , err
165+ return nil , e .NewError (
166+ e .ErrorCodeRefNotFound ,
167+ err ,
168+ )
169+ } else if err != nil {
170+ return nil , e .NewError (
171+ e .ErrorCodeInternalError ,
172+ err ,
173+ )
158174 }
159175
160176 return mapGithubBranchToBranch (b ), nil
@@ -226,13 +242,17 @@ func (g *Github) GetTag(ctx context.Context, u *ent.User, r *ent.Repo, tag strin
226242 "tag" : graphql .String (tag ),
227243 }
228244 if err := client .Query (ctx , & q , v ); err != nil {
229- return nil , err
245+ return nil , e .NewError (
246+ e .ErrorCodeInternalError ,
247+ err ,
248+ )
230249 }
231250
232251 if q .Repository .Refs .TotalCount == 0 {
233- return nil , & vo.RefNotFoundError {
234- Ref : tag ,
235- }
252+ return nil , e .NewError (
253+ e .ErrorCodeRefNotFound ,
254+ nil ,
255+ )
236256 }
237257
238258 n := q .Repository .Refs .Nodes [0 ]
0 commit comments