Skip to content

Commit 75205b5

Browse files
authored
Fix some API bugs (#16184)
* Repository object only count releases as releases (fix #16144) * EditOrg respect RepoAdminChangeTeamAccess option (fix #16013)
1 parent 29695cd commit 75205b5

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
lines changed

integrations/api_repo_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func TestAPIViewRepo(t *testing.T) {
223223
DecodeJSON(t, resp, &repo)
224224
assert.EqualValues(t, 1, repo.ID)
225225
assert.EqualValues(t, "repo1", repo.Name)
226-
assert.EqualValues(t, 3, repo.Releases)
226+
assert.EqualValues(t, 2, repo.Releases)
227227
assert.EqualValues(t, 1, repo.OpenIssues)
228228
assert.EqualValues(t, 3, repo.OpenPulls)
229229

modules/convert/repository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func innerToRepo(repo *models.Repository, mode models.AccessMode, isParent bool)
9191
return nil
9292
}
9393

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

9696
mirrorInterval := ""
9797
if repo.IsMirror {

modules/structs/org.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ type CreateOrgOption struct {
3131
RepoAdminChangeTeamAccess bool `json:"repo_admin_change_team_access"`
3232
}
3333

34+
// TODO: make EditOrgOption fields optional after https://gitea.com/go-chi/binding/pulls/5 got merged
35+
3436
// EditOrgOption options for editing an organization
3537
type EditOrgOption struct {
3638
FullName string `json:"full_name"`
@@ -40,5 +42,5 @@ type EditOrgOption struct {
4042
// possible values are `public`, `limited` or `private`
4143
// enum: public,limited,private
4244
Visibility string `json:"visibility" binding:"In(,public,limited,private)"`
43-
RepoAdminChangeTeamAccess bool `json:"repo_admin_change_team_access"`
45+
RepoAdminChangeTeamAccess *bool `json:"repo_admin_change_team_access"`
4446
}

routers/api/v1/org/org.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,13 @@ func Edit(ctx *context.APIContext) {
264264
if form.Visibility != "" {
265265
org.Visibility = api.VisibilityModes[form.Visibility]
266266
}
267-
if err := models.UpdateUserCols(org, "full_name", "description", "website", "location", "visibility"); err != nil {
267+
if form.RepoAdminChangeTeamAccess != nil {
268+
org.RepoAdminChangeTeamAccess = *form.RepoAdminChangeTeamAccess
269+
}
270+
if err := models.UpdateUserCols(org,
271+
"full_name", "description", "website", "location",
272+
"visibility", "repo_admin_change_team_access",
273+
); err != nil {
268274
ctx.Error(http.StatusInternalServerError, "EditOrganization", err)
269275
return
270276
}

routers/api/v1/utils/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func parseTime(value string) (int64, error) {
5555
// prepareQueryArg unescape and trim a query arg
5656
func prepareQueryArg(ctx *context.APIContext, name string) (value string, err error) {
5757
value, err = url.PathUnescape(ctx.Query(name))
58-
value = strings.Trim(value, " ")
58+
value = strings.TrimSpace(value)
5959
return
6060
}
6161

0 commit comments

Comments
 (0)