Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions backend/plugins/pagerduty/api/blueprint_v200.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,15 @@ func makePipelinePlanV200(
}

scope, scopeConfig := scopeDetail.Scope, scopeDetail.ScopeConfig
// construct task options for circleci
// construct task options for pagerduty
task, err := api.MakePipelinePlanTask(
"pagerduty",
subtaskMetas,
scopeConfig.Entities,
tasks.PagerDutyOptions{
ConnectionId: connection.ID,
ServiceId: scope.Id,
ConnectionId: connection.ID,
ServiceId: scope.Id,
ScopeConfigId: scopeConfig.ID,
},
)
if err != nil {
Expand Down
111 changes: 111 additions & 0 deletions backend/plugins/pagerduty/api/scope_config_api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
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 (
"github.com/apache/incubator-devlake/core/errors"
"github.com/apache/incubator-devlake/core/plugin"
)

// CreateScopeConfig create scope config for PagerDuty
// @Summary create scope config for PagerDuty
// @Description create scope config for PagerDuty
// @Tags plugins/pagerduty
// @Accept application/json
// @Param connectionId path int true "connectionId"
// @Param scopeConfig body models.PagerdutyScopeConfig true "scope config"
// @Success 200 {object} models.PagerdutyScopeConfig
// @Failure 400 {object} shared.ApiBody "Bad Request"
// @Failure 500 {object} shared.ApiBody "Internal Error"
// @Router /plugins/pagerduty/connections/{connectionId}/scope-configs [POST]
func CreateScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
return dsHelper.ScopeConfigApi.Post(input)
}

// PatchScopeConfig update scope config for PagerDuty
// @Summary update scope config for PagerDuty
// @Description update scope config for PagerDuty
// @Tags plugins/pagerduty
// @Accept application/json
// @Param id path int true "id"
// @Param connectionId path int true "connectionId"
// @Param scopeConfig body models.PagerdutyScopeConfig true "scope config"
// @Success 200 {object} models.PagerdutyScopeConfig
// @Failure 400 {object} shared.ApiBody "Bad Request"
// @Failure 500 {object} shared.ApiBody "Internal Error"
// @Router /plugins/pagerduty/connections/{connectionId}/scope-configs/{id} [PATCH]
func PatchScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
return dsHelper.ScopeConfigApi.Patch(input)
}

// GetScopeConfig return one scope config
// @Summary return one scope config
// @Description return one scope config
// @Tags plugins/pagerduty
// @Param id path int true "id"
// @Param connectionId path int true "connectionId"
// @Success 200 {object} models.PagerdutyScopeConfig
// @Failure 400 {object} shared.ApiBody "Bad Request"
// @Failure 500 {object} shared.ApiBody "Internal Error"
// @Router /plugins/pagerduty/connections/{connectionId}/scope-configs/{id} [GET]
func GetScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
return dsHelper.ScopeConfigApi.GetDetail(input)
}

// GetScopeConfigList return all scope configs
// @Summary return all scope configs
// @Description return all scope configs
// @Tags plugins/pagerduty
// @Param connectionId path int true "connectionId"
// @Param pageSize query int false "page size, default 50"
// @Param page query int false "page size, default 1"
// @Success 200 {object} []models.PagerdutyScopeConfig
// @Failure 400 {object} shared.ApiBody "Bad Request"
// @Failure 500 {object} shared.ApiBody "Internal Error"
// @Router /plugins/pagerduty/connections/{connectionId}/scope-configs [GET]
func GetScopeConfigList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
return dsHelper.ScopeConfigApi.GetAll(input)
}

// GetServicesByScopeConfig return services details related by scope config
// @Summary return all related services
// @Description return all related services
// @Tags plugins/pagerduty
// @Param id path int true "id"
// @Param scopeConfigId path int true "scopeConfigId"
// @Success 200 {object} models.ProjectScopeOutput
// @Failure 400 {object} shared.ApiBody "Bad Request"
// @Failure 500 {object} shared.ApiBody "Internal Error"
// @Router /plugins/pagerduty/scope-config/{scopeConfigId}/projects [GET]
func GetServicesByScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
return dsHelper.ScopeConfigApi.GetProjectsByScopeConfig(input)
}

