The Wayback Machine - https://web.archive.org/web/20210807164747/https://github.com/go-gitea/gitea/pull/15800
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

Refactor routers directory #15800

Merged
merged 17 commits into from Jun 8, 2021
Merged

Conversation

@lunny
Copy link
Member

@lunny lunny commented May 9, 2021

This PR creates routers/web, routers/install, routers/private , routers/api for different routers.

  • routers/web includes all web ui requests except api requests from the web ui
  • routers/install includes all install routers
  • routers/private include all internal routers
  • routers/api include all restful API v1 routers
routers/api/v1/repo/file.go Outdated Show resolved Hide resolved
@lunny lunny force-pushed the lunny:lunny/refactor_routers_directory branch 3 times, most recently from 94c35cf to 5ea679c May 9, 2021
@lunny lunny force-pushed the lunny:lunny/refactor_routers_directory branch 4 times, most recently from 901715e to 96dd4da May 29, 2021
@lunny lunny force-pushed the lunny:lunny/refactor_routers_directory branch 3 times, most recently from 59db1e4 to b587910 Jun 5, 2021
@6543 6543 added this to the 1.15.0 milestone Jun 6, 2021
@6543
6543 approved these changes Jun 6, 2021
@codecov-commenter
Copy link

@codecov-commenter codecov-commenter commented Jun 6, 2021

Codecov Report

Merging #15800 (b75a005) into main (e03a91a) will decrease coverage by 0.03%.
The diff coverage is 46.51%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #15800      +/-   ##
==========================================
- Coverage   44.17%   44.14%   -0.04%     
==========================================
  Files         684      693       +9     
  Lines       82289    82286       -3     
==========================================
- Hits        36354    36323      -31     
- Misses      40046    40074      +28     
  Partials     5889     5889              
Impacted Files Coverage Δ
cmd/web.go 0.00% <0.00%> (ø)
routers/api/v1/repo/file.go 62.50% <0.00%> (ø)
routers/install/install.go 0.00% <0.00%> (ø)
routers/install/routes.go 0.00% <0.00%> (ø)
routers/install/setting.go 0.00% <0.00%> (ø)
routers/web/admin/admin.go 11.37% <ø> (ø)
routers/web/admin/auths.go 35.16% <ø> (ø)
routers/web/admin/emails.go 0.00% <ø> (ø)
routers/web/admin/hooks.go 0.00% <ø> (ø)
routers/web/admin/notice.go 0.00% <ø> (ø)
... and 105 more

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 e03a91a...b75a005. Read the comment docs.

routers/web/web.go Outdated Show resolved Hide resolved
@6543
6543 approved these changes Jun 6, 2021
@lunny lunny force-pushed the lunny:lunny/refactor_routers_directory branch from fe32ae6 to 804a500 Jun 7, 2021
@6543
Copy link
Member

@6543 6543 commented Jun 7, 2021

@lunny you removed my changes on rebase :/

routers/common/cors.go Outdated Show resolved Hide resolved
routers/common/db.go Show resolved Hide resolved
routers/install/install.go Outdated Show resolved Hide resolved
routers/install/routes.go Outdated Show resolved Hide resolved
)

// Codes render explore code page
func Codes(ctx *context.Context) {

This comment has been minimized.

@zeripath

zeripath Jun 7, 2021
Contributor

Not really liking this name... I think there's some slight inconsistency with the naming of functions in this package.

This comment has been minimized.

@lunny

lunny Jun 8, 2021
Author Member

The name was changed from ExploreCode to Codes which like ExploreRepos to Repos.

This comment has been minimized.

@zeripath

zeripath Jun 8, 2021
Contributor

I guess Code is already a plural - so I think the s is triggering me. Would be happier if you dropped the s I think.

Suggested change
func Codes(ctx *context.Context) {
func Code(ctx *context.Context) {

But I think there is still a structural issue with the names of page renderers and their sub components here (and elsewhere).

Within this package there are the Render* functions which admittedly have a different signature but everything else in this package is also rendering. So I'm not sure that they need the Render prefix, but I do see the point of having some distinct way of labelling things as incomplete pages. Maybe these should be suffixed Component as they're not full pages. e.g. UserSearchComponent (or moved out of the explore package so the only things it exports are actually full pages.)

If we went for the suffix approach, that would then mean that the full page renderers here & elsewhere should really gain a Page suffix - e.g. CodePage, UsersPage, OrganizationsPage and so on. However, I appreciate that that would make the web routes function a bit wordy - so maybe cleaning up the routers packages so that only full page rendering functions are ever exported from them with subpage components elsewhere might be a better idea.

With better and clearer labelling of full page rendering functions etc we'll be better placed to actually start documenting the renderers as to which paths it's expected to fire on, it's permissions, etc. and maybe even move to make routes functions be generated.

This comment has been minimized.

@lunny

lunny Jun 8, 2021
Author Member

I will rename it to Code but not with Page suffix, otherwise all route functions will be added Page. It's awful.

This comment has been minimized.

@zeripath

zeripath Jun 8, 2021
Contributor

It's not great and I understand the reluctance - however there is a genuine issue here. Here are a couple of examples the problem that adding Page suffices or cleaning up the packages would help with:

in routers/repo/attachment.go:94 there is a func called GetAttachment(ctx context.Context) is this a page renderer? user.GetUserParams isn't a renderer. Turns out that it is a renderer.

RefBlame in routers/repo/blame.go is a page renderer, as is RefCommits in routers/repo/commits.go, Commits in that file is not a direct page renderer though nor are the RepoRefByType functions.

Would you guess that InitializeLabels is actually a page renderer but that RetrieveLabels is not?

From looking at a signature and name of a function you can't tell what it's supposed to be doing - and the comments aren't much better.

This comment has been minimized.

@6543

6543 Jun 8, 2021
Member

should we make the diff even more complex?

I think it's a valid issue but does it meet the scope of this pull?

routers/web/web.go Outdated Show resolved Hide resolved
@lunny lunny force-pushed the lunny:lunny/refactor_routers_directory branch from f0e0b0d to 069fa9d Jun 8, 2021
@6543 6543 requested a review from zeripath Jun 8, 2021
@6543 6543 merged commit 1bfb0a2 into go-gitea:main Jun 8, 2021
2 checks passed
2 checks passed
approvals/lgtm this commit looks good
continuous-integration/drone/pr Build is passing
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants