klesh commented on code in PR #3753: URL: https://github.com/apache/incubator-devlake/pull/3753#discussion_r1027509427
########## plugins/jira/api/scope.go: ########## @@ -0,0 +1,138 @@ +/* +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 ( + "net/http" + "net/url" + "strconv" + + "github.com/apache/incubator-devlake/errors" + "github.com/apache/incubator-devlake/plugins/core" + "github.com/apache/incubator-devlake/plugins/core/dal" + "github.com/apache/incubator-devlake/plugins/jira/models" + "github.com/mitchellh/mapstructure" +) + +type putBoardRequest struct { + ConnectionId uint64 `json:"connectionId"` + BoardId uint64 `json:"boardId"` + ProjectId uint `json:"projectId"` + Name string `json:"name"` + Self string `json:"self"` + Type string `json:"type"` +} + +// PutScope create or update jira board +// @Summary create or update jira board +// @Description Create or update Jira board +// @Tags plugins/jira +// @Accept application/json +// @Param scope body putBoardRequest true "json" +// @Success 200 {object} core.ApiResourceOutput +// @Failure 400 {object} shared.ApiBody "Bad Request" +// @Failure 500 {object} shared.ApiBody "Internal Error" +// @Router /plugins/jira/scopes [PUT] +func PutScope(input *core.ApiResourceInput) (*core.ApiResourceOutput, errors.Error) { + // update from request and save to database + var req putBoardRequest + err := mapstructure.Decode(input.Body, &req) + if err != nil { + return nil, errors.Default.Wrap(err, "error decoding map into putBoardRequest") + } + board := &models.JiraBoard{ + ConnectionId: req.ConnectionId, + BoardId: req.BoardId, + ProjectId: req.ProjectId, + Name: req.Name, + Self: req.Self, + Type: req.Type, + } + err = basicRes.GetDal().CreateOrUpdate(&board) + if err != nil { + return nil, errors.Default.Wrap(err, "error on saving JiraBoard") + } + return &core.ApiResourceOutput{Status: http.StatusOK}, nil +} + +// DeleteScope delete a jira board +// @Summary delete a jira board +// @Description delete a jira board +// @Tags plugins/jira +// @Param connectionId query int false "connection ID" +// @Param boardId query int false "board ID" +// @Success 200 {object} core.ApiResourceOutput +// @Failure 400 {object} shared.ApiBody "Bad Request" +// @Failure 500 {object} shared.ApiBody "Internal Error" +// @Router /plugins/jira/scopes [DELETE] +func DeleteScope(input *core.ApiResourceInput) (*core.ApiResourceOutput, errors.Error) { Review Comment: No delete ########## plugins/jira/api/scope.go: ########## @@ -0,0 +1,138 @@ +/* +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 ( + "net/http" + "net/url" + "strconv" + + "github.com/apache/incubator-devlake/errors" + "github.com/apache/incubator-devlake/plugins/core" + "github.com/apache/incubator-devlake/plugins/core/dal" + "github.com/apache/incubator-devlake/plugins/jira/models" + "github.com/mitchellh/mapstructure" +) + +type putBoardRequest struct { + ConnectionId uint64 `json:"connectionId"` + BoardId uint64 `json:"boardId"` + ProjectId uint `json:"projectId"` + Name string `json:"name"` + Self string `json:"self"` + Type string `json:"type"` +} + +// PutScope create or update jira board +// @Summary create or update jira board +// @Description Create or update Jira board +// @Tags plugins/jira +// @Accept application/json +// @Param scope body putBoardRequest true "json" +// @Success 200 {object} core.ApiResourceOutput +// @Failure 400 {object} shared.ApiBody "Bad Request" +// @Failure 500 {object} shared.ApiBody "Internal Error" +// @Router /plugins/jira/scopes [PUT] +func PutScope(input *core.ApiResourceInput) (*core.ApiResourceOutput, errors.Error) { + // update from request and save to database + var req putBoardRequest + err := mapstructure.Decode(input.Body, &req) + if err != nil { + return nil, errors.Default.Wrap(err, "error decoding map into putBoardRequest") + } + board := &models.JiraBoard{ Review Comment: this `api` package is getting complex, should we create a `services` for the plugin to hold the Biz Logic? ########## plugins/jira/api/transformation_rule.go: ########## @@ -0,0 +1,160 @@ +/* +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 Review Comment: This file has the same problems as `api/scope.go` ########## plugins/jira/api/scope.go: ########## @@ -0,0 +1,138 @@ +/* +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 ( + "net/http" + "net/url" + "strconv" + + "github.com/apache/incubator-devlake/errors" + "github.com/apache/incubator-devlake/plugins/core" + "github.com/apache/incubator-devlake/plugins/core/dal" + "github.com/apache/incubator-devlake/plugins/jira/models" + "github.com/mitchellh/mapstructure" +) + +type putBoardRequest struct { + ConnectionId uint64 `json:"connectionId"` + BoardId uint64 `json:"boardId"` + ProjectId uint `json:"projectId"` + Name string `json:"name"` + Self string `json:"self"` + Type string `json:"type"` +} + +// PutScope create or update jira board +// @Summary create or update jira board +// @Description Create or update Jira board +// @Tags plugins/jira +// @Accept application/json +// @Param scope body putBoardRequest true "json" +// @Success 200 {object} core.ApiResourceOutput +// @Failure 400 {object} shared.ApiBody "Bad Request" +// @Failure 500 {object} shared.ApiBody "Internal Error" +// @Router /plugins/jira/scopes [PUT] +func PutScope(input *core.ApiResourceInput) (*core.ApiResourceOutput, errors.Error) { + // update from request and save to database + var req putBoardRequest + err := mapstructure.Decode(input.Body, &req) + if err != nil { + return nil, errors.Default.Wrap(err, "error decoding map into putBoardRequest") + } + board := &models.JiraBoard{ + ConnectionId: req.ConnectionId, + BoardId: req.BoardId, + ProjectId: req.ProjectId, + Name: req.Name, + Self: req.Self, + Type: req.Type, + } + err = basicRes.GetDal().CreateOrUpdate(&board) + if err != nil { + return nil, errors.Default.Wrap(err, "error on saving JiraBoard") + } + return &core.ApiResourceOutput{Status: http.StatusOK}, nil +} + +// DeleteScope delete a jira board +// @Summary delete a jira board +// @Description delete a jira board +// @Tags plugins/jira +// @Param connectionId query int false "connection ID" +// @Param boardId query int false "board ID" +// @Success 200 {object} core.ApiResourceOutput +// @Failure 400 {object} shared.ApiBody "Bad Request" +// @Failure 500 {object} shared.ApiBody "Internal Error" +// @Router /plugins/jira/scopes [DELETE] +func DeleteScope(input *core.ApiResourceInput) (*core.ApiResourceOutput, errors.Error) { + connectionId, boardId := extractQuery(input.Query) + if connectionId == 0 { + return nil, errors.Default.New("invalid connectionId") + } + if boardId == 0 { + return nil, errors.Default.New("invalid boardId") + } + err := basicRes.GetDal().Delete(&models.JiraBoard{}, dal.Where("connection_id = ? AND board_id = ?", connectionId, boardId)) + if err != nil { + return nil, errors.Default.Wrap(err, "error on deleting JiraBoard") + } + return &core.ApiResourceOutput{Status: http.StatusOK}, nil +} + +// GetScope get Jira board Review Comment: boards? ########## plugins/jira/api/scope.go: ########## @@ -0,0 +1,138 @@ +/* +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 ( + "net/http" + "net/url" + "strconv" + + "github.com/apache/incubator-devlake/errors" + "github.com/apache/incubator-devlake/plugins/core" + "github.com/apache/incubator-devlake/plugins/core/dal" + "github.com/apache/incubator-devlake/plugins/jira/models" + "github.com/mitchellh/mapstructure" +) + +type putBoardRequest struct { + ConnectionId uint64 `json:"connectionId"` + BoardId uint64 `json:"boardId"` + ProjectId uint `json:"projectId"` + Name string `json:"name"` + Self string `json:"self"` + Type string `json:"type"` +} + +// PutScope create or update jira board +// @Summary create or update jira board +// @Description Create or update Jira board +// @Tags plugins/jira +// @Accept application/json +// @Param scope body putBoardRequest true "json" +// @Success 200 {object} core.ApiResourceOutput +// @Failure 400 {object} shared.ApiBody "Bad Request" +// @Failure 500 {object} shared.ApiBody "Internal Error" +// @Router /plugins/jira/scopes [PUT] Review Comment: `PUT /plugin/jira/connections/:connectionId/scopes/:scopeIdOrName` ########## plugins/jira/models/transformation_rules.go: ########## @@ -0,0 +1,31 @@ +/* +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 models + +import ( + "github.com/apache/incubator-devlake/models/common" + "gorm.io/datatypes" +) + +type JiraTransformationRule struct { + common.Model + EpicKeyField string `json:"epicKeyField"` + StoryPointField string `json:"storyPointField"` + RemotelinkCommitShaPattern string `json:"remotelinkCommitShaPattern"` + TypeMappings datatypes.JSON `json:"typeMappings"` Review Comment: same as above ########## plugins/jira/models/migrationscripts/archived/transformation_rules.go: ########## @@ -0,0 +1,31 @@ +/* +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 archived + +import ( + "github.com/apache/incubator-devlake/models/migrationscripts/archived" + "gorm.io/datatypes" +) + +type JiraTransformationRule struct { + archived.Model + EpicKeyField string `json:"epicKeyField"` + StoryPointField string `json:"storyPointField"` + RemotelinkCommitShaPattern string `json:"remotelinkCommitShaPattern"` + TypeMappings datatypes.JSON `json:"typeMappings"` Review Comment: please avoid using `gorm` package, use `json.RawMessage` instead ########## plugins/jira/api/scope.go: ########## @@ -0,0 +1,138 @@ +/* +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 ( + "net/http" + "net/url" + "strconv" + + "github.com/apache/incubator-devlake/errors" + "github.com/apache/incubator-devlake/plugins/core" + "github.com/apache/incubator-devlake/plugins/core/dal" + "github.com/apache/incubator-devlake/plugins/jira/models" + "github.com/mitchellh/mapstructure" +) + +type putBoardRequest struct { + ConnectionId uint64 `json:"connectionId"` + BoardId uint64 `json:"boardId"` + ProjectId uint `json:"projectId"` + Name string `json:"name"` + Self string `json:"self"` + Type string `json:"type"` +} + +// PutScope create or update jira board +// @Summary create or update jira board +// @Description Create or update Jira board +// @Tags plugins/jira +// @Accept application/json +// @Param scope body putBoardRequest true "json" +// @Success 200 {object} core.ApiResourceOutput +// @Failure 400 {object} shared.ApiBody "Bad Request" +// @Failure 500 {object} shared.ApiBody "Internal Error" +// @Router /plugins/jira/scopes [PUT] +func PutScope(input *core.ApiResourceInput) (*core.ApiResourceOutput, errors.Error) { + // update from request and save to database + var req putBoardRequest + err := mapstructure.Decode(input.Body, &req) + if err != nil { + return nil, errors.Default.Wrap(err, "error decoding map into putBoardRequest") + } + board := &models.JiraBoard{ + ConnectionId: req.ConnectionId, + BoardId: req.BoardId, + ProjectId: req.ProjectId, + Name: req.Name, + Self: req.Self, + Type: req.Type, + } + err = basicRes.GetDal().CreateOrUpdate(&board) + if err != nil { + return nil, errors.Default.Wrap(err, "error on saving JiraBoard") + } + return &core.ApiResourceOutput{Status: http.StatusOK}, nil +} + +// DeleteScope delete a jira board +// @Summary delete a jira board +// @Description delete a jira board +// @Tags plugins/jira +// @Param connectionId query int false "connection ID" +// @Param boardId query int false "board ID" +// @Success 200 {object} core.ApiResourceOutput +// @Failure 400 {object} shared.ApiBody "Bad Request" +// @Failure 500 {object} shared.ApiBody "Internal Error" +// @Router /plugins/jira/scopes [DELETE] +func DeleteScope(input *core.ApiResourceInput) (*core.ApiResourceOutput, errors.Error) { + connectionId, boardId := extractQuery(input.Query) + if connectionId == 0 { + return nil, errors.Default.New("invalid connectionId") + } + if boardId == 0 { + return nil, errors.Default.New("invalid boardId") + } + err := basicRes.GetDal().Delete(&models.JiraBoard{}, dal.Where("connection_id = ? AND board_id = ?", connectionId, boardId)) + if err != nil { + return nil, errors.Default.Wrap(err, "error on deleting JiraBoard") + } + return &core.ApiResourceOutput{Status: http.StatusOK}, nil +} + +// GetScope get Jira board Review Comment: This is very RESTful, we need a `list(search)` API as well as `detail` API, we need them side by side: 1. `GET /plugin/jira/connections/:connectionId/scopes?keyboard=xxx` 2. `GET /plugin/jira/connections/:connectionId/scopes/:scopeIdOrName` -- 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]
