-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Fix topics addition (Another solution) (#4031) #4258
Conversation
Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
@axifive Does the duplication of repository topics have any visible side affects for the user? If not I'd suggest moving that fix into a new PR and only keep the topic validator. |
And please fix lint errors. |
@daviian, lint errors already fixed, just drone second run missed the last commit |
@daviian, |
@axifive I've already restarted drone after that. There are new lint errors. |
@daviian, oh, I see, thank you. |
routers/repo/topic.go
Outdated
@@ -13,7 +13,7 @@ import ( | |||
) | |||
|
|||
// TopicPost response for creating repository |
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.
The lint error is right here TopicPost
should be TopicsPost
to match name of function
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
Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
Codecov Report
@@ Coverage Diff @@
## master #4258 +/- ##
=========================================
- Coverage 20.01% 20% -0.01%
=========================================
Files 153 153
Lines 30584 30620 +36
=========================================
+ Hits 6122 6127 +5
- Misses 23535 23565 +30
- Partials 927 928 +1
Continue to review full report at Codecov.
|
@daviian, I found where used |
Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
@axifive just restarted the build and it picked up your lint changes, so it should report successful in a couple of minutes. |
models/migrations/v67.go
Outdated
@@ -0,0 +1,137 @@ | |||
package migrations |
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.
Can you add copyright to top of this file?
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, missed it
Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
models/migrations/v67.go
Outdated
log.Info("Validating existed topics...") | ||
for start := 0; ; start += batchSize { | ||
topics = topics[:0] | ||
if err := x.Asc("id").Limit(batchSize, start).Find(&topics); 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.
If you deleted some topics, this will ignore some topics.
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 it, Thanks!
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.
I don't think it has been fixed. I think maybe you can save deleting topics to a slice and deleted them after the traversing.
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.
@lunny Why do you think so? How can I check this wrong behavior?
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.
@axifive because you have deleted the topics when your traversing the topics.
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.
@lunny, Ok, I'll rewrite this.
Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
models/topic.go
Outdated
@@ -20,6 +21,8 @@ func init() { | |||
) | |||
} | |||
|
|||
var topicPattern = regexp.MustCompile(`^[a-z0-9+#_.-]+$`) |
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.
I think we should limit same as github does with regexp: ^[a-z0-9][a-z0-9-]*$
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.
Ok, Changed it
options/locale/locale_en-US.ini
Outdated
@@ -1167,6 +1167,8 @@ branch.protected_deletion_failed = Branch '%s' is protected. It cannot be delete | |||
|
|||
topic.manage_topics = Manage Topics | |||
topic.done = Done | |||
topic.count_prompt = You can't select more than 25 topics | |||
topic.format_prompt = Topics must use letter or number and can include hyphen(-), underscore(_), plus(+), hash(#), dot(.) with max length of 35 |
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.
And error message if changed to the regexp above would be: Topics must start with letter or number, can include hyphen(-) must be no more than 35 characters long
or something like that :)
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
Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
models/migrations/v67.go
Outdated
} | ||
|
||
log.Info("Deleting incorrect topics...") | ||
for start := 0; ; start+=batchSize { |
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.
fmt
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.
already. Need restart drone task, it got: "RPC failed" error
Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
Topics should be already checked in JS. Example: If I type |
Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
@JonasFranzDEV I'll add this by another PR, I already have non-complete solution |
routers/repo/topic.go
Outdated
topics = topics[:i] | ||
|
||
if len(topics) > 25 { | ||
log.Error(2, "Incorrect number of topics(max 25)") |
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.
I don't think that this must be logged because the user receives the error message already. If you nevertheless want to log it, please use log.Info
or log.Warn
instead, since this is not a "real" error.
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.
That's reasonable, thank you
routers/repo/topic.go
Outdated
} | ||
|
||
if len(invalidTopics) > 0 { | ||
log.Error(2, "Invalid topics: %v", invalidTopics) |
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
Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
models/topic.go
Outdated
@@ -51,6 +54,11 @@ func (err ErrTopicNotExist) Error() string { | |||
return fmt.Sprintf("topic is not exist [name: %s]", err.Name) | |||
} | |||
|
|||
// TopicValidator checks topics by length and match pattern rules | |||
func TopicValidator(topic string) bool { |
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.
I don‘t like the name of this function because it sounds like a struct/interface, Please rename it to ValidateTopic
.
Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
repository.topics
fieldRequest for check duplicates on explore or user pages:
curl 'https://try.gitea.io/USER/REPO/topics' -H 'Origin: https://try.gitea.io' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Cache-Control: no-cache' -H 'X-Requested-With: XMLHttpRequest' -H 'Cookie: lang=en-US; i_like_gitea=Your_I_LIKE_GITEA; _csrf=Your_CSRF -H 'Connection: keep-alive' -H 'DNT: 1' --data '_csrf=Your_CSRF&topics=go,test,golang,test,go'