@@ -21,6 +21,7 @@ import (
21
21
"github.com/charmbracelet/soft-serve/server/storage"
22
22
"github.com/charmbracelet/soft-serve/server/task"
23
23
"github.com/charmbracelet/soft-serve/server/utils"
24
+ "github.com/charmbracelet/soft-serve/server/webhook"
24
25
)
25
26
26
27
func (d * Backend ) reposPath () string {
@@ -88,7 +89,16 @@ func (d *Backend) CreateRepository(ctx context.Context, name string, user proto.
88
89
return nil , err
89
90
}
90
91
91
- return d .Repository (ctx , name )
92
+ r , err := d .Repository (ctx , name )
93
+ if err != nil {
94
+ return nil , err
95
+ }
96
+
97
+ if err := webhook .SendRepositoryEvent (ctx , user , r , webhook .RepositoryEventCreated ); err != nil {
98
+ return r , err
99
+ }
100
+
101
+ return r , nil
92
102
}
93
103
94
104
// ImportRepository imports a repository from remote.
@@ -197,7 +207,7 @@ func (d *Backend) ImportRepository(_ context.Context, name string, user proto.Us
197
207
return err
198
208
}
199
209
200
- return nil
210
+ return webhook . SendRepositoryEvent ( ctx , user , r , webhook . RepositoryEventImported )
201
211
})
202
212
203
213
go func () {
@@ -262,12 +272,18 @@ func (d *Backend) DeleteRepository(ctx context.Context, name string) error {
262
272
return proto .ErrRepoNotFound
263
273
}
264
274
265
- return err
275
+ user := proto .UserFromContext (ctx )
276
+ r , err := d .Repository (ctx , name )
277
+ if err != nil {
278
+ return err
279
+ }
280
+
281
+ return webhook .SendRepositoryEvent (ctx , user , r , webhook .RepositoryEventDeleted )
266
282
}
267
283
268
284
// DeleteUserRepositories deletes all user repositories.
269
285
func (d * Backend ) DeleteUserRepositories (ctx context.Context , username string ) error {
270
- return d .db .TransactionContext (ctx , func (tx * db.Tx ) error {
286
+ if err := d .db .TransactionContext (ctx , func (tx * db.Tx ) error {
271
287
user , err := d .store .FindUserByUsername (ctx , tx , username )
272
288
if err != nil {
273
289
return err
@@ -285,7 +301,11 @@ func (d *Backend) DeleteUserRepositories(ctx context.Context, username string) e
285
301
}
286
302
287
303
return nil
288
- })
304
+ }); err != nil {
305
+ return db .WrapError (err )
306
+ }
307
+
308
+ return nil
289
309
}
290
310
291
311
// RenameRepository renames a repository.
@@ -301,6 +321,11 @@ func (d *Backend) RenameRepository(ctx context.Context, oldName string, newName
301
321
if err := utils .ValidateRepo (newName ); err != nil {
302
322
return err
303
323
}
324
+
325
+ if oldName == newName {
326
+ return nil
327
+ }
328
+
304
329
oldRepo := oldName + ".git"
305
330
newRepo := newName + ".git"
306
331
op := filepath .Join (d .reposPath (), oldRepo )
@@ -331,6 +356,16 @@ func (d *Backend) RenameRepository(ctx context.Context, oldName string, newName
331
356
return db .WrapError (err )
332
357
}
333
358
359
+ user := proto .UserFromContext (ctx )
360
+ repo , err := d .Repository (ctx , newName )
361
+ if err != nil {
362
+ return err
363
+ }
364
+
365
+ if err := webhook .SendRepositoryEvent (ctx , user , repo , webhook .RepositoryEventRenamed ); err != nil {
366
+ return err
367
+ }
368
+
334
369
return nil
335
370
}
336
371
@@ -537,7 +572,7 @@ func (d *Backend) SetPrivate(ctx context.Context, name string, private bool) err
537
572
// Delete cache
538
573
d .cache .Delete (name )
539
574
540
- return db .WrapError (
575
+ if err := db .WrapError (
541
576
d .db .TransactionContext (ctx , func (tx * db.Tx ) error {
542
577
fp := filepath .Join (rp , "git-daemon-export-ok" )
543
578
if ! private {
@@ -556,7 +591,23 @@ func (d *Backend) SetPrivate(ctx context.Context, name string, private bool) err
556
591
557
592
return d .store .SetRepoIsPrivateByName (ctx , tx , name , private )
558
593
}),
559
- )
594
+ ); err != nil {
595
+ return err
596
+ }
597
+
598
+ user := proto .UserFromContext (ctx )
599
+ repo , err := d .Repository (ctx , name )
600
+ if err != nil {
601
+ return err
602
+ }
603
+
604
+ if repo .IsPrivate () != ! private {
605
+ if err := webhook .SendRepositoryEvent (ctx , user , repo , webhook .RepositoryEventVisibilityChanged ); err != nil {
606
+ return err
607
+ }
608
+ }
609
+
610
+ return nil
560
611
}
561
612
562
613
// SetProjectName sets the project name of a repository.
@@ -651,6 +702,11 @@ func (r *repo) IsHidden() bool {
651
702
return r .repo .Hidden
652
703
}
653
704
705
+ // CreatedAt returns the repository's creation time.
706
+ func (r * repo ) CreatedAt () time.Time {
707
+ return r .repo .CreatedAt
708
+ }
709
+
654
710
// UpdatedAt returns the repository's last update time.
655
711
func (r * repo ) UpdatedAt () time.Time {
656
712
// Try to read the last modified time from the info directory.
0 commit comments