-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Repository avatars #6986
Repository avatars #6986
Conversation
- first variant of code from old work for gogs - add migration 87 - add new option in app.ini - add en-US locale string - add new class in repository.less
Should I commit also index.css? |
@sergey-dryabzhinsky yes, please. |
add new option in app.ini.sample and docs |
Codecov Report
@@ Coverage Diff @@
## master #6986 +/- ##
==========================================
- Coverage 41.43% 41.42% -0.01%
==========================================
Files 442 443 +1
Lines 59701 59865 +164
==========================================
+ Hits 24735 24797 +62
- Misses 31729 31819 +90
- Partials 3237 3249 +12
Continue to review full report at Codecov.
|
Ready for review |
models/migrations/v87.go
Outdated
} | ||
|
||
if err != nil { | ||
return fmt.Errorf("Error changing mirror interval column type: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do need this migration you need to change this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
routers/repo/setting.go
Outdated
@@ -727,3 +730,53 @@ func init() { | |||
panic(err) | |||
} | |||
} | |||
|
|||
// UpdateAvatarSetting update repo's avatar | |||
// FIXME: limit size. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You must limit size before we merge - just stick a config in it doesn't need a great UI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
- add file size check - add new option - update config docs - add new string to en-us locale
models/repo.go
Outdated
@@ -166,6 +172,9 @@ type Repository struct { | |||
CloseIssuesViaCommitInAnyBranch bool `xorm:"NOT NULL DEFAULT false"` | |||
Topics []string `xorm:"TEXT JSON"` | |||
|
|||
// Avatar | |||
Avatar string `xorm:"VARCHAR(2048)"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the full URL need to be stored in DB? For user avatars this makes sense due to gravatar (and other external avatar services), but for repo avatars it follows the following patter setting.AppSubURL + "/repo-avatars/" + repo.Avatar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean that it easily fits into 250 symbols?
ID+MD5 ~ (10-20) + 32.
64 symbols must be enough I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, rather than storing the full URL, just the filename could be stored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 4ae9383
models/repo.go
Outdated
// Users can upload the same image to other repo - prefix it with ID | ||
// Then repo will be removed - only it avatar file will be removed | ||
repo.Avatar = fmt.Sprintf("%d-%x", repo.ID, md5.Sum(data)) | ||
if _, err := x.ID(repo.ID).Cols("avatar").Update(repo); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sess.
not x.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in c007a9a
Also rewrite |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two code readability issues but otherwise LG-TM
models/repo.go
Outdated
func (repo *Repository) DeleteAvatar() error { | ||
|
||
// Avatar exists | ||
if len(repo.Avatar) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please return as soon as possible for code readability:
if len(repo.Avatar) > 0 { | |
if len(repo.Avatar) == 0 { | |
return nil | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Point taken.
Done in f53758a
routers/repo/setting.go
Outdated
// UpdateAvatarSetting update repo's avatar | ||
func UpdateAvatarSetting(ctx *context.Context, form auth.AvatarForm) error { | ||
ctxRepo := ctx.Repo.Repository | ||
if form.Avatar != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here (do not use else):
if form.Avatar != nil { | |
if form.Avatar == nil { | |
// No avatar is uploaded but setting has been changed to enable | |
// No random avatar here. | |
if !com.IsFile(ctxRepo.CustomAvatarPath()) { | |
log.Trace("No avatar was uploaded for repo: %d. Default icon will appear instead.", ctxRepo.ID) | |
} | |
return nil | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in f53758a
@sergey-dryabzhinsky Thanks for your good job!!! |
Yes, this looks great! Was going to review but looks like you have reviewers, and a few minor details to fix. This is definitely something my organization will find useful! |
@richmahn same here. Love to use gitea at home to manage my pet projects. |
When no repository avatar was assigned it will render an empty img tag in repository list. EDIT: Fixed in #7087 |
ohh... missed that then merge code changes from gogs. |
Really hyped for 1.9! Thanks, everyone! 👍 |
Definitely! To me 1.9 seems to be much larger than previous feature releases. 👍 |
* Repository avatars - first variant of code from old work for gogs - add migration 87 - add new option in app.ini - add en-US locale string - add new class in repository.less * Add changed index.css, remove unused template name * Update en-us doc about configuration options * Add comments to new functions, add new option to docker app.ini * Add comment for lint * Remove variable, not needed * Fix formatting * Update swagger api template * Check if avatar exists * Fix avatar link/path checks * Typo * TEXT column can't have a default value * Fixes: - remove old avatar file on upload - use ID in name of avatar file - users may upload same files - add simple tests * Fix fmt check * Generate PNG instead of "static" GIF * More informative comment * Fix error message * Update avatar upload checks: - add file size check - add new option - update config docs - add new string to en-us locale * Fixes: - use FileHEader field for check file size - add new test - upload big image * Fix formatting * Update comments * Update log message * Removed wrong style - not needed * Use Sync2 to migrate * Update repos list view - bigger avatar - fix html blocks alignment * A little adjust avatar size * Use small icons for explore/repo list * Use new cool avatar preparation func by @lafriks * Missing changes for new function * Remove unused import, move imports * Missed new option definition in app.ini Add file size check in user/profile avatar upload * Use smaller field length for Avatar * Use session to update repo DB data, update DeleteAvatar - use session too * Fix err variable definition * As suggested @lafriks - return as soon as possible, code readability
For issue #694 and #5625