-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
package internal | ||
Check warning Code scanning / Revive (reported by Codacy) should have a package comment Warning
should have a package comment
|
||
|
||
import ( | ||
"context" | ||
"fmt" | ||
model "github.com/ctreminiom/go-atlassian/pkg/infra/models" | ||
"github.com/ctreminiom/go-atlassian/service" | ||
"github.com/ctreminiom/go-atlassian/service/bitbucket" | ||
"net/http" | ||
) | ||
|
||
type ProjectGroupPermission struct { | ||
Check warning Code scanning / Revive (reported by Codacy) exported type ProjectGroupPermission should have comment or be unexported Warning
exported type ProjectGroupPermission should have comment or be unexported
|
||
internalClient bitbucket.ProjectGroupPermissionConnector | ||
} | ||
|
||
func (p *ProjectGroupPermission) Gets(ctx context.Context, workspace, projectKey string) (*model.BitbucketProjectGroupPermissionPageScheme, *model.ResponseScheme, error) { | ||
Check warning Code scanning / Revive (reported by Codacy) exported method ProjectGroupPermission.Gets should have comment or be unexported Warning
exported method ProjectGroupPermission.Gets should have comment or be unexported
|
||
return p.internalClient.Gets(ctx, workspace, projectKey) | ||
} | ||
|
||
func (p *ProjectGroupPermission) Get(ctx context.Context, workspace, projectKey, groupSlug string) (*model.ProjectGroupPermissionScheme, *model.ResponseScheme, error) { | ||
Check warning Code scanning / Revive (reported by Codacy) exported method ProjectGroupPermission.Get should have comment or be unexported Warning
exported method ProjectGroupPermission.Get should have comment or be unexported
|
||
return p.internalClient.Get(ctx, workspace, projectKey, groupSlug) | ||
} | ||
|
||
func (p *ProjectGroupPermission) Update(ctx context.Context, workspace, projectKey, groupSlug, permission string) (*model.ProjectGroupPermissionScheme, *model.ResponseScheme, error) { | ||
Check warning Code scanning / Revive (reported by Codacy) exported method ProjectGroupPermission.Update should have comment or be unexported Warning
exported method ProjectGroupPermission.Update should have comment or be unexported
|
||
return p.internalClient.Update(ctx, workspace, projectKey, groupSlug, permission) | ||
} | ||
|
||
func (p *ProjectGroupPermission) Delete(ctx context.Context, workspace, projectKey, groupSlug string) (*model.ResponseScheme, error) { | ||
Check warning Code scanning / Revive (reported by Codacy) exported method ProjectGroupPermission.Delete should have comment or be unexported Warning
exported method ProjectGroupPermission.Delete should have comment or be unexported
|
||
return p.internalClient.Delete(ctx, workspace, projectKey, groupSlug) | ||
} | ||
|
||
func NewProjectGroupPermissionService(client service.Connector) *ProjectGroupPermission { | ||
Check warning Code scanning / Revive (reported by Codacy) exported function NewProjectGroupPermissionService should have comment or be unexported Warning
exported function NewProjectGroupPermissionService should have comment or be unexported
|
||
return &ProjectGroupPermission{ | ||
internalClient: &internalProjectGroupPermissionImpl{c: client}, | ||
} | ||
} | ||
|
||
type internalProjectGroupPermissionImpl struct { | ||
c service.Connector | ||
} | ||
|
||
func (i *internalProjectGroupPermissionImpl) Gets(ctx context.Context, workspace, projectKey string) (*model.BitbucketProjectGroupPermissionPageScheme, *model.ResponseScheme, error) { | ||
|
||
if workspace == "" { | ||
return nil, nil, model.ErrNoWorkspace | ||
} | ||
|
||
if projectKey == "" { | ||
return nil, nil, model.ErrNoProjectSlug | ||
} | ||
|
||
endpoint := fmt.Sprintf("2.0/workspaces/%s/projects/%s/permissions-config/groups", workspace, projectKey) | ||
request, err := i.c.NewRequest(ctx, http.MethodGet, endpoint, "", nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
permissions := new(model.BitbucketProjectGroupPermissionPageScheme) | ||
response, err := i.c.Call(request, permissions) | ||
if err != nil { | ||
return nil, response, err | ||
} | ||
|
||
return permissions, response, nil | ||
} | ||
|
||
func (i *internalProjectGroupPermissionImpl) Get(ctx context.Context, workspace, projectKey, groupSlug string) (*model.ProjectGroupPermissionScheme, *model.ResponseScheme, error) { | ||
|
||
if workspace == "" { | ||
return nil, nil, model.ErrNoWorkspace | ||
} | ||
|
||
if projectKey == "" { | ||
return nil, nil, model.ErrNoProjectSlug | ||
} | ||
|
||
if groupSlug == "" { | ||
return nil, nil, model.ErrNoGroupSlug | ||
} | ||
|
||
endpoint := fmt.Sprintf("2.0/workspaces/%s/projects/%s/permissions-config/groups/%s", workspace, projectKey, groupSlug) | ||
request, err := i.c.NewRequest(ctx, http.MethodGet, endpoint, "", nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
permission := new(model.ProjectGroupPermissionScheme) | ||
response, err := i.c.Call(request, permission) | ||
if err != nil { | ||
return nil, response, err | ||
} | ||
|
||
return permission, response, nil | ||
} | ||
|
||
func (i *internalProjectGroupPermissionImpl) Update(ctx context.Context, workspace, projectKey, groupSlug, permission string) (*model.ProjectGroupPermissionScheme, *model.ResponseScheme, error) { | ||
|
||
if workspace == "" { | ||
return nil, nil, model.ErrNoWorkspace | ||
} | ||
|
||
if projectKey == "" { | ||
return nil, nil, model.ErrNoProjectSlug | ||
} | ||
|
||
if groupSlug == "" { | ||
return nil, nil, model.ErrNoGroupSlug | ||
} | ||
|
||
if permission == "" { | ||
return nil, nil, model.ErrNoPermissionSlug | ||
} | ||
|
||
endpoint := fmt.Sprintf("2.0/workspaces/%s/projects/%s/permissions-config/groups/%s", workspace, projectKey, groupSlug) | ||
request, err := i.c.NewRequest(ctx, http.MethodPut, endpoint, "", map[string]string{"permission": permission}) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
permissionUpdated := new(model.ProjectGroupPermissionScheme) | ||
response, err := i.c.Call(request, permissionUpdated) | ||
if err != nil { | ||
return nil, response, err | ||
} | ||
|
||
return permissionUpdated, response, nil | ||
} | ||
|
||
func (i *internalProjectGroupPermissionImpl) Delete(ctx context.Context, workspace, projectKey, groupSlug string) (*model.ResponseScheme, error) { | ||
|
||
if workspace == "" { | ||
return nil, model.ErrNoWorkspace | ||
} | ||
|
||
if projectKey == "" { | ||
return nil, model.ErrNoProjectSlug | ||
} | ||
|
||
if groupSlug == "" { | ||
return nil, model.ErrNoGroupSlug | ||
} | ||
|
||
endpoint := fmt.Sprintf("2.0/workspaces/%s/projects/%s/permissions-config/groups/%s", workspace, projectKey, groupSlug) | ||
request, err := i.c.NewRequest(ctx, http.MethodDelete, endpoint, "", nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return i.c.Call(request, nil) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package internal | ||
Check warning Code scanning / Revive (reported by Codacy) should have a package comment Warning
should have a package comment
|
||
|
||
import ( | ||
"context" | ||
"fmt" | ||
model "github.com/ctreminiom/go-atlassian/pkg/infra/models" | ||
"github.com/ctreminiom/go-atlassian/service" | ||
"github.com/ctreminiom/go-atlassian/service/bitbucket" | ||
"net/http" | ||
) | ||
|
||
// ProjectService handles communication with the project related methods of the Bitbucket API. | ||
type ProjectService struct { | ||
internalClient bitbucket.ProjectConnector | ||
} | ||
|
||
// NewProjectService handles communication with the project related methods of the Bitbucket API. | ||
func NewProjectService(client service.Connector) *ProjectService { | ||
|
||
return &ProjectService{ | ||
internalClient: &internalProjectServiceImpl{c: client}, | ||
} | ||
} | ||
|
||
type internalProjectServiceImpl struct { | ||
c service.Connector | ||
} | ||
|
||
func (i *internalProjectServiceImpl) Create(ctx context.Context, workspace string, payload *model.BitbucketProjectScheme) (*model.BitbucketProjectScheme, *model.ResponseScheme, error) { | ||
|
||
if workspace == "" { | ||
return nil, nil, model.ErrNoWorkspace | ||
} | ||
|
||
endpoint := fmt.Sprintf("2.0/workspaces/%v/projects", workspace) | ||
|
||
request, err := i.c.NewRequest(ctx, http.MethodPost, endpoint, "", payload) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
projectCreated := new(model.BitbucketProjectScheme) | ||
response, err := i.c.Call(request, projectCreated) | ||
if err != nil { | ||
return nil, response, err | ||
} | ||
|
||
return projectCreated, response, nil | ||
} | ||
|
||
func (i *internalProjectServiceImpl) Get(ctx context.Context, workspace, projectKey string) (*model.BitbucketProjectScheme, *model.ResponseScheme, error) { | ||
|
||
if workspace == "" { | ||
return nil, nil, model.ErrNoWorkspace | ||
} | ||
|
||
if projectKey == "" { | ||
return nil, nil, model.ErrNoProjectSlug | ||
} | ||
|
||
endpoint := fmt.Sprintf("2.0/workspaces/%v/projects/%v", workspace, projectKey) | ||
|
||
request, err := i.c.NewRequest(ctx, http.MethodGet, endpoint, "", nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
project := new(model.BitbucketProjectScheme) | ||
response, err := i.c.Call(request, project) | ||
if err != nil { | ||
return nil, response, err | ||
} | ||
|
||
return project, response, nil | ||
} | ||
|
||
func (i *internalProjectServiceImpl) Update(ctx context.Context, workspace, projectKey string, payload *model.BitbucketProjectScheme) (*model.BitbucketProjectScheme, *model.ResponseScheme, error) { | ||
|
||
if workspace == "" { | ||
return nil, nil, model.ErrNoWorkspace | ||
} | ||
|
||
if projectKey == "" { | ||
return nil, nil, model.ErrNoProjectSlug | ||
} | ||
|
||
endpoint := fmt.Sprintf("2.0/workspaces/%v/projects/%v", workspace, projectKey) | ||
|
||
request, err := i.c.NewRequest(ctx, http.MethodPut, endpoint, "", payload) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
projectUpdated := new(model.BitbucketProjectScheme) | ||
response, err := i.c.Call(request, projectUpdated) | ||
if err != nil { | ||
return nil, response, err | ||
} | ||
|
||
return projectUpdated, response, nil | ||
} | ||
|
||
func (i *internalProjectServiceImpl) Delete(ctx context.Context, workspace, projectKey string) (*model.ResponseScheme, error) { | ||
|
||
if workspace == "" { | ||
return nil, model.ErrNoWorkspace | ||
} | ||
|
||
if projectKey == "" { | ||
return nil, model.ErrNoProjectSlug | ||
} | ||
|
||
endpoint := fmt.Sprintf("2.0/workspaces/%v/projects/%v", workspace, projectKey) | ||
|
||
request, err := i.c.NewRequest(ctx, http.MethodDelete, endpoint, "", nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return i.c.Call(request, nil) | ||
} |