aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorRichard Mahn <richmahn@users.noreply.github.com>2019-05-30 11:09:05 -0400
committertechknowlogick <hello@techknowlogick.com>2019-05-30 11:09:05 -0400
commit1831b3b57144e87ccfc4f6322eefc88a49b2300e (patch)
tree225fa569e3908c153683009d0d75c42f9dacc956 /models
parentcdd10f145be0b5e9b94c19f1303dc01c6e9c8c29 (diff)
downloadgitea-1831b3b57144e87ccfc4f6322eefc88a49b2300e.tar.gz
gitea-1831b3b57144e87ccfc4f6322eefc88a49b2300e.zip
Fixes #5960 - Adds API Endpoint for Repo Edit (#7006)
* Feature - #5960 - API Endpoint for Repo Editing * Revert from merge * Adds integration testing * Updates to integration tests * Revert changes * Update year in file header * Misspell fix * XORM = test * XORM = test * revert XORM = file * Makes RepoUnit.ID be pk and autoincr * Fix to units * revert header * Remove print statement * Adds other responses * Improves swagger for creating repo * Fixes import order * Better Unit Type does not exist error * Adds editable repo properties to the response repo structure * Fix to api_repo_edit_test.go * Fixes repo test * Changes per review * Fixes typo and standardizes comments in the EditRepoOption struct for swagger * Fixes typo and standardizes comments in the EditRepoOption struct for swagger * Actually can unarchive through the API * Unlike delete, user doesn't have to be the owner of the org, just admin to the repo * Fix to swagger comments for field name change * Update to swagger docs * Update swagger * Changes allow_pull_requests to has_pull_requests
Diffstat (limited to 'models')
-rw-r--r--models/org.go4
-rw-r--r--models/repo.go111
-rw-r--r--models/unit.go8
3 files changed, 85 insertions, 38 deletions
diff --git a/models/org.go b/models/org.go
index b7db32ef16..6511072e2b 100644
--- a/models/org.go
+++ b/models/org.go
@@ -162,8 +162,8 @@ func CreateOrganization(org, owner *User) (err error) {
}
// insert units for team
- var units = make([]TeamUnit, 0, len(allRepUnitTypes))
- for _, tp := range allRepUnitTypes {
+ var units = make([]TeamUnit, 0, len(AllRepoUnitTypes))
+ for _, tp := range AllRepoUnitTypes {
units = append(units, TeamUnit{
OrgID: org.ID,
TeamID: t.ID,
diff --git a/models/repo.go b/models/repo.go
index b8a3714abf..16684bdeef 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -274,32 +274,64 @@ func (repo *Repository) innerAPIFormat(e Engine, mode AccessMode, isParent bool)
parent = repo.BaseRepo.innerAPIFormat(e, mode, true)
}
}
+ hasIssues := false
+ if _, err := repo.getUnit(e, UnitTypeIssues); err == nil {
+ hasIssues = true
+ }
+ hasWiki := false
+ if _, err := repo.getUnit(e, UnitTypeWiki); err == nil {
+ hasWiki = true
+ }
+ hasPullRequests := false
+ ignoreWhitespaceConflicts := false
+ allowMerge := false
+ allowRebase := false
+ allowRebaseMerge := false
+ allowSquash := false
+ if unit, err := repo.getUnit(e, UnitTypePullRequests); err == nil {
+ config := unit.PullRequestsConfig()
+ hasPullRequests = true
+ ignoreWhitespaceConflicts = config.IgnoreWhitespaceConflicts
+ allowMerge = config.AllowMerge
+ allowRebase = config.AllowRebase
+ allowRebaseMerge = config.AllowRebaseMerge
+ allowSquash = config.AllowSquash
+ }
+
return &api.Repository{
- ID: repo.ID,
- Owner: repo.Owner.APIFormat(),
- Name: repo.Name,
- FullName: repo.FullName(),
- Description: repo.Description,
- Private: repo.IsPrivate,
- Empty: repo.IsEmpty,
- Archived: repo.IsArchived,
- Size: int(repo.Size / 1024),
- Fork: repo.IsFork,
- Parent: parent,
- Mirror: repo.IsMirror,
- HTMLURL: repo.HTMLURL(),
- SSHURL: cloneLink.SSH,
- CloneURL: cloneLink.HTTPS,
- Website: repo.Website,
- Stars: repo.NumStars,
- Forks: repo.NumForks,
- Watchers: repo.NumWatches,
- OpenIssues: repo.NumOpenIssues,
- DefaultBranch: repo.DefaultBranch,
- Created: repo.CreatedUnix.AsTime(),
- Updated: repo.UpdatedUnix.AsTime(),
- Permissions: permission,
- AvatarURL: repo.AvatarLink(),
+ ID: repo.ID,
+ Owner: repo.Owner.APIFormat(),
+ Name: repo.Name,
+ FullName: repo.FullName(),
+ Description: repo.Description,
+ Private: repo.IsPrivate,
+ Empty: repo.IsEmpty,
+ Archived: repo.IsArchived,
+ Size: int(repo.Size / 1024),
+ Fork: repo.IsFork,
+ Parent: parent,
+ Mirror: repo.IsMirror,
+ HTMLURL: repo.HTMLURL(),
+ SSHURL: cloneLink.SSH,
+ CloneURL: cloneLink.HTTPS,
+ Website: repo.Website,
+ Stars: repo.NumStars,
+ Forks: repo.NumForks,
+ Watchers: repo.NumWatches,
+ OpenIssues: repo.NumOpenIssues,
+ DefaultBranch: repo.DefaultBranch,
+ Created: repo.CreatedUnix.AsTime(),
+ Updated: repo.UpdatedUnix.AsTime(),
+ Permissions: permission,
+ HasIssues: hasIssues,
+ HasWiki: hasWiki,
+ HasPullRequests: hasPullRequests,
+ IgnoreWhitespaceConflicts: ignoreWhitespaceConflicts,
+ AllowMerge: allowMerge,
+ AllowRebase: allowRebase,
+ AllowRebaseMerge: allowRebaseMerge,
+ AllowSquash: allowSquash,
+ AvatarURL: repo.AvatarLink(),
}
}
@@ -346,10 +378,20 @@ func (repo *Repository) UnitEnabled(tp UnitType) bool {
return false
}
-var (
- // ErrUnitNotExist organization does not exist
- ErrUnitNotExist = errors.New("Unit does not exist")
-)
+// ErrUnitTypeNotExist represents a "UnitTypeNotExist" kind of error.
+type ErrUnitTypeNotExist struct {
+ UT UnitType
+}
+
+// IsErrUnitTypeNotExist checks if an error is a ErrUnitNotExist.
+func IsErrUnitTypeNotExist(err error) bool {
+ _, ok := err.(ErrUnitTypeNotExist)
+ return ok
+}
+
+func (err ErrUnitTypeNotExist) Error() string {
+ return fmt.Sprintf("Unit type does not exist: %s", err.UT.String())
+}
// MustGetUnit always returns a RepoUnit object
func (repo *Repository) MustGetUnit(tp UnitType) *RepoUnit {
@@ -373,6 +415,11 @@ func (repo *Repository) MustGetUnit(tp UnitType) *RepoUnit {
Type: tp,
Config: new(PullRequestsConfig),
}
+ } else if tp == UnitTypeIssues {
+ return &RepoUnit{
+ Type: tp,
+ Config: new(IssuesConfig),
+ }
}
return &RepoUnit{
Type: tp,
@@ -394,7 +441,7 @@ func (repo *Repository) getUnit(e Engine, tp UnitType) (*RepoUnit, error) {
return unit, nil
}
}
- return nil, ErrUnitNotExist
+ return nil, ErrUnitTypeNotExist{tp}
}
func (repo *Repository) getOwner(e Engine) (err error) {
@@ -1232,8 +1279,8 @@ func createRepository(e *xorm.Session, doer, u *User, repo *Repository) (err err
}
// insert units for repo
- var units = make([]RepoUnit, 0, len(defaultRepoUnits))
- for _, tp := range defaultRepoUnits {
+ var units = make([]RepoUnit, 0, len(DefaultRepoUnits))
+ for _, tp := range DefaultRepoUnits {
if tp == UnitTypeIssues {
units = append(units, RepoUnit{
RepoID: repo.ID,
diff --git a/models/unit.go b/models/unit.go
index 697df696bc..9f5c8d3cbb 100644
--- a/models/unit.go
+++ b/models/unit.go
@@ -58,8 +58,8 @@ func (u UnitType) ColorFormat(s fmt.State) {
}
var (
- // allRepUnitTypes contains all the unit types
- allRepUnitTypes = []UnitType{
+ // AllRepoUnitTypes contains all the unit types
+ AllRepoUnitTypes = []UnitType{
UnitTypeCode,
UnitTypeIssues,
UnitTypePullRequests,
@@ -69,8 +69,8 @@ var (
UnitTypeExternalTracker,
}
- // defaultRepoUnits contains the default unit types
- defaultRepoUnits = []UnitType{
+ // DefaultRepoUnits contains the default unit types
+ DefaultRepoUnits = []UnitType{
UnitTypeCode,
UnitTypeIssues,
UnitTypePullRequests,