diff --git a/conf/locale/locale_en-US.ini b/conf/locale/locale_en-US.ini index 3f382540d..c17e2cacb 100644 --- a/conf/locale/locale_en-US.ini +++ b/conf/locale/locale_en-US.ini @@ -421,6 +421,8 @@ mirror_last_synced = Last Synced watchers = Watchers stargazers = Stargazers forks = Forks +repo_description_helper = Description of repository. Maximum 512 characters length. +repo_description_length = Available characters form.reach_limit_of_creation = The owner has reached maximum creation limit of %d repositories. form.name_reserved = Repository name '%s' is reserved. @@ -856,6 +858,8 @@ settings.add_key_success = New deploy key '%s' has been added successfully! settings.deploy_key_deletion = Delete Deploy Key settings.deploy_key_deletion_desc = Deleting this deploy key will remove all related accesses for this repository. Do you want to continue? settings.deploy_key_deletion_success = Deploy key has been deleted successfully! +settings.description_desc = Description of repository. Maximum 512 characters length. +settings.description_length = Available characters diff.browse_source = Browse Source diff.parent = parent diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 432717c75..7e700f49a 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -64,6 +64,8 @@ var migrations = []Migration{ NewMigration("update repository sizes", updateRepositorySizes), // v16 -> v17:v0.10.31 NewMigration("remove invalid protect branch whitelist", removeInvalidProtectBranchWhitelist), + // v17 -> v18:v0.11.48 + NewMigration("store long text in repository description field", updateRepositoryDescriptionField), } // Migrate database to current version diff --git a/models/migrations/v18.go b/models/migrations/v18.go new file mode 100644 index 000000000..086cd27af --- /dev/null +++ b/models/migrations/v18.go @@ -0,0 +1,34 @@ +// Copyright 2018 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package migrations + +import ( + "fmt" + + "github.com/go-xorm/xorm" + + "github.com/gogs/gogs/pkg/setting" +) + +func updateRepositoryDescriptionField(x *xorm.Engine) error { + exist, err := x.IsTableExist("repository") + if err != nil { + return fmt.Errorf("IsTableExist: %v", err) + } else if !exist { + return nil + } + switch { + case setting.UseMySQL: + _, err = x.Exec("ALTER TABLE `repository` MODIFY `description` VARCHAR(512);") + case setting.UseMSSQL: + _, err = x.Exec("ALTER TABLE `repository` ALTER COLUMN `description` VARCHAR(512);") + case setting.UsePostgreSQL: + _, err = x.Exec("ALTER TABLE `repository` ALTER COLUMN `description` TYPE VARCHAR(512);") + case setting.UseSQLite3: + // Sqlite3 uses TEXT type by default for any string type field. + // Keep this comment to mention that we don't missed any option. + } + return err +} diff --git a/models/repo.go b/models/repo.go index 7a873afc1..909af1d87 100644 --- a/models/repo.go +++ b/models/repo.go @@ -146,7 +146,7 @@ type Repository struct { Owner *User `xorm:"-" json:"-"` LowerName string `xorm:"UNIQUE(s) INDEX NOT NULL"` Name string `xorm:"INDEX NOT NULL"` - Description string + Description string `xorm:"VARCHAR(512)"` Website string DefaultBranch string Size int64 `xorm:"NOT NULL DEFAULT 0"` @@ -1331,8 +1331,8 @@ func GetRepositoriesByForkID(forkID int64) ([]*Repository, error) { func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err error) { repo.LowerName = strings.ToLower(repo.Name) - if len(repo.Description) > 255 { - repo.Description = repo.Description[:255] + if len(repo.Description) > 512 { + repo.Description = repo.Description[:512] } if len(repo.Website) > 255 { repo.Website = repo.Website[:255] diff --git a/pkg/form/repo.go b/pkg/form/repo.go index 5ec2cf7d0..a7ab1fa7b 100644 --- a/pkg/form/repo.go +++ b/pkg/form/repo.go @@ -26,7 +26,7 @@ type CreateRepo struct { UserID int64 `binding:"Required"` RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"` Private bool - Description string `binding:"MaxSize(255)"` + Description string `binding:"MaxSize(512)"` AutoInit bool Gitignores string License string @@ -45,7 +45,7 @@ type MigrateRepo struct { RepoName string `json:"repo_name" binding:"Required;AlphaDashDot;MaxSize(100)"` Mirror bool `json:"mirror"` Private bool `json:"private"` - Description string `json:"description" binding:"MaxSize(255)"` + Description string `json:"description" binding:"MaxSize(512)"` } func (f *MigrateRepo) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { @@ -82,7 +82,7 @@ func (f MigrateRepo) ParseRemoteAddr(user *models.User) (string, error) { type RepoSetting struct { RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"` - Description string `binding:"MaxSize(255)"` + Description string `binding:"MaxSize(512)"` Website string `binding:"Url;MaxSize(100)"` Branch string Interval int diff --git a/public/js/gogs.js b/public/js/gogs.js index 4eefff5ce..863c23a57 100644 --- a/public/js/gogs.js +++ b/public/js/gogs.js @@ -1443,3 +1443,24 @@ $(function () { if ($('.user.signin').length > 0) return; $('form').areYouSure(); }); + +function showMessageMaxLength(maxLen, textElemId, counterId) { + var $msg = $('#'+textElemId); //text message + $('#'+counterId).html(maxLen - $msg.val().length); //symbols count + + var onMessageKey = function (e) { + var $msg = $(this); + var text = $msg.val(); + var len = text.length; + var remainder = maxLen - len; + + if (len >= maxLen) { + $msg.val($msg.val().substr(0, maxLen)); + remainder = 0; + } + + $('#'+counterId).html(remainder); + }; + + $msg.keyup(onMessageKey).keydown(onMessageKey); +} diff --git a/public/plugins/autosize-4.0.2/dist/autosize.min.js b/public/plugins/autosize-4.0.2/dist/autosize.min.js new file mode 100644 index 000000000..4d9b4e9a7 --- /dev/null +++ b/public/plugins/autosize-4.0.2/dist/autosize.min.js @@ -0,0 +1,6 @@ +/*! + autosize 4.0.2 + license: MIT + http://www.jacklmoore.com/autosize +*/ +!function(e,t){if("function"==typeof define&&define.amd)define(["module","exports"],t);else if("undefined"!=typeof exports)t(module,exports);else{var n={exports:{}};t(n,n.exports),e.autosize=n.exports}}(this,function(e,t){"use strict";var n,o,p="function"==typeof Map?new Map:(n=[],o=[],{has:function(e){return-1 - + {{if .RequireAutosize}} + + {{end}} {{if .IsIPythonNotebook}} diff --git a/templates/repo/create.tmpl b/templates/repo/create.tmpl index 25c8dc278..89fe133cb 100644 --- a/templates/repo/create.tmpl +++ b/templates/repo/create.tmpl @@ -52,7 +52,9 @@
- + + {{.i18n.Tr "repo.repo_description_helper" | Safe}} + {{.i18n.Tr "repo.repo_description_length"}}:
@@ -113,4 +115,14 @@ + + + {{template "base/footer" .}} diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index b1334a3bb..976c6b212 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -19,7 +19,9 @@
- + +

{{.i18n.Tr "repo.settings.description_desc"}}

+

{{.i18n.Tr "repo.settings.description_length"}}:

@@ -415,4 +417,13 @@ {{end}} {{end}} + + {{template "base/footer" .}}