<commit_before>package sdk

import (
	"fmt"
	"sort"

	"github.com/fsamin/go-dump"
)

const (
	NodeTypePipeline     = "pipeline"
	NodeTypeJoin         = "join"
	NodeTypeOutGoingHook = "outgoinghook"
	NodeTypeFork         = "fork"
)

// Node represents a node in a workflow
type Node struct {
	ID                  int64             `json:"id" db:"id"`
	WorkflowID          int64             `json:"workflow_id" db:"workflow_id"`
	Name                string            `json:"name" db:"name"`
	Ref                 string            `json:"ref" db:"ref"`
	Type                string            `json:"type" db:"type"`
	Triggers            []NodeTrigger     `json:"triggers" db:"-"`
	TriggerID           int64             `json:"-" db:"-"`
	Context             *NodeContext      `json:"context" db:"-"`
	OutGoingHookContext *NodeOutGoingHook `json:"outgoing_hook" db:"-"`
	JoinContext         []NodeJoin        `json:"parents" db:"-"`
	Hooks               []NodeHook        `json:"hooks" db:"-"`
	Groups              []GroupPermission `json:"groups,omitempty" db:"-"`
}

func (n Node) GetHook(UUID string) *NodeHook {
	for _, h := range n.Hooks {
		if h.UUID == UUID {
			return &h
		}
	}
	return nil
}

// NodeContext represents a node linked to a pipeline
type NodeContext struct {
	ID                        int64                  `json:"id" db:"id"`
	NodeID                    int64                  `json:"node_id" db:"node_id"`
	PipelineID                int64                  `json:"pipeline_id" db:"pipeline_id"`
	PipelineName              string                 `json:"-" db:"-"`
	ApplicationID             int64                  `json:"application_id" db:"application_id"`
	ApplicationName           string                 `json:"-" db:"-"`
	EnvironmentID             int64                  `json:"environment_id" db:"environment_id"`
	EnvironmentName           string                 `json:"-" db:"-"`
	ProjectIntegrationID      int64                  `json:"project_integration_id" db:"project_integration_id"`
	ProjectIntegrationName    string                 `json:"-" db:"-"`
	DefaultPayload            interface{}            `json:"default_payload,omitempty" db:"-"`
	DefaultPipelineParameters []Parameter            `json:"default_pipeline_parameters" db:"-"`
	Conditions                WorkflowNodeConditions `json:"conditions" db:"-"`
	Mutex                     bool                   `json:"mutex" db:"mutex"`
}

// FilterHooksConfig filter all hooks configuration and remove somme configuration key
func (n *Node) FilterHooksConfig(s ...string) {
	if n == nil {
		return
	}

	for _, h := range n.Hooks {
		for i := range s {
			for k := range h.Config {
				if k == s[i] {
					delete(h.Config, k)
					break
				}
			}
		}
	}
}

//AddTrigger adds a trigger to the destination node from the node found by its name
func (n *Node) AddTrigger(name string, dest Node) {<commit_msg>fix(api): missing workflow context fields for audits (#5562)<commit_after>package sdk

import (
	"fmt"
	"sort"

	"github.com/fsamin/go-dump"
)

const (
	NodeTypePipeline     = "pipeline"
	NodeTypeJoin         = "join"
	NodeTypeOutGoingHook = "outgoinghook"
	NodeTypeFork         = "fork"
)

// Node represents a node in a workflow
type Node struct {
	ID                  int64             `json:"id" db:"id"`
	WorkflowID          int64             `json:"workflow_id" db:"workflow_id"`
	Name                string            `json:"name" db:"name"`
	Ref                 string            `json:"ref" db:"ref"`
	Type                string            `json:"type" db:"type"`
	Triggers            []NodeTrigger     `json:"triggers" db:"-"`
	TriggerID           int64             `json:"-" db:"-"`
	Context             *NodeContext      `json:"context" db:"-"`
	OutGoingHookContext *NodeOutGoingHook `json:"outgoing_hook" db:"-"`
	JoinContext         []NodeJoin        `json:"parents" db:"-"`
	Hooks               []NodeHook        `json:"hooks" db:"-"`
	Groups              []GroupPermission `json:"groups,omitempty" db:"-"`
}

func (n Node) GetHook(UUID string) *NodeHook {
	for _, h := range n.Hooks {
		if h.UUID == UUID {
			return &h
		}
	}
	return nil
}

// NodeContext represents a node linked to a pipeline
type NodeContext struct {
	ID                        int64                  `json:"id" db:"id"`
	NodeID                    int64                  `json:"node_id" db:"node_id"`
	PipelineID                int64                  `json:"pipeline_id" db:"pipeline_id"`
	PipelineName              string                 `json:"pipeline_name" db:"-"`
	ApplicationID             int64                  `json:"application_id" db:"application_id"`
	ApplicationName           string                 `json:"application_name" db:"-"`
	EnvironmentID             int64                  `json:"environment_id" db:"environment_id"`
	EnvironmentName           string                 `json:"environment_name" db:"-"`
	ProjectIntegrationID      int64                  `json:"project_integration_id" db:"project_integration_id"`
	ProjectIntegrationName    string                 `json:"project_integration_name" db:"-"`
	DefaultPayload            interface{}            `json:"default_payload,omitempty" db:"-"`
	DefaultPipelineParameters []Parameter            `json:"default_pipeline_parameters" db:"-"`
	Conditions                WorkflowNodeConditions `json:"conditions" db:"-"`
	Mutex                     bool                   `json:"mutex" db:"mutex"`
}

// FilterHooksConfig filter all hooks configuration and remove somme configuration key
func (n *Node) FilterHooksConfig(s ...string) {
	if n == nil {
		return
	}

	for _, h := range n.Hooks {
		for i := range s {
			for k := range h.Config {
				if k == s[i] {
					delete(h.Config, k)
					break
				}
			}
		}
	}
}

//AddTrigger adds a trigger to the destination node from the node found by its name
func (n *Node) AddTrigger(name string, dest Node) {
{'fraction_non_alphanumeric': 0.11864406779661017, 'fraction_numerical': 0.006779661016949152, 'mean_word_length': 1.9183976261127595, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2317499', 'n_tokens_mistral': 1782, 'n_tokens_neox': 1672, 'n_words': 439}