From b6e9ba6c96327a104f8847fcafcd5bcaa67eb994 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Wed, 16 Jun 2021 00:43:20 +0200 Subject: [PATCH 1/3] API: User expose counters --- modules/convert/user.go | 5 +++++ modules/structs/user.go | 6 ++++++ templates/swagger/v1_json.tmpl | 21 +++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/modules/convert/user.go b/modules/convert/user.go index 088ede5add507..c44a3c2761e1a 100644 --- a/modules/convert/user.go +++ b/modules/convert/user.go @@ -48,6 +48,11 @@ func toUser(user *models.User, signed, authed bool) *api.User { Location: user.Location, Website: user.Website, Description: user.Description, + // counter's + Followers: user.NumFollowers, + Following: user.NumFollowing, + StarredRepos: user.NumStars, + PublicRepos: int(models.CountUserRepositories(user.ID, false)), } // hide primary email if API caller is anonymous or user keep email private if signed && (!user.KeepEmailPrivate || authed) { diff --git a/modules/structs/user.go b/modules/structs/user.go index 2dbc5305382ab..fc68ccf0185ca 100644 --- a/modules/structs/user.go +++ b/modules/structs/user.go @@ -43,6 +43,12 @@ type User struct { Website string `json:"website"` // the user's description Description string `json:"description"` + + // user counts + Followers int `json:"followers_count"` + Following int `json:"following_count"` + StarredRepos int `json:"starred_repos_count"` + PublicRepos int `json:"public_repos_count"` } // MarshalJSON implements the json.Marshaler interface for User, adding field(s) for backward compatibility diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index e3ac4a4c8a68c..3ebf65d5f2e62 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -16275,6 +16275,17 @@ "format": "email", "x-go-name": "Email" }, + "followers_count": { + "description": "user counts", + "type": "integer", + "format": "int64", + "x-go-name": "Followers" + }, + "following_count": { + "type": "integer", + "format": "int64", + "x-go-name": "Following" + }, "full_name": { "description": "the user's full name", "type": "string", @@ -16316,11 +16327,21 @@ "type": "boolean", "x-go-name": "ProhibitLogin" }, + "public_repos_count": { + "type": "integer", + "format": "int64", + "x-go-name": "PublicRepos" + }, "restricted": { "description": "Is user restricted", "type": "boolean", "x-go-name": "Restricted" }, + "starred_repos_count": { + "type": "integer", + "format": "int64", + "x-go-name": "StarredRepos" + }, "website": { "description": "the user's website", "type": "string", From a279322b4f6aaa0de84a589a9d1b92bf455f2e3e Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 17 Jun 2021 00:46:55 +0200 Subject: [PATCH 2/3] rm PublicRepos due to resource usage --- modules/convert/user.go | 1 - modules/structs/user.go | 1 - 2 files changed, 2 deletions(-) diff --git a/modules/convert/user.go b/modules/convert/user.go index c44a3c2761e1a..c588f5f2f076b 100644 --- a/modules/convert/user.go +++ b/modules/convert/user.go @@ -52,7 +52,6 @@ func toUser(user *models.User, signed, authed bool) *api.User { Followers: user.NumFollowers, Following: user.NumFollowing, StarredRepos: user.NumStars, - PublicRepos: int(models.CountUserRepositories(user.ID, false)), } // hide primary email if API caller is anonymous or user keep email private if signed && (!user.KeepEmailPrivate || authed) { diff --git a/modules/structs/user.go b/modules/structs/user.go index fc68ccf0185ca..de2e68c2a2e30 100644 --- a/modules/structs/user.go +++ b/modules/structs/user.go @@ -48,7 +48,6 @@ type User struct { Followers int `json:"followers_count"` Following int `json:"following_count"` StarredRepos int `json:"starred_repos_count"` - PublicRepos int `json:"public_repos_count"` } // MarshalJSON implements the json.Marshaler interface for User, adding field(s) for backward compatibility From 4319628a2805c4fbdbda665a5dcc5dd84d8972ff Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 17 Jun 2021 08:40:07 +0200 Subject: [PATCH 3/3] make generate-swagger --- templates/swagger/v1_json.tmpl | 5 ----- 1 file changed, 5 deletions(-) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index cf73580fba9c9..e0d7ae575d2e3 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -16391,11 +16391,6 @@ "type": "boolean", "x-go-name": "ProhibitLogin" }, - "public_repos_count": { - "type": "integer", - "format": "int64", - "x-go-name": "PublicRepos" - }, "restricted": { "description": "Is user restricted", "type": "boolean",