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

Add repository type option to /api/repo/search #2326

Closed

Conversation

Morlinest
Copy link
Member

First attempt to solve #2321. I want to check, if this way is OK.

}

type RepoType int
Copy link
Member

Choose a reason for hiding this comment

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

Missing comments for type and constants below

Copy link
Member Author

Choose a reason for hiding this comment

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

Comments added

@Morlinest Morlinest force-pushed the feature-api-repo-search-options branch from c0a0ada to 9a50260 Compare August 18, 2017 08:17
@Morlinest
Copy link
Member Author

Added some comments and rename RepoTypeAll to RepoTypeAny. BTW it's working solution :).

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Aug 18, 2017
@Morlinest Morlinest force-pushed the feature-api-repo-search-options branch from 9a50260 to 90e1e5b Compare August 18, 2017 08:36
@Morlinest Morlinest force-pushed the feature-api-repo-search-options branch from 90e1e5b to 94f563b Compare August 18, 2017 12:54
@lafriks
Copy link
Member

lafriks commented Aug 19, 2017

Can you add integration tests for this?

@Morlinest
Copy link
Member Author

@lafriks I can try. I have to learn what's in test db first and how to do it right.

@Morlinest
Copy link
Member Author

@lafriks I can't even run tests in gitea, so no...

@lunny lunny added this to the 1.3.0 milestone Aug 20, 2017
@Morlinest Morlinest force-pushed the feature-api-repo-search-options branch from 8cc9ea4 to 4ad515f Compare August 20, 2017 13:04
@Morlinest
Copy link
Member Author

Rebased on master

@Morlinest Morlinest force-pushed the feature-api-repo-search-options branch from 4ad515f to e07d6e2 Compare August 21, 2017 21:08
@Morlinest Morlinest force-pushed the feature-api-repo-search-options branch from e07d6e2 to 43b77fe Compare September 16, 2017 12:46
@Morlinest Morlinest changed the title Add repo type search option to repo/search api Add repository type option to /api/repo/search Sep 16, 2017
@Morlinest Morlinest force-pushed the feature-api-repo-search-options branch 2 times, most recently from f4cc1bb to 144c507 Compare September 16, 2017 14:40
@codecov-io
Copy link

codecov-io commented Sep 16, 2017

Codecov Report

Merging #2326 into master will increase coverage by 0.28%.
The diff coverage is 63.01%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2326      +/-   ##
==========================================
+ Coverage   27.32%   27.61%   +0.28%     
==========================================
  Files          86       86              
  Lines       17135    17112      -23     
==========================================
+ Hits         4682     4725      +43     
+ Misses      11775    11709      -66     
  Partials      678      678
Impacted Files Coverage Δ
routers/user/profile.go 0% <0%> (ø) ⬆️
models/repo_list.go 51.59% <73.01%> (+27.7%) ⬆️
models/user.go 18.67% <0%> (+0.21%) ⬆️
models/consistency.go 96.55% <0%> (+2.58%) ⬆️

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 1eedd98...19c15bb. Read the comment docs.

@Morlinest
Copy link
Member Author

Rebased on top of #2371. Only last commit is new. I'll create new tests for added feature soon.

Copy link
Member

@daviian daviian left a comment

Choose a reason for hiding this comment

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

Added my thoughts ;-)
And is the huge amount of new test data really necessary for your tests?

}

// Set again after reset by Count()
if includeStarred {
sess.Join("INNER", "star", "star.repo_id = repository.id")
Copy link
Member

Choose a reason for hiding this comment

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

IMO includeStarred is misleading as it doesn't include starred, it restricts to starred repositories.
Suggest changing to something like includeOnlyStarred !?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this part is only about adding/joining "starred" table to SQL. It doesn't restrict anything. Maybe renaming it to includeStarredTable or joinStarredTable would be better.

Copy link
Member

Choose a reason for hiding this comment

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

Inner join actually does restrict only to records that are in started table

Copy link
Member Author

Choose a reason for hiding this comment

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

@lafriks True, I was thinking about left join in the future update... My mistake.

@@ -217,7 +279,7 @@ func Repositories(opts *SearchRepoOptions) (_ RepositoryList, count int64, err e

if err = x.
Limit(opts.PageSize, (opts.Page-1)*opts.PageSize).
OrderBy(opts.OrderBy).
OrderBy(opts.OrderBy.String()).
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this lead to an error if len(opts.OrderBy) == 0 evaluates to true as "id ASC".String() does not exist?

Copy link
Member Author

@Morlinest Morlinest Sep 19, 2017

Choose a reason for hiding this comment

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

I think no. opts.OrderBy is custom type SearchOrderBy, you can't pass just string and it can't be of zero length here, because there is check for that above:

	if len(opts.OrderBy) == 0 {
		opts.OrderBy = SearchOrderByAlphabetically
  	}

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right, I was looking at other place... Answer: It will not fail :). You can put any string there.

@@ -61,7 +61,6 @@ func Swagger(ctx *context.Context) {
// RepoSearchOptions when calling search repositories
type RepoSearchOptions struct {
Ranger func(*models.SearchRepoOptions) (models.RepositoryList, int64, error)
Copy link
Member

Choose a reason for hiding this comment

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

AFAIK Ranger is not needed anymore and can be generally be removed from RepoSearchOptions and thus at

Ranger: models.Repositories,
too.

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, but I'll remove more redudant functions in another PR (I mentioned it in #2371). 1 removed function is enough right now (as it belongs to #2371). This PR (it's not based on master) is about adding feature.

for _, repo := range body.Data {
assert.Contains(t, repo.Name, keyword)
assert.False(t, repo.Private)
}
Copy link
Member

Choose a reason for hiding this comment

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

This test should also be added to your testCases list

Copy link
Member Author

Choose a reason for hiding this comment

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

I am thinking (last few days) about extracting this change to new PR because actually it's fix for non working test.

assert.NoError(t, err)
assert.Equal(t, int64(3), count)
assert.Len(t, repos, 3)
Copy link
Member

Choose a reason for hiding this comment

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

Add existing tests to testCases.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't want to do it in this (#2371) PR because:

  1. I want to show my PR will pass existing tests without changes
  2. For moving existing tests to my added test cases it would be needed fixes at least in "repository.yml" and "access.yml".

@Morlinest Morlinest force-pushed the feature-api-repo-search-options branch 2 times, most recently from 0baae9f to 2c8263c Compare September 20, 2017 14:37
@Morlinest Morlinest force-pushed the feature-api-repo-search-options branch from 2c8263c to 19c15bb Compare September 21, 2017 09:48
@Morlinest Morlinest closed this Sep 22, 2017
@lunny
Copy link
Member

lunny commented Sep 22, 2017

@Morlinest why close this PR?

@Morlinest
Copy link
Member Author

@lunny I'll reopen this PR once needed changes will be made and merged (#2321, #2371).

@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants