@@ -35,6 +35,19 @@ type UpdateEntityJobParams struct {
3535 Condition ConditionNode // Job condition expression
3636}
3737
38+ // UpdateEntityJobBuilder encapsulates entity-specific configuration for building update jobs
39+ type UpdateEntityJobBuilder struct {
40+ EntityType UpdateEntityType
41+ ConfigKey string
42+ JobName string
43+ StepName string
44+ ScriptGetter func () string
45+ PermissionsFunc func () * Permissions
46+ BuildCustomEnvVars func (* UpdateEntityConfig ) []string
47+ BuildOutputs func () map [string ]string
48+ BuildEventCondition func (string ) ConditionNode // Optional: builds event condition if target is empty
49+ }
50+
3851// parseUpdateEntityConfig is a generic function to parse update entity configurations
3952func (c * Compiler ) parseUpdateEntityConfig (outputMap map [string ]any , params UpdateEntityJobParams , logger * logger.Logger , parseSpecificFields func (map [string ]any , * UpdateEntityConfig )) * UpdateEntityConfig {
4053 if configData , exists := outputMap [params .ConfigKey ]; exists {
@@ -94,3 +107,51 @@ func (c *Compiler) buildUpdateEntityJob(data *WorkflowData, mainJobName string,
94107 TargetRepoSlug : config .TargetRepoSlug ,
95108 })
96109}
110+
111+ // buildUpdateEntityJobWithConfig is a higher-level helper that encapsulates the common pattern
112+ // of building update entity jobs, reducing duplication across issue/PR/release builders
113+ func (c * Compiler ) buildUpdateEntityJobWithConfig (
114+ data * WorkflowData ,
115+ mainJobName string ,
116+ config * UpdateEntityConfig ,
117+ builder UpdateEntityJobBuilder ,
118+ logger * logger.Logger ,
119+ ) (* Job , error ) {
120+ if config == nil {
121+ return nil , fmt .Errorf ("safe-outputs.%s configuration is required" , builder .ConfigKey )
122+ }
123+
124+ // Build entity-specific custom environment variables
125+ customEnvVars := builder .BuildCustomEnvVars (config )
126+
127+ // Append target configuration environment variables
128+ customEnvVars = append (customEnvVars , BuildTargetEnvVar ("GH_AW_UPDATE_TARGET" , config .Target )... )
129+
130+ // Build entity-specific outputs
131+ outputs := builder .BuildOutputs ()
132+
133+ // Build job condition with safe output type check
134+ jobCondition := BuildSafeOutputType (builder .JobName )
135+
136+ // Add optional event condition if target is empty and event condition builder is provided
137+ if builder .BuildEventCondition != nil && config .Target == "" {
138+ eventCondition := builder .BuildEventCondition (config .Target )
139+ jobCondition = buildAnd (jobCondition , eventCondition )
140+ }
141+
142+ // Create UpdateEntityJobParams with all the configuration
143+ params := UpdateEntityJobParams {
144+ EntityType : builder .EntityType ,
145+ ConfigKey : builder .ConfigKey ,
146+ JobName : builder .JobName ,
147+ StepName : builder .StepName ,
148+ ScriptGetter : builder .ScriptGetter ,
149+ PermissionsFunc : builder .PermissionsFunc ,
150+ CustomEnvVars : customEnvVars ,
151+ Outputs : outputs ,
152+ Condition : jobCondition ,
153+ }
154+
155+ // Use the existing buildUpdateEntityJob to create the job
156+ return c .buildUpdateEntityJob (data , mainJobName , config , params , logger )
157+ }
0 commit comments