You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by GitBox <gi...@apache.org> on 2022/11/23 11:43:19 UTC

[GitHub] [incubator-devlake] mindlesscloud opened a new pull request, #3797: refactor: add transformation_rule_id to _tool_jira_boards

mindlesscloud opened a new pull request, #3797:
URL: https://github.com/apache/incubator-devlake/pull/3797

   ### Summary
   In addition to fixing some omissions in #3753, this PR contains the following modification:
   1. add `transformation_rule_id` to `_tool_jira_boards`
   2. provide `PATCH` API for Jira scope
   
   ### Does this close any open issues?
   No, but partially fulfilled issue #3468
   
   ### Screenshots
   the scope API
   ![image](https://user-images.githubusercontent.com/8455907/203538073-76fe9e1b-7729-4dac-b635-367ee058e6a2.png)
   
   ### Other Information
   Any other information that is important to this PR.
   


-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] klesh commented on a diff in pull request #3797: refactor: add transformation_rule_id to _tool_jira_boards

Posted by GitBox <gi...@apache.org>.
klesh commented on code in PR #3797:
URL: https://github.com/apache/incubator-devlake/pull/3797#discussion_r1030435365


##########
plugins/jira/api/scope.go:
##########
@@ -122,3 +149,16 @@ func extractParam(params map[string]string) (uint64, uint64) {
 	boardId, _ := strconv.ParseUint(params["boardId"], 10, 64)
 	return connectionId, boardId
 }
+
+func verifyBoard(board *models.JiraBoard) errors.Error {
+	if board.ConnectionId == 0 {
+		return errors.BadInput.New("invalid connectionId")
+	}
+	if board.BoardId == 0 {
+		return errors.BadInput.New("invalid boardId")
+	}
+	if board.ScopeId != strconv.FormatUint(board.BoardId, 10) {

Review Comment:
   come to think about it, do we have `ScopeName` as well? config-ui would need this for a human-readable representation.
   ![image](https://user-images.githubusercontent.com/61080/203557177-de905e4d-7ee0-419a-b070-a68e1fc14053.png)
   



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] likyh commented on a diff in pull request #3797: refactor: add transformation_rule_id to _tool_jira_boards

Posted by GitBox <gi...@apache.org>.
likyh commented on code in PR #3797:
URL: https://github.com/apache/incubator-devlake/pull/3797#discussion_r1030428179


##########
plugins/jira/api/scope.go:
##########
@@ -122,3 +149,16 @@ func extractParam(params map[string]string) (uint64, uint64) {
 	boardId, _ := strconv.ParseUint(params["boardId"], 10, 64)
 	return connectionId, boardId
 }
+
+func verifyBoard(board *models.JiraBoard) errors.Error {
+	if board.ConnectionId == 0 {
+		return errors.BadInput.New("invalid connectionId")
+	}
+	if board.BoardId == 0 {
+		return errors.BadInput.New("invalid boardId")
+	}
+	if board.ScopeId != strconv.FormatUint(board.BoardId, 10) {

Review Comment:
   why not set `board.ScopeId = board.BoardId` instead reading it from frontend?



##########
plugins/jira/api/scope.go:
##########
@@ -122,3 +149,16 @@ func extractParam(params map[string]string) (uint64, uint64) {
 	boardId, _ := strconv.ParseUint(params["boardId"], 10, 64)
 	return connectionId, boardId
 }
+
+func verifyBoard(board *models.JiraBoard) errors.Error {
+	if board.ConnectionId == 0 {
+		return errors.BadInput.New("invalid connectionId")
+	}
+	if board.BoardId == 0 {
+		return errors.BadInput.New("invalid boardId")
+	}
+	if board.ScopeId != strconv.FormatUint(board.BoardId, 10) {

Review Comment:
   why not set `board.ScopeId = board.BoardId` instead of reading it from frontend?



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] klesh commented on a diff in pull request #3797: refactor: add transformation_rule_id to _tool_jira_boards

Posted by GitBox <gi...@apache.org>.
klesh commented on code in PR #3797:
URL: https://github.com/apache/incubator-devlake/pull/3797#discussion_r1030369176


##########
plugins/jira/api/scope.go:
##########
@@ -24,52 +24,66 @@ import (
 	"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/helper"
 	"github.com/apache/incubator-devlake/plugins/jira/models"
 	"github.com/mitchellh/mapstructure"
 )
 
-type putBoardRequest struct {
-	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 connectionId path int false "connection ID"
 // @Param boardId path int false "board ID"
-// @Param scope body putBoardRequest true "json"
+// @Param scope body models.JiraBoard true "json"
 // @Success 200  {object} models.JiraBoard
 // @Failure 400  {object} shared.ApiBody "Bad Request"
 // @Failure 500  {object} shared.ApiBody "Internal Error"
 // @Router /plugins/jira/connections/{connectionId}/scopes/{boardId} [PUT]
 func PutScope(input *core.ApiResourceInput) (*core.ApiResourceOutput, errors.Error) {
-	connectionId, boardId := extractParam(input.Params)
-	if connectionId*boardId == 0 {
-		return nil, errors.BadInput.New("invalid path params")
+	board, err := extractBoard(input)
+	if err != nil {
+		return nil, err
 	}
-	var req putBoardRequest
-	err := mapstructure.Decode(input.Body, &req)
+	err = basicRes.GetDal().CreateOrUpdate(board)
 	if err != nil {
-		return nil, errors.Default.Wrap(err, "error decoding map into putBoardRequest")
+		return nil, errors.Default.Wrap(err, "error on saving JiraBoard")
 	}
-	board := &models.JiraBoard{
-		ConnectionId: connectionId,
-		BoardId:      boardId,
-		ProjectId:    req.ProjectId,
-		Name:         req.Name,
-		Self:         req.Self,
-		Type:         req.Type,
+	return &core.ApiResourceOutput{Body: board, Status: http.StatusOK}, nil
+}
+
+// UpdateScope patch to jira board
+// @Summary patch to jira board
+// @Description patch to jira board
+// @Tags plugins/jira
+// @Accept application/json
+// @Param connectionId path int false "connection ID"
+// @Param boardId path int false "board ID"
+// @Param scope body models.JiraBoard true "json"
+// @Success 200  {object} models.JiraBoard
+// @Failure 400  {object} shared.ApiBody "Bad Request"
+// @Failure 500  {object} shared.ApiBody "Internal Error"
+// @Router /plugins/jira/connections/{connectionId}/scopes/{boardId} [PATCH]
+func UpdateScope(input *core.ApiResourceInput) (*core.ApiResourceOutput, errors.Error) {
+	board, err := extractBoard(input)

Review Comment:
   This is not needed. What we need to do:
   1. load the board from db
   2. DecodeMapStruct from input.body to the board (this is essentially a patch operation)
   3. verify and save



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] likyh commented on a diff in pull request #3797: refactor: add transformation_rule_id to _tool_jira_boards

Posted by GitBox <gi...@apache.org>.
likyh commented on code in PR #3797:
URL: https://github.com/apache/incubator-devlake/pull/3797#discussion_r1030446169


##########
plugins/jira/api/scope.go:
##########
@@ -122,3 +149,16 @@ func extractParam(params map[string]string) (uint64, uint64) {
 	boardId, _ := strconv.ParseUint(params["boardId"], 10, 64)
 	return connectionId, boardId
 }
+
+func verifyBoard(board *models.JiraBoard) errors.Error {
+	if board.ConnectionId == 0 {
+		return errors.BadInput.New("invalid connectionId")
+	}
+	if board.BoardId == 0 {
+		return errors.BadInput.New("invalid boardId")
+	}
+	if board.ScopeId != strconv.FormatUint(board.BoardId, 10) {

Review Comment:
   ScopeName is easy to set. But ScopeId maybe has some complex rules to calculate.



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] mindlesscloud merged pull request #3797: refactor: add transformation_rule_id to _tool_jira_boards

Posted by GitBox <gi...@apache.org>.
mindlesscloud merged PR #3797:
URL: https://github.com/apache/incubator-devlake/pull/3797


-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] mindlesscloud commented on a diff in pull request #3797: refactor: add transformation_rule_id to _tool_jira_boards

Posted by GitBox <gi...@apache.org>.
mindlesscloud commented on code in PR #3797:
URL: https://github.com/apache/incubator-devlake/pull/3797#discussion_r1030446600


##########
plugins/jira/api/scope.go:
##########
@@ -122,3 +149,16 @@ func extractParam(params map[string]string) (uint64, uint64) {
 	boardId, _ := strconv.ParseUint(params["boardId"], 10, 64)
 	return connectionId, boardId
 }
+
+func verifyBoard(board *models.JiraBoard) errors.Error {
+	if board.ConnectionId == 0 {
+		return errors.BadInput.New("invalid connectionId")
+	}
+	if board.BoardId == 0 {
+		return errors.BadInput.New("invalid boardId")
+	}
+	if board.ScopeId != strconv.FormatUint(board.BoardId, 10) {

Review Comment:
   I wish to expose `scopeId`, `transformationRuleId`, and `connection_id` as common fields among all of the plugin's scope API



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] klesh commented on a diff in pull request #3797: refactor: add transformation_rule_id to _tool_jira_boards

Posted by GitBox <gi...@apache.org>.
klesh commented on code in PR #3797:
URL: https://github.com/apache/incubator-devlake/pull/3797#discussion_r1030434304


##########
plugins/jira/api/scope.go:
##########
@@ -122,3 +149,16 @@ func extractParam(params map[string]string) (uint64, uint64) {
 	boardId, _ := strconv.ParseUint(params["boardId"], 10, 64)
 	return connectionId, boardId
 }
+
+func verifyBoard(board *models.JiraBoard) errors.Error {
+	if board.ConnectionId == 0 {
+		return errors.BadInput.New("invalid connectionId")
+	}
+	if board.BoardId == 0 {
+		return errors.BadInput.New("invalid boardId")
+	}
+	if board.ScopeId != strconv.FormatUint(board.BoardId, 10) {

Review Comment:
   I think it is for config-ui to display the scope in a uniform way, especially on the pipeline page.
   config-ui can display scope id/name directly without detecting plugin.



##########
plugins/jira/api/scope.go:
##########
@@ -122,3 +149,16 @@ func extractParam(params map[string]string) (uint64, uint64) {
 	boardId, _ := strconv.ParseUint(params["boardId"], 10, 64)
 	return connectionId, boardId
 }
+
+func verifyBoard(board *models.JiraBoard) errors.Error {
+	if board.ConnectionId == 0 {
+		return errors.BadInput.New("invalid connectionId")
+	}
+	if board.BoardId == 0 {
+		return errors.BadInput.New("invalid boardId")
+	}
+	if board.ScopeId != strconv.FormatUint(board.BoardId, 10) {

Review Comment:
   come to think about it, do we have `ScopeName` as well? config-ui would need this for a human-readable representation.



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org