@@ -6,6 +6,7 @@ package repo
66import (
77 "context"
88 "fmt"
9+ "strings"
910
1011 "code.gitea.io/gitea/models/db"
1112 "code.gitea.io/gitea/models/unit"
@@ -162,6 +163,42 @@ func (cfg *PullRequestsConfig) GetDefaultMergeStyle() MergeStyle {
162163 return MergeStyleMerge
163164}
164165
166+ type ActionsConfig struct {
167+ DisabledWorkflows []string
168+ }
169+
170+ func (cfg * ActionsConfig ) EnableWorkflow (file string ) {
171+ cfg .DisabledWorkflows = util .SliceRemoveAll (cfg .DisabledWorkflows , file )
172+ }
173+
174+ func (cfg * ActionsConfig ) ToString () string {
175+ return strings .Join (cfg .DisabledWorkflows , "," )
176+ }
177+
178+ func (cfg * ActionsConfig ) IsWorkflowDisabled (file string ) bool {
179+ return util .SliceContains (cfg .DisabledWorkflows , file )
180+ }
181+
182+ func (cfg * ActionsConfig ) DisableWorkflow (file string ) {
183+ for _ , workflow := range cfg .DisabledWorkflows {
184+ if file == workflow {
185+ return
186+ }
187+ }
188+
189+ cfg .DisabledWorkflows = append (cfg .DisabledWorkflows , file )
190+ }
191+
192+ // FromDB fills up a ActionsConfig from serialized format.
193+ func (cfg * ActionsConfig ) FromDB (bs []byte ) error {
194+ return json .UnmarshalHandleDoubleEncode (bs , & cfg )
195+ }
196+
197+ // ToDB exports a ActionsConfig to a serialized format.
198+ func (cfg * ActionsConfig ) ToDB () ([]byte , error ) {
199+ return json .Marshal (cfg )
200+ }
201+
165202// BeforeSet is invoked from XORM before setting the value of a field of this object.
166203func (r * RepoUnit ) BeforeSet (colName string , val xorm.Cell ) {
167204 switch colName {
@@ -175,7 +212,9 @@ func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) {
175212 r .Config = new (PullRequestsConfig )
176213 case unit .TypeIssues :
177214 r .Config = new (IssuesConfig )
178- case unit .TypeCode , unit .TypeReleases , unit .TypeWiki , unit .TypeProjects , unit .TypePackages , unit .TypeActions :
215+ case unit .TypeActions :
216+ r .Config = new (ActionsConfig )
217+ case unit .TypeCode , unit .TypeReleases , unit .TypeWiki , unit .TypeProjects , unit .TypePackages :
179218 fallthrough
180219 default :
181220 r .Config = new (UnitConfig )
@@ -218,6 +257,11 @@ func (r *RepoUnit) ExternalTrackerConfig() *ExternalTrackerConfig {
218257 return r .Config .(* ExternalTrackerConfig )
219258}
220259
260+ // ActionsConfig returns config for unit.ActionsConfig
261+ func (r * RepoUnit ) ActionsConfig () * ActionsConfig {
262+ return r .Config .(* ActionsConfig )
263+ }
264+
221265func getUnitsByRepoID (ctx context.Context , repoID int64 ) (units []* RepoUnit , err error ) {
222266 var tmpUnits []* RepoUnit
223267 if err := db .GetEngine (ctx ).Where ("repo_id = ?" , repoID ).Find (& tmpUnits ); err != nil {
0 commit comments