This is an automated email from the ASF dual-hosted git repository.
hez pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new eb8bed4c9 fix: Fix scopes API path in PagerDuty (#4874)
eb8bed4c9 is described below
commit eb8bed4c90c25530895f2c173e7c4f92e40e5155
Author: Keon Amini <[email protected]>
AuthorDate: Fri Apr 7 15:37:50 2023 -0500
fix: Fix scopes API path in PagerDuty (#4874)
---
backend/helpers/pluginhelper/api/scope_helper.go | 16 ++++++++++-----
backend/plugins/pagerduty/api/scope.go | 26 ++++++++++++------------
backend/plugins/pagerduty/impl/impl.go | 8 ++++----
3 files changed, 28 insertions(+), 22 deletions(-)
diff --git a/backend/helpers/pluginhelper/api/scope_helper.go
b/backend/helpers/pluginhelper/api/scope_helper.go
index a47f1ec53..f0f28e6f9 100644
--- a/backend/helpers/pluginhelper/api/scope_helper.go
+++ b/backend/helpers/pluginhelper/api/scope_helper.go
@@ -88,7 +88,7 @@ func (c *ScopeApiHelper[Conn, Scope, Tr]) Put(input
*plugin.ApiResourceInput) (*
// Extract the connection ID from the input.Params map
connectionId, _ := extractFromReqParam(input.Params)
if connectionId == 0 {
- return nil, errors.BadInput.New("invalid connectionId or
scopeId")
+ return nil, errors.BadInput.New("invalid connectionId")
}
err = c.VerifyConnection(connectionId)
if err != nil {
@@ -131,9 +131,12 @@ func (c *ScopeApiHelper[Conn, Scope, Tr]) Put(input
*plugin.ApiResourceInput) (*
func (c *ScopeApiHelper[Conn, Scope, Tr]) Update(input
*plugin.ApiResourceInput, fieldName string) (*plugin.ApiResourceOutput,
errors.Error) {
connectionId, scopeId := extractFromReqParam(input.Params)
- if connectionId == 0 || len(scopeId) == 0 || scopeId == "0" {
+ if connectionId == 0 {
return &plugin.ApiResourceOutput{Body: nil, Status:
http.StatusInternalServerError}, errors.BadInput.New("invalid connectionId")
}
+ if len(scopeId) == 0 || scopeId == "0" {
+ return &plugin.ApiResourceOutput{Body: nil, Status:
http.StatusInternalServerError}, errors.BadInput.New("invalid scopeId")
+ }
err := c.VerifyConnection(connectionId)
if err != nil {
return &plugin.ApiResourceOutput{Body: nil, Status:
http.StatusInternalServerError}, err
@@ -180,7 +183,7 @@ func (c *ScopeApiHelper[Conn, Scope, Tr])
GetScopeList(input *plugin.ApiResource
// Extract the connection ID from the input.Params map
connectionId, _ := extractFromReqParam(input.Params)
if connectionId == 0 {
- return nil, errors.BadInput.New("invalid path params")
+ return nil, errors.BadInput.New("invalid path params:
\"connectionId\" not set")
}
err := c.VerifyConnection(connectionId)
if err != nil {
@@ -225,8 +228,11 @@ func (c *ScopeApiHelper[Conn, Scope, Tr])
GetScopeList(input *plugin.ApiResource
func (c *ScopeApiHelper[Conn, Scope, Tr]) GetScope(input
*plugin.ApiResourceInput, fieldName string) (*plugin.ApiResourceOutput,
errors.Error) {
connectionId, scopeId := extractFromReqParam(input.Params)
- if connectionId == 0 || len(scopeId) == 0 || scopeId == "0" {
- return nil, errors.BadInput.New("invalid path params")
+ if connectionId == 0 {
+ return nil, errors.BadInput.New("invalid path params:
\"connectionId\" not set")
+ }
+ if len(scopeId) == 0 || scopeId == "0" {
+ return nil, errors.BadInput.New("invalid path params:
\"scopeId\" not set/invalid")
}
err := c.VerifyConnection(connectionId)
if err != nil {
diff --git a/backend/plugins/pagerduty/api/scope.go
b/backend/plugins/pagerduty/api/scope.go
index c4e28bca5..59fae3b9a 100644
--- a/backend/plugins/pagerduty/api/scope.go
+++ b/backend/plugins/pagerduty/api/scope.go
@@ -30,9 +30,9 @@ type (
ScopeRes api.ScopeRes[models.Service]
)
-// PutScope create or update pagerduty repo
-// @Summary create or update pagerduty repo
-// @Description Create or update pagerduty repo
+// PutScope create or update pagerduty service
+// @Summary create or update pagerduty service
+// @Description Create or update pagerduty service
// @Tags plugins/pagerduty
// @Accept application/json
// @Param connectionId path int true "connection ID"
@@ -45,18 +45,18 @@ func PutScope(input *plugin.ApiResourceInput)
(*plugin.ApiResourceOutput, errors
return scopeHelper.Put(input)
}
-// UpdateScope patch to pagerduty repo
-// @Summary patch to pagerduty repo
-// @Description patch to pagerduty repo
+// UpdateScope patch to pagerduty service
+// @Summary patch to pagerduty service
+// @Description patch to pagerduty service
// @Tags plugins/pagerduty
// @Accept application/json
// @Param connectionId path int true "connection ID"
-// @Param repoId path int true "repo ID"
+// @Param serviceId path string true "service ID"
// @Param scope body models.Service true "json"
// @Success 200 {object} models.Service
// @Failure 400 {object} shared.ApiBody "Bad Request"
// @Failure 500 {object} shared.ApiBody "Internal Error"
-// @Router /plugins/pagerduty/connections/{connectionId}/scopes/{repoId}
[PATCH]
+// @Router /plugins/pagerduty/connections/{connectionId}/scopes/{serviceId}
[PATCH]
func UpdateScope(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
errors.Error) {
return scopeHelper.Update(input, "id")
}
@@ -76,16 +76,16 @@ func GetScopeList(input *plugin.ApiResourceInput)
(*plugin.ApiResourceOutput, er
return scopeHelper.GetScopeList(input)
}
-// GetScope get one PagerDuty repo
-// @Summary get one PagerDuty repo
-// @Description get one PagerDuty repo
+// GetScope get one PagerDuty service
+// @Summary get one PagerDuty service
+// @Description get one PagerDuty service
// @Tags plugins/pagerduty
// @Param connectionId path int true "connection ID"
-// @Param repoId path int true "repo ID"
+// @Param serviceId path int true "service ID"
// @Success 200 {object} ScopeRes
// @Failure 400 {object} shared.ApiBody "Bad Request"
// @Failure 500 {object} shared.ApiBody "Internal Error"
-// @Router /plugins/pagerduty/connections/{connectionId}/scopes/{repoId} [GET]
+// @Router /plugins/pagerduty/connections/{connectionId}/scopes/{serviceId}
[GET]
func GetScope(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
errors.Error) {
return scopeHelper.GetScope(input, "id")
}
diff --git a/backend/plugins/pagerduty/impl/impl.go
b/backend/plugins/pagerduty/impl/impl.go
index cdcca4b3f..d669e7e82 100644
--- a/backend/plugins/pagerduty/impl/impl.go
+++ b/backend/plugins/pagerduty/impl/impl.go
@@ -119,10 +119,6 @@ func (p PagerDuty) ApiResources()
map[string]map[string]plugin.ApiResourceHandle
"PATCH": api.PatchConnection,
"DELETE": api.DeleteConnection,
},
- "connections/:connectionId/scopes/:projectId": {
- "GET": api.GetScope,
- "PATCH": api.UpdateScope,
- },
"connections/:connectionId/remote-scopes": {
"GET": api.RemoteScopes,
},
@@ -133,6 +129,10 @@ func (p PagerDuty) ApiResources()
map[string]map[string]plugin.ApiResourceHandle
"GET": api.GetScopeList,
"PUT": api.PutScope,
},
+ "connections/:connectionId/scopes/:scopeId": {
+ "GET": api.GetScope,
+ "PATCH": api.UpdateScope,
+ },
"connections/:connectionId/transformation_rules": {
"POST": api.CreateTransformationRule,
"GET": api.GetTransformationRuleList,