Skip to content
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

Merged
merged 22 commits into from
Jun 21, 2018

Conversation

axifive
Copy link
Member

@axifive axifive commented Jun 16, 2018

  • Added topics validator (fixed the problems discussed in fix topic special tags #4031)
  • Fixed topics duplication in repository.topics field
  • Added migration file for cleanup incorrect topics

Request 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'

Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
@daviian
Copy link
Member

daviian commented Jun 16, 2018

@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.

@bkcsoft bkcsoft added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 16, 2018
@daviian
Copy link
Member

daviian commented Jun 16, 2018

And please fix lint errors.

@axifive
Copy link
Member Author

axifive commented Jun 16, 2018

@daviian, lint errors already fixed, just drone second run missed the last commit

@axifive
Copy link
Member Author

axifive commented Jun 16, 2018

@daviian, Ok, and I think we can delete the field repository.topics as unused, only which can have duplicates

@daviian
Copy link
Member

daviian commented Jun 16, 2018

@axifive I've already restarted drone after that. There are new lint errors.

@axifive
Copy link
Member Author

axifive commented Jun 16, 2018

@daviian, oh, I see, thank you.

@lunny lunny added this to the 1.5.0 milestone Jun 17, 2018
@lunny lunny added the type/bug label Jun 17, 2018
@lunny lunny mentioned this pull request Jun 17, 2018
@@ -13,7 +13,7 @@ import (
)

// TopicPost response for creating repository
Copy link
Member

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

Copy link
Member Author

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-io
Copy link

codecov-io commented Jun 17, 2018

Codecov Report

Merging #4258 into master will decrease coverage by <.01%.
The diff coverage is 13.51%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
routers/repo/topic.go 0% <0%> (ø) ⬆️
models/topic.go 54.7% <62.5%> (+0.57%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9ae7664...0c97476. Read the comment docs.

@axifive
Copy link
Member Author

axifive commented Jun 17, 2018

@daviian, I found where used repository.topics. It used for repo_list template, unfortunately, GoLand сan't search by templates.
So we need cleaning requested duplicate topics or select validated topics from DB and then update repo field.

Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
@techknowlogick
Copy link
Member

@axifive just restarted the build and it picked up your lint changes, so it should report successful in a couple of minutes.

@@ -0,0 +1,137 @@
package migrations
Copy link
Member

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?

Copy link
Member Author

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>
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 {
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it, Thanks!

Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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+#_.-]+$`)
Copy link
Member

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-]*$

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, Changed it

@@ -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
Copy link
Member

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 :)

Copy link
Member Author

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>
}

log.Info("Deleting incorrect topics...")
for start := 0; ; start+=batchSize {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fmt

Copy link
Member Author

@axifive axifive Jun 19, 2018

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>
@jonasfranz
Copy link
Member

jonasfranz commented Jun 19, 2018

Topics should be already checked in JS.

Example: If I type <iframe> and press enter, an iframe gets rendered. A validation error should be shown instead.

Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
@axifive
Copy link
Member Author

axifive commented Jun 19, 2018

@JonasFranzDEV I'll add this by another PR, I already have non-complete solution

topics = topics[:i]

if len(topics) > 25 {
log.Error(2, "Incorrect number of topics(max 25)")
Copy link
Member

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.

Copy link
Member Author

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

}

if len(invalidTopics) > 0 {
log.Error(2, "Invalid topics: %v", invalidTopics)
Copy link
Member

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>
@bkcsoft bkcsoft added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jun 20, 2018
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 {
Copy link
Member

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>
@lafriks
Copy link
Member

lafriks commented Jun 20, 2018

@JonasFranzDEV @daviian @lunny please approve

@bkcsoft bkcsoft added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jun 20, 2018
@jonasfranz
Copy link
Member

Needs @daviian 's and @lunny 's approval

@lunny lunny merged commit 46d19c4 into go-gitea:master Jun 21, 2018
@axifive axifive deleted the fix-topics-addition branch June 21, 2018 16:04
@Treora Treora mentioned this pull request Jun 23, 2018
5 tasks
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants