Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(providers): Added bitbucket enterprise provider #568

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(providers): Added bitbucket enterprise provider
The new provider use rest API v1.0. For more info see https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html
This PR also contain fix in case when gitscm.List Report() response don't contain info about user permissions
Porsh33 committed Apr 14, 2022
commit d7e32cbeb44197ac363aaed05f46896af6a7d8d2
9 changes: 9 additions & 0 deletions pkg/gitscm/scm.go
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ import (
"github.com/drone/go-scm/scm/driver/github"
"github.com/drone/go-scm/scm/driver/gitlab"
"github.com/drone/go-scm/scm/driver/gogs"
"github.com/drone/go-scm/scm/driver/stash"
"github.com/drone/go-scm/scm/transport"
)

@@ -39,6 +40,8 @@ func New(ctx context.Context, provider, url, token string) (SCM, error) {
scm.client, err = github.New(scm.url)
case "bitbucket":
scm.client, err = bitbucket.New(scm.url)
case "stash":
scm.client, err = stash.New(scm.url)
case "gitea":
scm.client, err = gitea.New(scm.url)
case "gitlab":
@@ -68,6 +71,12 @@ func (s SCM) FindRepo(name string) (*scm.Repository, error) {
return repo, err
}

// FindPerms returns perms of repo.
func (s SCM) FindPerms(repo *scm.Repository) (*scm.Perm, error) {
perm, _, err := s.client.Repositories.FindPerms(s.ctx, fmt.Sprintf("%s/%s", repo.Namespace, repo.Name))
return perm, err
}

// ListCommits returns list of commits.
func (s SCM) ListCommits(repo, branch string) ([]*scm.Commit, error) {
if s.provider != "gitea" {
11 changes: 11 additions & 0 deletions server/store/provider/provider.go
Original file line number Diff line number Diff line change
@@ -102,6 +102,17 @@ func (s providerStore) findRepos(id uint, page, size int) ([]*scm.Repository, er
return repos, err
}
repos, err = gitscm.ListRepos(page, size)

// Some providers like Stash don't return perms in ListRepos response
for _, repo := range repos {
if repo.Perm == nil {
repo.Perm, err = gitscm.FindPerms(repo)
if err != nil {
repo.Perm = &scm.Perm{}
}
}
}

return repos, err
}

Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ export class ProvidersModalComponent implements OnInit {
{ value: 'github', placeholder: 'GitHub' },
{ value: 'gitlab', placeholder: 'GitLab' },
{ value: 'bitbucket', placeholder: 'Bitbucket' },
{ value: 'stash', placeholder: 'Bitbucket Enterprise' },
{ value: 'gitea', placeholder: 'Gitea' },
{ value: 'gogs', placeholder: 'Gogs' }
];
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
<i class="fab fa-github is-medium is-gray" *ngSwitchCase="'github'"></i>
<i class="fab fa-gitlab is-medium is-gray" *ngSwitchCase="'gitlab'"></i>
<i class="fab fa-bitbucket is-medium is-gray" *ngSwitchCase="'bitbucket'"></i>
<i class="fab fa-bitbucket is-medium is-gray" *ngSwitchCase="'stash'"></i>
<img src="/assets/images/icons/gitea-gray.svg" *ngSwitchCase="'gitea'" />
<i class="fab fa-git is-medium is-gray" *ngSwitchDefault></i>
</div>