@@ -51,12 +51,12 @@ func CreateOrganizationRepository(ctx context.Context, gc gitprovider.Client, do
5151 return fmt .Errorf ("failed to create repository: %w" , err )
5252 }
5353
54- if err := createCodeownersFile (ctx , repo , spec .Maintainers ); err != nil {
54+ if err := setupProjectStructure (ctx , repo , spec .Maintainers ); err != nil {
5555 if cerr := repo .Delete (ctx ); cerr != nil {
5656 err = errors .Join (err , cerr )
5757 }
5858
59- return fmt .Errorf ("failed to add CODEOWNERS file : %w" , err )
59+ return fmt .Errorf ("failed to create initial project structure : %w" , err )
6060 }
6161
6262 logger .Info ("successfully created organization repository" , "domain" , domain , "repository" , spec .RepositoryName )
@@ -69,12 +69,12 @@ func CreateOrganizationRepository(ctx context.Context, gc gitprovider.Client, do
6969 if ! created {
7070 logger .Info ("using existing repository" , "domain" , domain , "repository" , spec .RepositoryName )
7171 } else {
72- if err := createCodeownersFile (ctx , repo , spec .Maintainers ); err != nil {
72+ if err := setupProjectStructure (ctx , repo , spec .Maintainers ); err != nil {
7373 if cerr := repo .Delete (ctx ); cerr != nil {
7474 err = errors .Join (err , cerr )
7575 }
7676
77- return fmt .Errorf ("failed to add CODEOWNERS file : %w" , err )
77+ return fmt .Errorf ("failed to create initial project structure : %w" , err )
7878 }
7979
8080 logger .Info ("successfully created organization repository" , "domain" , domain , "repository" , spec .RepositoryName )
@@ -120,12 +120,12 @@ func CreateUserRepository(ctx context.Context, gc gitprovider.Client, domain str
120120 return fmt .Errorf ("failed to create repository: %w" , err )
121121 }
122122
123- if err := createCodeownersFile (ctx , repo , spec .Maintainers ); err != nil {
123+ if err := setupProjectStructure (ctx , repo , spec .Maintainers ); err != nil {
124124 if cerr := repo .Delete (ctx ); cerr != nil {
125125 err = errors .Join (err , cerr )
126126 }
127127
128- return fmt .Errorf ("failed to add CODEOWNERS file : %w" , err )
128+ return fmt .Errorf ("failed to create initial project structure : %w" , err )
129129 }
130130
131131 logger .Info ("successfully created user repository" , "domain" , domain , "repository" , spec .RepositoryName )
@@ -138,12 +138,12 @@ func CreateUserRepository(ctx context.Context, gc gitprovider.Client, domain str
138138 if ! created {
139139 logger .Info ("using existing repository" , "domain" , domain , "repository" , spec .RepositoryName )
140140 } else {
141- if err := createCodeownersFile (ctx , repo , spec .Maintainers ); err != nil {
141+ if err := setupProjectStructure (ctx , repo , spec .Maintainers ); err != nil {
142142 if cerr := repo .Delete (ctx ); cerr != nil {
143143 err = errors .Join (err , cerr )
144144 }
145145
146- return fmt .Errorf ("failed to add CODEOWNERS file : %w" , err )
146+ return fmt .Errorf ("failed to create initial project structure : %w" , err )
147147 }
148148
149149 logger .Info ("successfully created user repository" , "domain" , domain , "repository" , spec .RepositoryName )
@@ -246,32 +246,44 @@ type Repositories interface {
246246 Commits () gitprovider.CommitClient
247247}
248248
249- func createCodeownersFile (ctx context.Context , repo Repositories , maintainers []string ) error {
250- if len (maintainers ) == 0 {
251- return nil
252- }
253-
249+ func setupProjectStructure (ctx context.Context , repo Repositories , maintainers []string ) error {
254250 logger := log .FromContext (ctx )
255251
256- content := strings. Builder {}
252+ var files []gitprovider. CommitFile
257253
258- for _ , m := range maintainers {
259- _ , _ = content .WriteString (fmt .Sprintf ("%s\n " , m ))
260- }
254+ if len (maintainers ) > 0 {
255+ content := strings.Builder {}
256+
257+ for _ , m := range maintainers {
258+ _ , _ = content .WriteString (fmt .Sprintf ("%s\n " , m ))
259+ }
261260
262- files := []gitprovider.CommitFile {
263- {
261+ files = append (files , gitprovider.CommitFile {
264262 Path : gitprovider .StringVar ("CODEOWNERS" ),
265263 Content : gitprovider .StringVar (content .String ()),
266- },
264+ })
267265 }
268266
269- commit , err := repo .Commits ().Create (ctx , "main" , "adding CODEOWNERS" , files )
267+ files = append (files , gitprovider.CommitFile {
268+ Path : gitprovider .StringVar ("generators/.keep" ),
269+ Content : gitprovider .StringVar ("" ),
270+ }, gitprovider.CommitFile {
271+ Path : gitprovider .StringVar ("products/.keep" ),
272+ Content : gitprovider .StringVar ("" ),
273+ }, gitprovider.CommitFile {
274+ Path : gitprovider .StringVar ("subscriptions/.keep" ),
275+ Content : gitprovider .StringVar ("" ),
276+ }, gitprovider.CommitFile {
277+ Path : gitprovider .StringVar ("targets/.keep" ),
278+ Content : gitprovider .StringVar ("" ),
279+ })
280+
281+ commit , err := repo .Commits ().Create (ctx , "main" , "creating initial project structure" , files )
270282 if err != nil {
271- return fmt .Errorf ("failed to create CODEOWNERS file : %w" , err )
283+ return fmt .Errorf ("failed to create project structure : %w" , err )
272284 }
273285
274- logger .Info ("successfully added CODEOWNERS " , "url" , commit .Get ().URL )
286+ logger .Info ("successfully created initial project structure " , "url" , commit .Get ().URL )
275287
276288 return nil
277289}
0 commit comments