klesh commented on code in PR #1994:
URL: https://github.com/apache/incubator-devlake/pull/1994#discussion_r889845116


##########
plugins/jira/api/connection.go:
##########
@@ -279,7 +146,7 @@ DELETE /plugins/jira/connections/:connectionId
 */
 func DeleteConnection(input *core.ApiResourceInput) (*core.ApiResourceOutput, 
error) {
        // load from db
-       jiraConnectionID, err := getJiraConnectionIdByInputParam(input)
+       jiraConnectionID, err := 
helper.GetConnectionIdByInputParam(input.Params)

Review Comment:
   How about `GetConnection`?



##########
plugins/jira/api/connection.go:
##########
@@ -213,24 +106,14 @@ POST /plugins/jira/connections
        "basicAuthEncoded": "generated by `echo -n <jira login email>:<jira 
token> | base64`",
        "epicKeyField": "name of customfield of epic key",
        "storyPointField": "name of customfield of story point",
-       "typeMappings": { // optional, send empty object to delete all 
typeMappings of the data connection
-               "userType": {
-                       "standardType": "devlake standard type",
-                       "statusMappings": {  // optional, send empt object to 
delete all status mapping for the user type
-                               "userStatus": {
-                                       "standardStatus": "devlake standard 
status"
-                               }
-                       }
-               }
-       }
 }
 */
 func PostConnections(input *core.ApiResourceInput) (*core.ApiResourceOutput, 
error) {
        // create a new connection
        jiraConnection := &models.JiraConnection{}
 
        // update from request and save to database
-       err := refreshAndSaveJiraConnection(jiraConnection, input.Body)
+       err := helper.Create(input.Body, jiraConnection, db)

Review Comment:
   `Create` is too vague, how about `CreateConnection` ?



##########
plugins/jira/api/connection.go:
##########
@@ -410,7 +238,11 @@ type GranularitiesResponse struct {
 }
 
 func GetGranularitiesByConnectionId(input *core.ApiResourceInput) 
(*core.ApiResourceOutput, error) {
-       jiraConnection, err := findConnectionByInputParam(input)

Review Comment:
   I don't think `GetGranularitiesByConnectionId` and `GetBoardsByConnectionId` 
are being used anywhere, and they shouldn't be used anyway, I suggest that we 
delete them



##########
plugins/helper/connection_test.go:
##########
@@ -0,0 +1,151 @@
+/*
+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 helper
+
+import (
+       "reflect"
+       "testing"
+
+       "github.com/stretchr/testify/assert"
+)
+
+type TestConnection struct {

Review Comment:
   Can you rename this to `MockConnection` or `UnitTestConnection`?
   I thought it is related to `/api/plugins/xxx/connection/test` every time I 
see it.



##########
plugins/jira/api/connection.go:
##########
@@ -304,22 +171,19 @@ func DeleteConnection(input *core.ApiResourceInput) 
(*core.ApiResourceOutput, er
 GET /plugins/jira/connections
 */
 func ListConnections(input *core.ApiResourceInput) (*core.ApiResourceOutput, 
error) {
-       jiraConnections := make([]models.JiraConnection, 0)
+       jiraConnections := make([]*models.JiraConnection, 0)

Review Comment:
   Can we also create a `ListConnection` for it?



##########
plugins/jira/api/connection.go:
##########
@@ -246,27 +129,11 @@ PATCH /plugins/jira/connections/:connectionId
        "basicAuthEncoded": "generated by `echo -n <jira login email>:<jira 
token> | base64`",
        "epicKeyField": "name of customfield of epic key",
        "storyPointField": "name of customfield of story point",
-       "typeMappings": { // optional, send empty object to delete all 
typeMappings of the data connection
-               "userType": {
-                       "standardType": "devlake standard type",
-                       "statusMappings": {  // optional, send empt object to 
delete all status mapping for the user type
-                               "userStatus": {
-                                       "standardStatus": "devlake standard 
status"
-                               }
-                       }
-               }
-       }
 }
 */
 func PatchConnection(input *core.ApiResourceInput) (*core.ApiResourceOutput, 
error) {
-       // load from db
-       jiraConnection, err := findConnectionByInputParam(input)
-       if err != nil {
-               return nil, err
-       }
-
-       // update from request and save to database
-       err = refreshAndSaveJiraConnection(jiraConnection, input.Body)
+       jiraConnection := &models.JiraConnection{}
+       err := helper.Patch(input, jiraConnection, db)

Review Comment:
   Same as above



-- 
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]

Reply via email to