@@ -146,3 +146,157 @@ func (c *Compiler) buildCloseEntityJob(data *WorkflowData, mainJobName string, c
146146 TargetRepoSlug : config .TargetRepoSlug ,
147147 })
148148}
149+
150+ // closeEntityDefinition holds all parameters for a close entity type
151+ type closeEntityDefinition struct {
152+ EntityType CloseEntityType
153+ ConfigKey string
154+ EnvVarPrefix string
155+ JobName string
156+ StepName string
157+ OutputNumberKey string
158+ OutputURLKey string
159+ EventNumberPath1 string
160+ EventNumberPath2 string
161+ ScriptGetter func () string
162+ PermissionsFunc func () * Permissions
163+ Logger * logger.Logger
164+ }
165+
166+ // closeEntityRegistry holds all close entity definitions
167+ var closeEntityRegistry = []closeEntityDefinition {
168+ {
169+ EntityType : CloseEntityIssue ,
170+ ConfigKey : "close-issue" ,
171+ EnvVarPrefix : "GH_AW_CLOSE_ISSUE" ,
172+ JobName : "close_issue" ,
173+ StepName : "Close Issue" ,
174+ OutputNumberKey : "issue_number" ,
175+ OutputURLKey : "issue_url" ,
176+ EventNumberPath1 : "github.event.issue.number" ,
177+ EventNumberPath2 : "github.event.comment.issue.number" ,
178+ ScriptGetter : getCloseIssueScript ,
179+ PermissionsFunc : NewPermissionsContentsReadIssuesWrite ,
180+ Logger : logger .New ("workflow:close_issue" ),
181+ },
182+ {
183+ EntityType : CloseEntityPullRequest ,
184+ ConfigKey : "close-pull-request" ,
185+ EnvVarPrefix : "GH_AW_CLOSE_PR" ,
186+ JobName : "close_pull_request" ,
187+ StepName : "Close Pull Request" ,
188+ OutputNumberKey : "pull_request_number" ,
189+ OutputURLKey : "pull_request_url" ,
190+ EventNumberPath1 : "github.event.pull_request.number" ,
191+ EventNumberPath2 : "github.event.comment.pull_request.number" ,
192+ ScriptGetter : getClosePullRequestScript ,
193+ PermissionsFunc : NewPermissionsContentsReadPRWrite ,
194+ Logger : logger .New ("workflow:close_pull_request" ),
195+ },
196+ {
197+ EntityType : CloseEntityDiscussion ,
198+ ConfigKey : "close-discussion" ,
199+ EnvVarPrefix : "GH_AW_CLOSE_DISCUSSION" ,
200+ JobName : "close_discussion" ,
201+ StepName : "Close Discussion" ,
202+ OutputNumberKey : "discussion_number" ,
203+ OutputURLKey : "discussion_url" ,
204+ EventNumberPath1 : "github.event.discussion.number" ,
205+ EventNumberPath2 : "github.event.comment.discussion.number" ,
206+ ScriptGetter : getCloseDiscussionScript ,
207+ PermissionsFunc : NewPermissionsContentsReadDiscussionsWrite ,
208+ Logger : logger .New ("workflow:close_discussion" ),
209+ },
210+ }
211+
212+ // Type aliases for backward compatibility
213+ type CloseIssuesConfig = CloseEntityConfig
214+ type ClosePullRequestsConfig = CloseEntityConfig
215+ type CloseDiscussionsConfig = CloseEntityConfig
216+
217+ // parseCloseIssuesConfig handles close-issue configuration
218+ func (c * Compiler ) parseCloseIssuesConfig (outputMap map [string ]any ) * CloseIssuesConfig {
219+ def := closeEntityRegistry [0 ] // issue
220+ params := CloseEntityJobParams {
221+ EntityType : def .EntityType ,
222+ ConfigKey : def .ConfigKey ,
223+ }
224+ return c .parseCloseEntityConfig (outputMap , params , def .Logger )
225+ }
226+
227+ // parseClosePullRequestsConfig handles close-pull-request configuration
228+ func (c * Compiler ) parseClosePullRequestsConfig (outputMap map [string ]any ) * ClosePullRequestsConfig {
229+ def := closeEntityRegistry [1 ] // pull request
230+ params := CloseEntityJobParams {
231+ EntityType : def .EntityType ,
232+ ConfigKey : def .ConfigKey ,
233+ }
234+ return c .parseCloseEntityConfig (outputMap , params , def .Logger )
235+ }
236+
237+ // parseCloseDiscussionsConfig handles close-discussion configuration
238+ func (c * Compiler ) parseCloseDiscussionsConfig (outputMap map [string ]any ) * CloseDiscussionsConfig {
239+ def := closeEntityRegistry [2 ] // discussion
240+ params := CloseEntityJobParams {
241+ EntityType : def .EntityType ,
242+ ConfigKey : def .ConfigKey ,
243+ }
244+ return c .parseCloseEntityConfig (outputMap , params , def .Logger )
245+ }
246+
247+ // buildCreateOutputCloseIssueJob creates the close_issue job
248+ func (c * Compiler ) buildCreateOutputCloseIssueJob (data * WorkflowData , mainJobName string ) (* Job , error ) {
249+ def := closeEntityRegistry [0 ] // issue
250+ params := CloseEntityJobParams {
251+ EntityType : def .EntityType ,
252+ ConfigKey : def .ConfigKey ,
253+ EnvVarPrefix : def .EnvVarPrefix ,
254+ JobName : def .JobName ,
255+ StepName : def .StepName ,
256+ OutputNumberKey : def .OutputNumberKey ,
257+ OutputURLKey : def .OutputURLKey ,
258+ EventNumberPath1 : def .EventNumberPath1 ,
259+ EventNumberPath2 : def .EventNumberPath2 ,
260+ ScriptGetter : def .ScriptGetter ,
261+ PermissionsFunc : def .PermissionsFunc ,
262+ }
263+ return c .buildCloseEntityJob (data , mainJobName , data .SafeOutputs .CloseIssues , params , def .Logger )
264+ }
265+
266+ // buildCreateOutputClosePullRequestJob creates the close_pull_request job
267+ func (c * Compiler ) buildCreateOutputClosePullRequestJob (data * WorkflowData , mainJobName string ) (* Job , error ) {
268+ def := closeEntityRegistry [1 ] // pull request
269+ params := CloseEntityJobParams {
270+ EntityType : def .EntityType ,
271+ ConfigKey : def .ConfigKey ,
272+ EnvVarPrefix : def .EnvVarPrefix ,
273+ JobName : def .JobName ,
274+ StepName : def .StepName ,
275+ OutputNumberKey : def .OutputNumberKey ,
276+ OutputURLKey : def .OutputURLKey ,
277+ EventNumberPath1 : def .EventNumberPath1 ,
278+ EventNumberPath2 : def .EventNumberPath2 ,
279+ ScriptGetter : def .ScriptGetter ,
280+ PermissionsFunc : def .PermissionsFunc ,
281+ }
282+ return c .buildCloseEntityJob (data , mainJobName , data .SafeOutputs .ClosePullRequests , params , def .Logger )
283+ }
284+
285+ // buildCreateOutputCloseDiscussionJob creates the close_discussion job
286+ func (c * Compiler ) buildCreateOutputCloseDiscussionJob (data * WorkflowData , mainJobName string ) (* Job , error ) {
287+ def := closeEntityRegistry [2 ] // discussion
288+ params := CloseEntityJobParams {
289+ EntityType : def .EntityType ,
290+ ConfigKey : def .ConfigKey ,
291+ EnvVarPrefix : def .EnvVarPrefix ,
292+ JobName : def .JobName ,
293+ StepName : def .StepName ,
294+ OutputNumberKey : def .OutputNumberKey ,
295+ OutputURLKey : def .OutputURLKey ,
296+ EventNumberPath1 : def .EventNumberPath1 ,
297+ EventNumberPath2 : def .EventNumberPath2 ,
298+ ScriptGetter : def .ScriptGetter ,
299+ PermissionsFunc : def .PermissionsFunc ,
300+ }
301+ return c .buildCloseEntityJob (data , mainJobName , data .SafeOutputs .CloseDiscussions , params , def .Logger )
302+ }
0 commit comments