warren830 commented on code in PR #4461: URL: https://github.com/apache/incubator-devlake/pull/4461#discussion_r1112911466
########## backend/plugins/bamboo/api/remote.go: ########## @@ -0,0 +1,319 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package api + +import ( + "context" + "encoding/base64" + "encoding/json" + "fmt" + "net/http" + "net/url" + "strconv" + + "github.com/apache/incubator-devlake/core/errors" + "github.com/apache/incubator-devlake/core/plugin" + "github.com/apache/incubator-devlake/helpers/pluginhelper/api" + "github.com/apache/incubator-devlake/plugins/bamboo/models" +) + +type RemoteScopesChild struct { + Type string `json:"type"` + ParentId *string `json:"parentId"` + Id string `json:"id"` + Name string `json:"name"` + Data interface{} `json:"data"` +} + +type RemoteScopesOutput struct { + Children []RemoteScopesChild `json:"children"` + NextPageToken string `json:"nextPageToken"` +} + +type SearchRemoteScopesOutput struct { + Children []RemoteScopesChild `json:"children"` + Page int `json:"page"` + PageSize int `json:"pageSize"` +} + +type PageData struct { + Page int `json:"page"` + PageSize int `json:"per_page"` +} + +const BambooRemoteScopesPerPage int = 100 +const TypeProject string = "scope" +const TypeGroup string = "group" + +// RemoteScopes list all available scope for users +// @Summary list all available scope for users +// @Description list all available scope for users +// @Tags plugins/bamboo +// @Accept application/json +// @Param connectionId path int false "connection ID" +// @Param groupId query string false "group ID" +// @Param pageToken query string false "page Token" +// @Success 200 {object} RemoteScopesOutput +// @Failure 400 {object} shared.ApiBody "Bad Request" +// @Failure 500 {object} shared.ApiBody "Internal Error" +// @Router /plugins/bamboo/connections/{connectionId}/remote-scopes [GET] +func RemoteScopes(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) { + connectionId, _ := extractParam(input.Params) + if connectionId == 0 { + return nil, errors.BadInput.New("invalid connectionId") + } + + connection := &models.BambooConnection{} + err := connectionHelper.First(connection, input.Params) + if err != nil { + return nil, err + } + + groupId, ok := input.Query["groupId"] + if !ok || len(groupId) == 0 { + groupId = []string{""} + } + + pageToken, ok := input.Query["pageToken"] + if !ok || len(pageToken) == 0 { + pageToken = []string{""} + } + + // get gid and pageData + gid := groupId[0] Review Comment: As bamboo doesn't have group, I think we don't need gid -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
