Skip to content

Commit 7f5a047

Browse files
Added get languages func in drivers (#13)
* added list repo language in github * added check langugae support functionality in repo gitlab * added check langugae support functionality in repo gitlab
1 parent 3e705ed commit 7f5a047

File tree

9 files changed

+50
-9
lines changed

9 files changed

+50
-9
lines changed

scm/driver/azure/repo.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ type RepositoryService struct {
2121
func (s *RepositoryService) Find(ctx context.Context, repo string) (*scm.Repository, *scm.Response, error) {
2222
// https://docs.microsoft.com/en-us/rest/api/azure/devops/git/repositories/get?view=azure-devops-rest-4.1
2323
if s.client.project == "" {
24-
return nil, nil, ProjectRequiredError()
25-
}
24+
return nil, nil, ProjectRequiredError()
25+
}
2626
endpoint := fmt.Sprintf("%s/%s/_apis/git/repositories/%s?api-version=6.0", s.client.owner, s.client.project, repo)
2727

2828
out := new(repository)
@@ -59,12 +59,16 @@ func (s *RepositoryService) List2(ctx context.Context, orgSlug string, opts scm.
5959
return nil, nil, scm.ErrNotSupported
6060
}
6161

62+
func (s *RepositoryService) ListRepoLanguages(context.Context, string) (map[string]float64, *scm.Response, error) {
63+
return nil, nil, scm.ErrNotSupported
64+
}
65+
6266
// ListHooks returns a list or repository hooks.
6367
func (s *RepositoryService) ListHooks(ctx context.Context, repo string, opts scm.ListOptions) ([]*scm.Hook, *scm.Response, error) {
6468
// https://docs.microsoft.com/en-us/rest/api/azure/devops/hooks/subscriptions/list?view=azure-devops-rest-6.0
6569
if s.client.project == "" {
66-
return nil, nil, ProjectRequiredError()
67-
}
70+
return nil, nil, ProjectRequiredError()
71+
}
6872
endpoint := fmt.Sprintf("%s/_apis/hooks/subscriptions?api-version=6.0", s.client.owner)
6973
out := new(subscriptions)
7074
res, err := s.client.do(ctx, "GET", endpoint, nil, &out)
@@ -80,8 +84,8 @@ func (s *RepositoryService) ListStatus(ctx context.Context, repo, ref string, op
8084
func (s *RepositoryService) CreateHook(ctx context.Context, repo string, input *scm.HookInput) (*scm.Hook, *scm.Response, error) {
8185
// https://docs.microsoft.com/en-us/rest/api/azure/devops/hooks/subscriptions/create?view=azure-devops-rest-6.0
8286
if s.client.project == "" {
83-
return nil, nil, ProjectRequiredError()
84-
}
87+
return nil, nil, ProjectRequiredError()
88+
}
8589
endpoint := fmt.Sprintf("%s/_apis/hooks/subscriptions?api-version=6.0", s.client.owner)
8690
in := new(subscription)
8791
in.Status = "enabled"
@@ -133,8 +137,8 @@ func (s *RepositoryService) UpdateHook(ctx context.Context, repo, id string, inp
133137
func (s *RepositoryService) DeleteHook(ctx context.Context, repo, id string) (*scm.Response, error) {
134138
// https://docs.microsoft.com/en-us/rest/api/azure/devops/hooks/subscriptions/delete?view=azure-devops-rest-6.0
135139
if s.client.project == "" {
136-
return nil, ProjectRequiredError()
137-
}
140+
return nil, ProjectRequiredError()
141+
}
138142
endpoint := fmt.Sprintf("%s/_apis/hooks/subscriptions/%s?api-version=6.0", s.client.owner, id)
139143
return s.client.do(ctx, "DELETE", endpoint, nil, nil)
140144
}

scm/driver/bitbucket/repo.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ func (s *repositoryService) List(ctx context.Context, opts scm.ListOptions) ([]*
172172
return convertRepositoryList(out), res, err
173173
}
174174

175+
func (s *repositoryService) ListRepoLanguages(context.Context, string) (map[string]float64, *scm.Response, error) {
176+
return nil, nil, scm.ErrNotSupported
177+
}
178+
175179
// ListHooks returns a list or repository hooks.
176180
func (s *repositoryService) ListHooks(ctx context.Context, repo string, opts scm.ListOptions) ([]*scm.Hook, *scm.Response, error) {
177181
path := fmt.Sprintf("2.0/repositories/%s/hooks?%s", repo, encodeListOptions(opts))

scm/driver/gitea/repo.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ func (s *repositoryService) List2(ctx context.Context, orgSlug string, opts scm.
5050
return nil, nil, scm.ErrNotSupported
5151
}
5252

53+
func (s *repositoryService) ListRepoLanguages(context.Context, string) (map[string]float64, *scm.Response, error) {
54+
return nil, nil, scm.ErrNotSupported
55+
}
56+
5357
func (s *repositoryService) ListHooks(ctx context.Context, repo string, opts scm.ListOptions) ([]*scm.Hook, *scm.Response, error) {
5458
path := fmt.Sprintf("api/v1/repos/%s/hooks?%s", repo, encodeListOptions(opts))
5559
out := []*hook{}

scm/driver/gitee/repo.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ func (s *RepositoryService) List2(ctx context.Context, orgSlug string, opts scm.
5050
return nil, nil, scm.ErrNotSupported
5151
}
5252

53+
func (s *RepositoryService) ListRepoLanguages(context.Context, string) (map[string]float64, *scm.Response, error) {
54+
return nil, nil, scm.ErrNotSupported
55+
}
56+
5357
func (s *RepositoryService) ListHooks(ctx context.Context, repo string, opts scm.ListOptions) ([]*scm.Hook, *scm.Response, error) {
5458
path := fmt.Sprintf("repos/%s/hooks?%s", repo, encodeListOptions(opts))
5559
out := []*hook{}

scm/driver/github/repo.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ func (s *RepositoryService) List2(ctx context.Context, installationID string, op
116116
return convertRepositoryList(out.Repositories), res, err
117117
}
118118

119+
func (s *RepositoryService) ListRepoLanguages(ctx context.Context, repo string) (map[string]float64, *scm.Response, error) {
120+
path := fmt.Sprintf("repos/%s/languages", repo)
121+
out := map[string]float64{}
122+
res, err := s.client.do(ctx, "GET", path, nil, &out)
123+
return out, res, err
124+
}
125+
119126
// ListHooks returns a list or repository hooks.
120127
func (s *RepositoryService) ListHooks(ctx context.Context, repo string, opts scm.ListOptions) ([]*scm.Hook, *scm.Response, error) {
121128
path := fmt.Sprintf("repos/%s/hooks?%s", repo, encodeListOptions(opts))

scm/driver/gitlab/repo.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ func (s *repositoryService) List2(ctx context.Context, orgSlug string, opts scm.
9898
return nil, nil, scm.ErrNotSupported
9999
}
100100

101+
func (s *repositoryService) ListRepoLanguages(ctx context.Context, repo string) (map[string]float64, *scm.Response, error) {
102+
path := fmt.Sprintf("api/v4/projects/%s/languages", encode(repo))
103+
out := map[string]float64{}
104+
res, err := s.client.do(ctx, "GET", path, nil, &out)
105+
return out, res, err
106+
}
107+
101108
func (s *repositoryService) ListHooks(ctx context.Context, repo string, opts scm.ListOptions) ([]*scm.Hook, *scm.Response, error) {
102109
path := fmt.Sprintf("api/v4/projects/%s/hooks?%s", encode(repo), encodeListOptions(opts))
103110
out := []*hook{}

scm/driver/gogs/repo.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ func (s *repositoryService) List2(ctx context.Context, orgSlug string, opts scm.
4949
return nil, nil, scm.ErrNotSupported
5050
}
5151

52+
func (s *repositoryService) ListRepoLanguages(context.Context, string) (map[string]float64, *scm.Response, error) {
53+
return nil, nil, scm.ErrNotSupported
54+
}
55+
5256
func (s *repositoryService) ListHooks(ctx context.Context, repo string, _ scm.ListOptions) ([]*scm.Hook, *scm.Response, error) {
5357
path := fmt.Sprintf("api/v1/repos/%s/hooks", repo)
5458
out := []*hook{}

scm/driver/stash/repo.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ func (s *repositoryService) List2(ctx context.Context, orgSlug string, opts scm.
172172
return nil, nil, scm.ErrNotSupported
173173
}
174174

175+
func (s *repositoryService) ListRepoLanguages(context.Context, string) (map[string]float64, *scm.Response, error) {
176+
return nil, nil, scm.ErrNotSupported
177+
}
178+
175179
// listWrite returns the user repository list.
176180
func (s *repositoryService) listWrite(ctx context.Context, repo string) ([]*scm.Repository, *scm.Response, error) {
177181
_, name := scm.Split(repo)

scm/repo.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,12 @@ type (
120120
// List returns a list of repositories.
121121
List(context.Context, ListOptions) ([]*Repository, *Response, error)
122122

123-
// List returns a list of repositories .
123+
// List2 returns a list of repositories .
124124
List2(context.Context, string, ListOptions) ([]*Repository, *Response, error)
125125

126+
// ListRepoLanguages returns a list of repositories language with percentage.
127+
ListRepoLanguages(context.Context, string) (map[string]float64, *Response, error)
128+
126129
// ListHooks returns a list or repository hooks.
127130
ListHooks(context.Context, string, ListOptions) ([]*Hook, *Response, error)
128131

0 commit comments

Comments
 (0)