// DeleteScopeConfig delete a scope config
// @Summary delete a scope config
// @Description delete a scope config
// @Tags plugins/pagerduty
// @Param id path int true "id"
// @Param connectionId path int true "connectionId"
// @Success 200
// @Failure 400 {object} shared.ApiBody "Bad Request"
// @Failure 500 {object} shared.ApiBody "Internal Error"
// @Router /plugins/pagerduty/connections/{connectionId}/scope-configs/{id} [DELETE]
func DeleteScopeConfig(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
return dsHelper.ScopeConfigApi.Delete(input)
}
29 changes: 28 additions & 1 deletion backend/plugins/pagerduty/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (p PagerDuty) Scope() plugin.ToolLayerScope {
}

func (p PagerDuty) ScopeConfig() dal.Tabler {
return nil
return &models.PagerdutyScopeConfig{}
}

func (p PagerDuty) SubTaskMetas() []plugin.SubTaskMeta {
Expand Down Expand Up @@ -109,6 +109,21 @@ func (p PagerDuty) PrepareTaskData(taskCtx plugin.TaskContext, options map[strin
return nil, errors.Default.Wrap(err, "unable to get Pagerduty connection by the given connection ID")
}

// Load ScopeConfig from database if only ScopeConfigId is provided
if op.ScopeConfig == nil && op.ScopeConfigId != 0 {
var scopeConfig models.PagerdutyScopeConfig
db := taskCtx.GetDal()
err = db.First(&scopeConfig, dal.Where("id = ?", op.ScopeConfigId))
if err != nil && !db.IsErrorNotFound(err) {
return nil, errors.BadInput.Wrap(err, "fail to get scopeConfig")
}
op.ScopeConfig = &scopeConfig
}
// Initialize empty ScopeConfig if none provided
if op.ScopeConfig == nil {
op.ScopeConfig = new(models.PagerdutyScopeConfig)
}

client, err := helper.NewApiClientFromConnection(taskCtx.GetContext(), taskCtx, connection)

if err != nil {
Expand Down Expand Up @@ -168,6 +183,18 @@ func (p PagerDuty) ApiResources() map[string]map[string]plugin.ApiResourceHandle
"connections/:connectionId/scopes/:scopeId/latest-sync-state": {
"GET": api.GetScopeLatestSyncState,
},
"connections/:connectionId/scope-configs": {
"POST": api.CreateScopeConfig,
"GET": api.GetScopeConfigList,
},
"connections/:connectionId/scope-configs/:scopeConfigId": {
"PATCH": api.PatchScopeConfig,
"GET": api.GetScopeConfig,
"DELETE": api.DeleteScopeConfig,
},
"scope-config/:scopeConfigId/projects": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change it to connections/:connectionId/scope-configs/:scopeConfigId/projects to comply RESTful convention.

"GET": api.GetServicesByScopeConfig,
},
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
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 migrationscripts

import (
"github.com/apache/incubator-devlake/core/context"
"github.com/apache/incubator-devlake/core/errors"
"github.com/apache/incubator-devlake/core/plugin"
)

var _ plugin.MigrationScript = (*addFilterFieldsToPagerDutyScopeConfig20251003)(nil)

type PagerDutyScopeConfig20251003 struct {
PriorityFilter []string `mapstructure:"priorityFilter" json:"priorityFilter" gorm:"type:text;serializer:json"`
UrgencyFilter []string `mapstructure:"urgencyFilter" json:"urgencyFilter" gorm:"type:text;serializer:json"`
}

func (o PagerDutyScopeConfig20251003) TableName() string {
return "_tool_pagerduty_scope_configs"
}

type addFilterFieldsToPagerDutyScopeConfig20251003 struct{}

func (script *addFilterFieldsToPagerDutyScopeConfig20251003) Up(basicRes context.BasicRes) errors.Error {
return basicRes.GetDal().AutoMigrate(&PagerDutyScopeConfig20251003{})
}

func (*addFilterFieldsToPagerDutyScopeConfig20251003) Version() uint64 {
return 20251003000000
}

func (script *addFilterFieldsToPagerDutyScopeConfig20251003) Name() string {
return "add priority_filter and urgency_filter fields to table _tool_pagerduty_scope_configs"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
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 migrationscripts

import (
"github.com/apache/incubator-devlake/core/context"
"github.com/apache/incubator-devlake/core/errors"
"github.com/apache/incubator-devlake/core/plugin"
)

var _ plugin.MigrationScript = (*addScopeConfigIdToServices20251003)(nil)

type service20251003 struct {
ScopeConfigId uint64 `gorm:"column:scope_config_id"`
}

func (service20251003) TableName() string {
return "_tool_pagerduty_services"
}

type addScopeConfigIdToServices20251003 struct{}

func (script *addScopeConfigIdToServices20251003) Up(basicRes context.BasicRes) errors.Error {
return basicRes.GetDal().AutoMigrate(&service20251003{})
}

func (*addScopeConfigIdToServices20251003) Version() uint64 {
return 20251003000001
}

func (script *addScopeConfigIdToServices20251003) Name() string {
return "add scope_config_id to _tool_pagerduty_services"
}
2 changes: 2 additions & 0 deletions backend/plugins/pagerduty/models/migrationscripts/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@ func All() []plugin.MigrationScript {
new(addIncidentPriority),
new(addPagerDutyScopeConfig20231214),
new(addPagerDutyScopeConfig20240614),
new(addFilterFieldsToPagerDutyScopeConfig20251003),
new(addScopeConfigIdToServices20251003),
}
}
2 changes: 2 additions & 0 deletions backend/plugins/pagerduty/models/scope_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (

type PagerdutyScopeConfig struct {
common.ScopeConfig `mapstructure:",squash" json:",inline" gorm:"embedded"`
PriorityFilter []string `mapstructure:"priorityFilter" json:"priorityFilter" gorm:"type:text;serializer:json"`
UrgencyFilter []string `mapstructure:"urgencyFilter" json:"urgencyFilter" gorm:"type:text;serializer:json"`
}

func (p PagerdutyScopeConfig) TableName() string {
Expand Down
15 changes: 15 additions & 0 deletions backend/plugins/pagerduty/tasks/incidents_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@ func CollectIncidents(taskCtx plugin.SubTaskContext) errors.Error {
query.Set("limit", fmt.Sprintf("%d", reqData.Pager.Size))
query.Set("offset", fmt.Sprintf("%d", reqData.Pager.Skip))
query.Set("total", "true")

// Apply Priority filters if configured
if data.Options.ScopeConfig != nil && len(data.Options.ScopeConfig.PriorityFilter) > 0 {
for _, priority := range data.Options.ScopeConfig.PriorityFilter {
query.Add("priorities[]", priority)
}
}

// Apply Urgency filters if configured
if data.Options.ScopeConfig != nil && len(data.Options.ScopeConfig.UrgencyFilter) > 0 {
for _, urgency := range data.Options.ScopeConfig.UrgencyFilter {
query.Add("urgencies[]", urgency)
}
}

return query, nil
},
ResponseParser: func(res *http.Response) ([]json.RawMessage, errors.Error) {
Expand Down
8 changes: 8 additions & 0 deletions config-ui/src/plugins/components/scope-config-form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { AzureTransformation } from '@/plugins/register/azure';
import { TapdTransformation } from '@/plugins/register/tapd';
import { BambooTransformation } from '@/plugins/register/bamboo';
import { CircleCITransformation } from '@/plugins/register/circleci';
import { PagerDutyTransformation } from '@/plugins/register/pagerduty';
import { DOC_URL } from '@/release';
import { operator } from '@/utils';

Expand Down Expand Up @@ -285,6 +286,13 @@ export const ScopeConfigForm = ({
setTransformation={setTransformation}
/>
)}

{plugin === 'pagerduty' && (
<PagerDutyTransformation
transformation={transformation}
setTransformation={setTransformation}
/>
)}
</Form>
</Card>
<Flex justify="flex-end" gap="small">
Expand Down
7 changes: 7 additions & 0 deletions config-ui/src/plugins/register/pagerduty/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,11 @@ export const PagerDutyConfig: IPluginConfig = {
dataScope: {
title: 'Services',
},
scopeConfig: {
entities: ['TICKET'],
transformation: {
priorityFilter: [],
urgencyFilter: [],
},
},
};
1 change: 1 addition & 0 deletions config-ui/src/plugins/register/pagerduty/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
*/

export * from './config';
export * from './transformation';
Loading
Loading