Skip to content

Commit

Permalink
Fix some API bugs (#16184) (#16190)
Browse files Browse the repository at this point in the history
* Fix some API bugs (#16184)

* Repository object only count releases as releases (fix #16144)

* EditOrg respect RepoAdminChangeTeamAccess option (fix #16013)

* adjut to v1.14
  • Loading branch information
6543 authored Jun 18, 2021
1 parent 544ef7d commit f832e8e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion integrations/api_repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func TestAPIViewRepo(t *testing.T) {
DecodeJSON(t, resp, &repo)
assert.EqualValues(t, 1, repo.ID)
assert.EqualValues(t, "repo1", repo.Name)
assert.EqualValues(t, 2, repo.Releases)
assert.EqualValues(t, 1, repo.Releases)
assert.EqualValues(t, 1, repo.OpenIssues)
assert.EqualValues(t, 3, repo.OpenPulls)

Expand Down
2 changes: 1 addition & 1 deletion modules/convert/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func innerToRepo(repo *models.Repository, mode models.AccessMode, isParent bool)
return nil
}

numReleases, _ := models.GetReleaseCountByRepoID(repo.ID, models.FindReleasesOptions{IncludeDrafts: false, IncludeTags: true})
numReleases, _ := models.GetReleaseCountByRepoID(repo.ID, models.FindReleasesOptions{IncludeDrafts: false, IncludeTags: false})

mirrorInterval := ""
if repo.IsMirror {
Expand Down
4 changes: 3 additions & 1 deletion modules/structs/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type CreateOrgOption struct {
RepoAdminChangeTeamAccess bool `json:"repo_admin_change_team_access"`
}

// TODO: make EditOrgOption fields optional after https://gitea.com/go-chi/binding/pulls/5 got merged

// EditOrgOption options for editing an organization
type EditOrgOption struct {
FullName string `json:"full_name"`
Expand All @@ -40,5 +42,5 @@ type EditOrgOption struct {
// possible values are `public`, `limited` or `private`
// enum: public,limited,private
Visibility string `json:"visibility" binding:"In(,public,limited,private)"`
RepoAdminChangeTeamAccess bool `json:"repo_admin_change_team_access"`
RepoAdminChangeTeamAccess *bool `json:"repo_admin_change_team_access"`
}
8 changes: 7 additions & 1 deletion routers/api/v1/org/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,13 @@ func Edit(ctx *context.APIContext) {
if form.Visibility != "" {
org.Visibility = api.VisibilityModes[form.Visibility]
}
if err := models.UpdateUserCols(org, "full_name", "description", "website", "location", "visibility"); err != nil {
if form.RepoAdminChangeTeamAccess != nil {
org.RepoAdminChangeTeamAccess = *form.RepoAdminChangeTeamAccess
}
if err := models.UpdateUserCols(org,
"full_name", "description", "website", "location",
"visibility", "repo_admin_change_team_access",
); err != nil {
ctx.Error(http.StatusInternalServerError, "EditOrganization", err)
return
}
Expand Down
2 changes: 1 addition & 1 deletion routers/api/v1/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func parseTime(value string) (int64, error) {
// prepareQueryArg unescape and trim a query arg
func prepareQueryArg(ctx *context.APIContext, name string) (value string, err error) {
value, err = url.PathUnescape(ctx.Query(name))
value = strings.Trim(value, " ")
value = strings.TrimSpace(value)
return
}

Expand Down

0 comments on commit f832e8e

Please sign in to comment.