@@ -42,7 +42,6 @@ import (
42
42
"github.com/unknwon/com"
43
43
ini "gopkg.in/ini.v1"
44
44
"xorm.io/builder"
45
- "xorm.io/xorm"
46
45
)
47
46
48
47
var repoWorkingPool = sync .NewExclusivePool ()
@@ -173,8 +172,8 @@ type Repository struct {
173
172
* Mirror `xorm:"-"`
174
173
Status RepositoryStatus `xorm:"NOT NULL DEFAULT 0"`
175
174
176
- ExternalMetas map [string ]string `xorm:"-"`
177
- Units []* RepoUnit `xorm:"-"`
175
+ RenderingMetas map [string ]string `xorm:"-"`
176
+ Units []* RepoUnit `xorm:"-"`
178
177
179
178
IsFork bool `xorm:"INDEX NOT NULL DEFAULT false"`
180
179
ForkID int64 `xorm:"INDEX"`
@@ -559,27 +558,39 @@ func (repo *Repository) mustOwnerName(e Engine) string {
559
558
560
559
// ComposeMetas composes a map of metas for properly rendering issue links and external issue trackers.
561
560
func (repo * Repository ) ComposeMetas () map [string ]string {
562
- if repo .ExternalMetas == nil {
563
- repo . ExternalMetas = map [string ]string {
561
+ if repo .RenderingMetas == nil {
562
+ metas : = map [string ]string {
564
563
"user" : repo .MustOwner ().Name ,
565
564
"repo" : repo .Name ,
566
565
"repoPath" : repo .RepoPath (),
567
566
}
567
+
568
568
unit , err := repo .GetUnit (UnitTypeExternalTracker )
569
- if err != nil {
570
- return repo .ExternalMetas
569
+ if err == nil {
570
+ metas ["format" ] = unit .ExternalTrackerConfig ().ExternalTrackerFormat
571
+ switch unit .ExternalTrackerConfig ().ExternalTrackerStyle {
572
+ case markup .IssueNameStyleAlphanumeric :
573
+ metas ["style" ] = markup .IssueNameStyleAlphanumeric
574
+ default :
575
+ metas ["style" ] = markup .IssueNameStyleNumeric
576
+ }
571
577
}
572
578
573
- repo .ExternalMetas ["format" ] = unit .ExternalTrackerConfig ().ExternalTrackerFormat
574
- switch unit .ExternalTrackerConfig ().ExternalTrackerStyle {
575
- case markup .IssueNameStyleAlphanumeric :
576
- repo .ExternalMetas ["style" ] = markup .IssueNameStyleAlphanumeric
577
- default :
578
- repo .ExternalMetas ["style" ] = markup .IssueNameStyleNumeric
579
+ if repo .Owner .IsOrganization () {
580
+ teams := make ([]string , 0 , 5 )
581
+ _ = x .Table ("team_repo" ).
582
+ Join ("INNER" , "team" , "team.id = team_repo.team_id" ).
583
+ Where ("team_repo.repo_id = ?" , repo .ID ).
584
+ Select ("team.lower_name" ).
585
+ OrderBy ("team.lower_name" ).
586
+ Find (& teams )
587
+ metas ["teams" ] = "," + strings .Join (teams , "," ) + ","
588
+ metas ["org" ] = repo .Owner .LowerName
579
589
}
580
590
591
+ repo .RenderingMetas = metas
581
592
}
582
- return repo .ExternalMetas
593
+ return repo .RenderingMetas
583
594
}
584
595
585
596
// DeleteWiki removes the actual and local copy of repository wiki.
@@ -1246,20 +1257,6 @@ type CreateRepoOptions struct {
1246
1257
Status RepositoryStatus
1247
1258
}
1248
1259
1249
- // GenerateRepoOptions contains the template units to generate
1250
- type GenerateRepoOptions struct {
1251
- Name string
1252
- Description string
1253
- Private bool
1254
- GitContent bool
1255
- Topics bool
1256
- }
1257
-
1258
- // IsValid checks whether at least one option is chosen for generation
1259
- func (gro GenerateRepoOptions ) IsValid () bool {
1260
- return gro .GitContent || gro .Topics // or other items as they are added
1261
- }
1262
-
1263
1260
func getRepoInitFile (tp , name string ) ([]byte , error ) {
1264
1261
cleanedName := strings .TrimLeft (path .Clean ("/" + name ), "/" )
1265
1262
relPath := path .Join ("options" , tp , cleanedName )
@@ -1471,37 +1468,6 @@ func initRepository(e Engine, repoPath string, u *User, repo *Repository, opts C
1471
1468
return nil
1472
1469
}
1473
1470
1474
- // generateRepository initializes repository from template
1475
- func generateRepository (e Engine , repo , templateRepo * Repository ) (err error ) {
1476
- tmpDir := filepath .Join (os .TempDir (), "gitea-" + repo .Name + "-" + com .ToStr (time .Now ().Nanosecond ()))
1477
-
1478
- if err := os .MkdirAll (tmpDir , os .ModePerm ); err != nil {
1479
- return fmt .Errorf ("Failed to create dir %s: %v" , tmpDir , err )
1480
- }
1481
-
1482
- defer func () {
1483
- if err := os .RemoveAll (tmpDir ); err != nil {
1484
- log .Error ("RemoveAll: %v" , err )
1485
- }
1486
- }()
1487
-
1488
- if err = generateRepoCommit (e , repo , templateRepo , tmpDir ); err != nil {
1489
- return fmt .Errorf ("generateRepoCommit: %v" , err )
1490
- }
1491
-
1492
- // re-fetch repo
1493
- if repo , err = getRepositoryByID (e , repo .ID ); err != nil {
1494
- return fmt .Errorf ("getRepositoryByID: %v" , err )
1495
- }
1496
-
1497
- repo .DefaultBranch = "master"
1498
- if err = updateRepository (e , repo , false ); err != nil {
1499
- return fmt .Errorf ("updateRepository: %v" , err )
1500
- }
1501
-
1502
- return nil
1503
- }
1504
-
1505
1471
var (
1506
1472
reservedRepoNames = []string {"." , ".." }
1507
1473
reservedRepoPatterns = []string {"*.git" , "*.wiki" }
@@ -1512,7 +1478,7 @@ func IsUsableRepoName(name string) error {
1512
1478
return isUsableName (reservedRepoNames , reservedRepoPatterns , name )
1513
1479
}
1514
1480
1515
- func createRepository (e * xorm. Session , doer , u * User , repo * Repository ) (err error ) {
1481
+ func createRepository (e Engine , doer , u * User , repo * Repository ) (err error ) {
1516
1482
if err = IsUsableRepoName (repo .Name ); err != nil {
1517
1483
return err
1518
1484
}
@@ -2759,72 +2725,6 @@ func ForkRepository(doer, owner *User, oldRepo *Repository, name, desc string) (
2759
2725
return repo , CopyLFS (repo , oldRepo )
2760
2726
}
2761
2727
2762
- // GenerateRepository generates a repository from a template
2763
- func GenerateRepository (doer , owner * User , templateRepo * Repository , opts GenerateRepoOptions ) (_ * Repository , err error ) {
2764
- repo := & Repository {
2765
- OwnerID : owner .ID ,
2766
- Owner : owner ,
2767
- Name : opts .Name ,
2768
- LowerName : strings .ToLower (opts .Name ),
2769
- Description : opts .Description ,
2770
- IsPrivate : opts .Private ,
2771
- IsEmpty : ! opts .GitContent || templateRepo .IsEmpty ,
2772
- IsFsckEnabled : templateRepo .IsFsckEnabled ,
2773
- TemplateID : templateRepo .ID ,
2774
- }
2775
-
2776
- createSess := x .NewSession ()
2777
- defer createSess .Close ()
2778
- if err = createSess .Begin (); err != nil {
2779
- return nil , err
2780
- }
2781
-
2782
- if err = createRepository (createSess , doer , owner , repo ); err != nil {
2783
- return nil , err
2784
- }
2785
-
2786
- //Commit repo to get created repo ID
2787
- err = createSess .Commit ()
2788
- if err != nil {
2789
- return nil , err
2790
- }
2791
-
2792
- sess := x .NewSession ()
2793
- defer sess .Close ()
2794
- if err = sess .Begin (); err != nil {
2795
- return repo , err
2796
- }
2797
-
2798
- repoPath := RepoPath (owner .Name , repo .Name )
2799
- if err = checkInitRepository (repoPath ); err != nil {
2800
- return repo , err
2801
- }
2802
-
2803
- if opts .GitContent && ! templateRepo .IsEmpty {
2804
- if err = generateRepository (sess , repo , templateRepo ); err != nil {
2805
- return repo , err
2806
- }
2807
-
2808
- if err = repo .updateSize (sess ); err != nil {
2809
- return repo , fmt .Errorf ("failed to update size for repository: %v" , err )
2810
- }
2811
-
2812
- if err = copyLFS (sess , repo , templateRepo ); err != nil {
2813
- return repo , fmt .Errorf ("failed to copy LFS: %v" , err )
2814
- }
2815
- }
2816
-
2817
- if opts .Topics {
2818
- for _ , topic := range templateRepo .Topics {
2819
- if _ , err = addTopicByNameToRepo (sess , repo .ID , topic ); err != nil {
2820
- return repo , err
2821
- }
2822
- }
2823
- }
2824
-
2825
- return repo , sess .Commit ()
2826
- }
2827
-
2828
2728
// GetForks returns all the forks of the repository
2829
2729
func (repo * Repository ) GetForks () ([]* Repository , error ) {
2830
2730
forks := make ([]* Repository , 0 , repo .NumForks )
@@ -3041,8 +2941,12 @@ func (repo *Repository) GetTreePathLock(treePath string) (*LFSLock, error) {
3041
2941
return nil , nil
3042
2942
}
3043
2943
2944
+ func updateRepositoryCols (e Engine , repo * Repository , cols ... string ) error {
2945
+ _ , err := e .ID (repo .ID ).Cols (cols ... ).Update (repo )
2946
+ return err
2947
+ }
2948
+
3044
2949
// UpdateRepositoryCols updates repository's columns
3045
2950
func UpdateRepositoryCols (repo * Repository , cols ... string ) error {
3046
- _ , err := x .ID (repo .ID ).Cols (cols ... ).Update (repo )
3047
- return err
2951
+ return updateRepositoryCols (x , repo , cols ... )
3048
2952
}
0 commit comments