Skip to content

Commit 0820930

Browse files
committed
Rename unit.UnitType as unit.Type
1 parent e031b04 commit 0820930

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+464
-464
lines changed

integrations/api_repo_edit_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ func getRepoEditOptionFromRepo(repo *models.Repository) *api.EditRepoOption {
2727
hasIssues := false
2828
var internalTracker *api.InternalTracker
2929
var externalTracker *api.ExternalTracker
30-
if unit, err := repo.GetUnit(unit_model.UnitTypeIssues); err == nil {
30+
if unit, err := repo.GetUnit(unit_model.TypeIssues); err == nil {
3131
config := unit.IssuesConfig()
3232
hasIssues = true
3333
internalTracker = &api.InternalTracker{
3434
EnableTimeTracker: config.EnableTimetracker,
3535
AllowOnlyContributorsToTrackTime: config.AllowOnlyContributorsToTrackTime,
3636
EnableIssueDependencies: config.EnableDependencies,
3737
}
38-
} else if unit, err := repo.GetUnit(unit_model.UnitTypeExternalTracker); err == nil {
38+
} else if unit, err := repo.GetUnit(unit_model.TypeExternalTracker); err == nil {
3939
config := unit.ExternalTrackerConfig()
4040
hasIssues = true
4141
externalTracker = &api.ExternalTracker{
@@ -46,9 +46,9 @@ func getRepoEditOptionFromRepo(repo *models.Repository) *api.EditRepoOption {
4646
}
4747
hasUncyclo := false
4848
var externalUncyclo *api.ExternalUncyclo
49-
if _, err := repo.GetUnit(unit_model.UnitTypeUncyclo); err == nil {
49+
if _, err := repo.GetUnit(unit_model.TypeUncyclo); err == nil {
5050
hasUncyclo = true
51-
} else if unit, err := repo.GetUnit(unit_model.UnitTypeExternalUncyclo); err == nil {
51+
} else if unit, err := repo.GetUnit(unit_model.TypeExternalUncyclo); err == nil {
5252
hasUncyclo = true
5353
config := unit.ExternalUncycloConfig()
5454
externalUncyclo = &api.ExternalUncyclo{
@@ -62,7 +62,7 @@ func getRepoEditOptionFromRepo(repo *models.Repository) *api.EditRepoOption {
6262
allowRebase := false
6363
allowRebaseMerge := false
6464
allowSquash := false
65-
if unit, err := repo.GetUnit(unit_model.UnitTypePullRequests); err == nil {
65+
if unit, err := repo.GetUnit(unit_model.TypePullRequests); err == nil {
6666
config := unit.PullRequestsConfig()
6767
hasPullRequests = true
6868
ignoreWhitespaceConflicts = config.IgnoreWhitespaceConflicts

models/attachment.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,25 @@ func (a *Attachment) DownloadURL() string {
6363
}
6464

6565
// LinkedRepository returns the linked repo if any
66-
func (a *Attachment) LinkedRepository() (*Repository, unit.UnitType, error) {
66+
func (a *Attachment) LinkedRepository() (*Repository, unit.Type, error) {
6767
if a.IssueID != 0 {
6868
iss, err := GetIssueByID(a.IssueID)
6969
if err != nil {
70-
return nil, unit.UnitTypeIssues, err
70+
return nil, unit.TypeIssues, err
7171
}
7272
repo, err := GetRepositoryByID(iss.RepoID)
73-
unitType := unit.UnitTypeIssues
73+
unitType := unit.TypeIssues
7474
if iss.IsPull {
75-
unitType = unit.UnitTypePullRequests
75+
unitType = unit.TypePullRequests
7676
}
7777
return repo, unitType, err
7878
} else if a.ReleaseID != 0 {
7979
rel, err := GetReleaseByID(a.ReleaseID)
8080
if err != nil {
81-
return nil, unit.UnitTypeReleases, err
81+
return nil, unit.TypeReleases, err
8282
}
8383
repo, err := GetRepositoryByID(rel.RepoID)
84-
return repo, unit.UnitTypeReleases, err
84+
return repo, unit.TypeReleases, err
8585
}
8686
return nil, -1, nil
8787
}

models/attachment_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ func TestLinkedRepository(t *testing.T) {
108108
name string
109109
attachID int64
110110
expectedRepo *Repository
111-
expectedUnitType unit.UnitType
111+
expectedUnitType unit.Type
112112
}{
113-
{"LinkedIssue", 1, &Repository{ID: 1}, unit.UnitTypeIssues},
114-
{"LinkedComment", 3, &Repository{ID: 1}, unit.UnitTypePullRequests},
115-
{"LinkedRelease", 9, &Repository{ID: 1}, unit.UnitTypeReleases},
113+
{"LinkedIssue", 1, &Repository{ID: 1}, unit.TypeIssues},
114+
{"LinkedComment", 3, &Repository{ID: 1}, unit.TypePullRequests},
115+
{"LinkedRelease", 9, &Repository{ID: 1}, unit.TypeReleases},
116116
{"Notlinked", 10, nil, -1},
117117
}
118118
for _, tc := range testCases {

models/branches.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (protectBranch *ProtectedBranch) CanUserPush(userID int64) bool {
7575
} else if repo, err := GetRepositoryByID(protectBranch.RepoID); err != nil {
7676
log.Error("GetRepositoryByID: %v", err)
7777
return false
78-
} else if writeAccess, err := HasAccessUnit(user, repo, unit.UnitTypeCode, AccessModeWrite); err != nil {
78+
} else if writeAccess, err := HasAccessUnit(user, repo, unit.TypeCode, AccessModeWrite); err != nil {
7979
log.Error("HasAccessUnit: %v", err)
8080
return false
8181
} else {
@@ -103,7 +103,7 @@ func (protectBranch *ProtectedBranch) CanUserPush(userID int64) bool {
103103
func (protectBranch *ProtectedBranch) IsUserMergeWhitelisted(userID int64, permissionInRepo Permission) bool {
104104
if !protectBranch.EnableMergeWhitelist {
105105
// Then we need to fall back on whether the user has write permission
106-
return permissionInRepo.CanWrite(unit.UnitTypeCode)
106+
return permissionInRepo.CanWrite(unit.TypeCode)
107107
}
108108

109109
if base.Int64sContains(protectBranch.MergeWhitelistUserIDs, userID) {
@@ -135,7 +135,7 @@ func (protectBranch *ProtectedBranch) isUserOfficialReviewer(e db.Engine, user *
135135

136136
if !protectBranch.EnableApprovalsWhitelist {
137137
// Anyone with write access is considered official reviewer
138-
writeAccess, err := hasAccessUnit(e, user, repo, unit.UnitTypeCode, AccessModeWrite)
138+
writeAccess, err := hasAccessUnit(e, user, repo, unit.TypeCode, AccessModeWrite)
139139
if err != nil {
140140
return false, err
141141
}
@@ -455,7 +455,7 @@ func updateUserWhitelist(repo *Repository, currentWhitelist, newWhitelist []int6
455455
return nil, fmt.Errorf("GetUserRepoPermission [user_id: %d, repo_id: %d]: %v", userID, repo.ID, err)
456456
}
457457

458-
if !perm.CanWrite(unit.UnitTypeCode) {
458+
if !perm.CanWrite(unit.TypeCode) {
459459
continue // Drop invalid user ID
460460
}
461461

models/issue.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,9 +2032,9 @@ func (issue *Issue) ResolveMentionsByVisibility(ctx context.Context, doer *User,
20322032
}
20332033
if len(teams) != 0 {
20342034
checked := make([]int64, 0, len(teams))
2035-
unittype := unit.UnitTypeIssues
2035+
unittype := unit.TypeIssues
20362036
if issue.IsPull {
2037-
unittype = unit.UnitTypePullRequests
2037+
unittype = unit.TypePullRequests
20382038
}
20392039
for _, team := range teams {
20402040
if team.Authorize >= AccessModeOwner {

models/issue_dependency.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (repo *Repository) IsDependenciesEnabled() bool {
142142
func (repo *Repository) isDependenciesEnabled(e db.Engine) bool {
143143
var u *RepoUnit
144144
var err error
145-
if u, err = repo.getUnit(e, unit.UnitTypeIssues); err != nil {
145+
if u, err = repo.getUnit(e, unit.TypeIssues); err != nil {
146146
log.Trace("%s", err)
147147
return setting.Service.DefaultEnableDependencies
148148
}

models/lfs_lock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func CheckLFSAccessForRepo(u *User, repo *Repository, mode AccessMode) error {
153153
if err != nil {
154154
return err
155155
}
156-
if !perm.CanAccess(mode, unit.UnitTypeCode) {
156+
if !perm.CanAccess(mode, unit.TypeCode) {
157157
return ErrLFSUnauthorizedAction{repo.ID, u.DisplayName(), mode}
158158
}
159159
return nil

models/notification.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,10 @@ func createOrUpdateIssueNotifications(e db.Engine, issueID, commentID, notificat
263263

264264
return err
265265
}
266-
if issue.IsPull && !issue.Repo.checkUnitUser(e, user, unit.UnitTypePullRequests) {
266+
if issue.IsPull && !issue.Repo.checkUnitUser(e, user, unit.TypePullRequests) {
267267
continue
268268
}
269-
if !issue.IsPull && !issue.Repo.checkUnitUser(e, user, unit.UnitTypeIssues) {
269+
if !issue.IsPull && !issue.Repo.checkUnitUser(e, user, unit.TypeIssues) {
270270
continue
271271
}
272272

models/org_team.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,11 @@ func (t *Team) RemoveRepository(repoID int64) error {
436436
}
437437

438438
// UnitEnabled returns if the team has the given unit type enabled
439-
func (t *Team) UnitEnabled(tp unit.UnitType) bool {
439+
func (t *Team) UnitEnabled(tp unit.Type) bool {
440440
return t.unitEnabled(db.GetEngine(db.DefaultContext), tp)
441441
}
442442

443-
func (t *Team) unitEnabled(e db.Engine, tp unit.UnitType) bool {
443+
func (t *Team) unitEnabled(e db.Engine, tp unit.Type) bool {
444444
if err := t.getUnits(e); err != nil {
445445
log.Warn("Error loading team (ID: %d) units: %s", t.ID, err.Error())
446446
}
@@ -1030,10 +1030,10 @@ func GetTeamsWithAccessToRepo(orgID, repoID int64, mode AccessMode) ([]*Team, er
10301030

10311031
// TeamUnit describes all units of a repository
10321032
type TeamUnit struct {
1033-
ID int64 `xorm:"pk autoincr"`
1034-
OrgID int64 `xorm:"INDEX"`
1035-
TeamID int64 `xorm:"UNIQUE(s)"`
1036-
Type unit.UnitType `xorm:"UNIQUE(s)"`
1033+
ID int64 `xorm:"pk autoincr"`
1034+
OrgID int64 `xorm:"INDEX"`
1035+
TeamID int64 `xorm:"UNIQUE(s)"`
1036+
Type unit.Type `xorm:"UNIQUE(s)"`
10371037
}
10381038

10391039
// Unit returns Unit

models/pull.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func (pr *PullRequest) GetDefaultMergeMessage() string {
237237
}
238238

239239
issueReference := "#"
240-
if pr.BaseRepo.UnitEnabled(unit.UnitTypeExternalTracker) {
240+
if pr.BaseRepo.UnitEnabled(unit.TypeExternalTracker) {
241241
issueReference = "!"
242242
}
243243

@@ -339,7 +339,7 @@ func (pr *PullRequest) GetDefaultSquashMessage() string {
339339
log.Error("LoadBaseRepo: %v", err)
340340
return ""
341341
}
342-
if pr.BaseRepo.UnitEnabled(unit.UnitTypeExternalTracker) {
342+
if pr.BaseRepo.UnitEnabled(unit.TypeExternalTracker) {
343343
return fmt.Sprintf("%s (!%d)", pr.Issue.Title, pr.Issue.Index)
344344
}
345345
return fmt.Sprintf("%s (#%d)", pr.Issue.Title, pr.Issue.Index)

models/pull_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ func TestPullRequest_GetDefaultMergeMessage_ExternalTracker(t *testing.T) {
256256
assert.NoError(t, db.PrepareTestDatabase())
257257

258258
externalTracker := RepoUnit{
259-
Type: unit.UnitTypeExternalTracker,
259+
Type: unit.TypeExternalTracker,
260260
Config: &ExternalTrackerConfig{
261261
ExternalTrackerFormat: "https://someurl.com/{user}/{repo}/{issue}",
262262
},

models/repo.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,11 @@ func (repo *Repository) getUnits(e db.Engine) (err error) {
354354
}
355355

356356
// CheckUnitUser check whether user could visit the unit of this repository
357-
func (repo *Repository) CheckUnitUser(user *User, unitType unit.UnitType) bool {
357+
func (repo *Repository) CheckUnitUser(user *User, unitType unit.Type) bool {
358358
return repo.checkUnitUser(db.GetEngine(db.DefaultContext), user, unitType)
359359
}
360360

361-
func (repo *Repository) checkUnitUser(e db.Engine, user *User, unitType unit.UnitType) bool {
361+
func (repo *Repository) checkUnitUser(e db.Engine, user *User, unitType unit.Type) bool {
362362
if user.IsAdmin {
363363
return true
364364
}
@@ -372,7 +372,7 @@ func (repo *Repository) checkUnitUser(e db.Engine, user *User, unitType unit.Uni
372372
}
373373

374374
// UnitEnabled if this repository has the given unit enabled
375-
func (repo *Repository) UnitEnabled(tp unit.UnitType) bool {
375+
func (repo *Repository) UnitEnabled(tp unit.Type) bool {
376376
if err := repo.getUnits(db.GetEngine(db.DefaultContext)); err != nil {
377377
log.Warn("Error loading repository (ID: %d) units: %s", repo.ID, err.Error())
378378
}
@@ -386,7 +386,7 @@ func (repo *Repository) UnitEnabled(tp unit.UnitType) bool {
386386

387387
// ErrUnitTypeNotExist represents a "UnitTypeNotExist" kind of error.
388388
type ErrUnitTypeNotExist struct {
389-
UT unit.UnitType
389+
UT unit.Type
390390
}
391391

392392
// IsErrUnitTypeNotExist checks if an error is a ErrUnitNotExist.
@@ -400,28 +400,28 @@ func (err ErrUnitTypeNotExist) Error() string {
400400
}
401401

402402
// MustGetUnit always returns a RepoUnit object
403-
func (repo *Repository) MustGetUnit(tp unit.UnitType) *RepoUnit {
403+
func (repo *Repository) MustGetUnit(tp unit.Type) *RepoUnit {
404404
ru, err := repo.GetUnit(tp)
405405
if err == nil {
406406
return ru
407407
}
408408

409-
if tp == unit.UnitTypeExternalUncyclo {
409+
if tp == unit.TypeExternalUncyclo {
410410
return &RepoUnit{
411411
Type: tp,
412412
Config: new(ExternalUncycloConfig),
413413
}
414-
} else if tp == unit.UnitTypeExternalTracker {
414+
} else if tp == unit.TypeExternalTracker {
415415
return &RepoUnit{
416416
Type: tp,
417417
Config: new(ExternalTrackerConfig),
418418
}
419-
} else if tp == unit.UnitTypePullRequests {
419+
} else if tp == unit.TypePullRequests {
420420
return &RepoUnit{
421421
Type: tp,
422422
Config: new(PullRequestsConfig),
423423
}
424-
} else if tp == unit.UnitTypeIssues {
424+
} else if tp == unit.TypeIssues {
425425
return &RepoUnit{
426426
Type: tp,
427427
Config: new(IssuesConfig),
@@ -434,11 +434,11 @@ func (repo *Repository) MustGetUnit(tp unit.UnitType) *RepoUnit {
434434
}
435435

436436
// GetUnit returns a RepoUnit object
437-
func (repo *Repository) GetUnit(tp unit.UnitType) (*RepoUnit, error) {
437+
func (repo *Repository) GetUnit(tp unit.Type) (*RepoUnit, error) {
438438
return repo.getUnit(db.GetEngine(db.DefaultContext), tp)
439439
}
440440

441-
func (repo *Repository) getUnit(e db.Engine, tp unit.UnitType) (*RepoUnit, error) {
441+
func (repo *Repository) getUnit(e db.Engine, tp unit.Type) (*RepoUnit, error) {
442442
if err := repo.getUnits(e); err != nil {
443443
return nil, err
444444
}
@@ -485,7 +485,7 @@ func (repo *Repository) ComposeMetas() map[string]string {
485485
"mode": "comment",
486486
}
487487

488-
unit, err := repo.GetUnit(unit.UnitTypeExternalTracker)
488+
unit, err := repo.GetUnit(unit.TypeExternalTracker)
489489
if err == nil {
490490
metas["format"] = unit.ExternalTrackerConfig().ExternalTrackerFormat
491491
switch unit.ExternalTrackerConfig().ExternalTrackerStyle {
@@ -803,7 +803,7 @@ func (repo *Repository) CanEnablePulls() bool {
803803

804804
// AllowsPulls returns true if repository meets the requirements of accepting pulls and has them enabled.
805805
func (repo *Repository) AllowsPulls() bool {
806-
return repo.CanEnablePulls() && repo.UnitEnabled(unit.UnitTypePullRequests)
806+
return repo.CanEnablePulls() && repo.UnitEnabled(unit.TypePullRequests)
807807
}
808808

809809
// CanEnableEditor returns true if repository meets the requirements of web editor.
@@ -1079,7 +1079,7 @@ func CreateRepository(ctx context.Context, doer, u *User, repo *Repository, over
10791079
// insert units for repo
10801080
units := make([]RepoUnit, 0, len(unit.DefaultRepoUnits))
10811081
for _, tp := range unit.DefaultRepoUnits {
1082-
if tp == unit.UnitTypeIssues {
1082+
if tp == unit.TypeIssues {
10831083
units = append(units, RepoUnit{
10841084
RepoID: repo.ID,
10851085
Type: tp,
@@ -1089,7 +1089,7 @@ func CreateRepository(ctx context.Context, doer, u *User, repo *Repository, over
10891089
EnableDependencies: setting.Service.DefaultEnableDependencies,
10901090
},
10911091
})
1092-
} else if tp == unit.UnitTypePullRequests {
1092+
} else if tp == unit.TypePullRequests {
10931093
units = append(units, RepoUnit{
10941094
RepoID: repo.ID,
10951095
Type: tp,
@@ -1407,7 +1407,7 @@ func UpdateRepositoryUpdatedTime(repoID int64, updateTime time.Time) error {
14071407
}
14081408

14091409
// UpdateRepositoryUnits updates a repository's units
1410-
func UpdateRepositoryUnits(repo *Repository, units []RepoUnit, deleteUnitTypes []unit.UnitType) (err error) {
1410+
func UpdateRepositoryUnits(repo *Repository, units []RepoUnit, deleteUnitTypes []unit.Type) (err error) {
14111411
sess := db.NewSession(db.DefaultContext)
14121412
defer sess.Close()
14131413
if err = sess.Begin(); err != nil {

models/repo_collaboration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ func (repo *Repository) IsOwnerMemberCollaborator(userID int64) (bool, error) {
277277
teamMember, err := db.GetEngine(db.DefaultContext).Join("INNER", "team_repo", "team_repo.team_id = team_user.team_id").
278278
Join("INNER", "team_unit", "team_unit.team_id = team_user.team_id").
279279
Where("team_repo.repo_id = ?", repo.ID).
280-
And("team_unit.`type` = ?", unit.UnitTypeCode).
280+
And("team_unit.`type` = ?", unit.TypeCode).
281281
And("team_user.uid = ?", userID).Table("team_user").Exist(&TeamUser{})
282282
if err != nil {
283283
return false, err

models/repo_issue.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (repo *Repository) IsTimetrackerEnabled() bool {
3030

3131
var u *RepoUnit
3232
var err error
33-
if u, err = repo.GetUnit(unit.UnitTypeIssues); err != nil {
33+
if u, err = repo.GetUnit(unit.TypeIssues); err != nil {
3434
return setting.Service.DefaultEnableTimetracking
3535
}
3636
return u.IssuesConfig().EnableTimetracker
@@ -40,7 +40,7 @@ func (repo *Repository) IsTimetrackerEnabled() bool {
4040
func (repo *Repository) AllowOnlyContributorsToTrackTime() bool {
4141
var u *RepoUnit
4242
var err error
43-
if u, err = repo.GetUnit(unit.UnitTypeIssues); err != nil {
43+
if u, err = repo.GetUnit(unit.TypeIssues); err != nil {
4444
return setting.Service.DefaultAllowOnlyContributorsToTrackTime
4545
}
4646
return u.IssuesConfig().AllowOnlyContributorsToTrackTime

0 commit comments

Comments
 (0)