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 HTTP request context #17979

Merged
merged 5 commits into from
Dec 15, 2021

Conversation

wxiaoguang
Copy link
Contributor

@wxiaoguang wxiaoguang commented Dec 14, 2021

Background

I was working on some new enhancements, while I found the modules/context/context.go is quite messy, so I think it's better to refactor first before other works.

Major Changes

  • HTMLString(name string, data interface{}) => RenderToString(name base.TplName, data map[string]interface{}), the first paramter is a TplName, and the old HTMLString naming conflicts with other function names like HTML/PlainText
  • TmplLoadTimes is reworked. The old TmplLoadTimes in old HTMLString has no effects because the render doesn't use ctx.Data
  • NotFound(title string, err error) and ServerError(title string, err error) related functions are refactored, because the title is not title, it only appears in log.
  • use PlainText(string) and PlainTextBytes([]byte) to replace old PlainText([]bytes) and HandleText(string)
  • remove unused SignedUserName
  • use golang standard type contextKeyType struct{}; var contextKey interface{} = contextKeyType{} to replace var contextKey interface{} = "default_context"
  • use ctx.RespHeader() to replace ctx.Header(), because ctx.Header() is not clear whether it is for request or response.

@wxiaoguang wxiaoguang added the type/refactoring Existing code has been cleaned up. There should be no new functionality. label Dec 14, 2021
modules/context/context.go Outdated Show resolved Hide resolved
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Dec 14, 2021
@wxiaoguang
Copy link
Contributor Author

CI failure is not related. Other passed PRs also have such failure:

        testlogger.go:78: 2021/12/14 12:02:08 ...y/files/temp_repo.go:257:CommitTreeWithDate() [E] Unable to commit-tree in temporary repo: user2/initial-unsigned (integrations/gitea-integration-mysql/data/integrations/gitea-integration-mysql/tmp/local-repo/upload.git1503302879) Error: exit status 1
            	Stdout: 
            	Stderr: error: gpg failed to sign the data

        testlogger.go:78: 2021/12/14 12:02:08 .../api/v1/repo/file.go:387:handleCreateOrUpdateFileError() [E] UpdateFile: Unable to commit-tree in temporary repo: user2/initial-unsigned Error: exit status 1
            	Stdout: 
            	Stderr: error: gpg failed to sign the data

@GiteaBot GiteaBot 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 Dec 14, 2021
@GiteaBot GiteaBot 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 Dec 15, 2021
@wxiaoguang wxiaoguang added the skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. label Dec 15, 2021
@codecov-commenter
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (main@9d943bf). Click here to learn what that means.
The diff coverage is 51.78%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #17979   +/-   ##
=======================================
  Coverage        ?   45.28%           
=======================================
  Files           ?      820           
  Lines           ?    90930           
  Branches        ?        0           
=======================================
  Hits            ?    41174           
  Misses          ?    43195           
  Partials        ?     6561           
Impacted Files Coverage Δ
modules/context/repo.go 52.88% <0.00%> (ø)
modules/templates/base.go 44.89% <ø> (ø)
routers/api/v1/user/gpg_key.go 44.31% <0.00%> (ø)
routers/install/install.go 0.56% <0.00%> (ø)
routers/private/mail.go 0.00% <0.00%> (ø)
routers/private/manager.go 0.00% <0.00%> (ø)
routers/private/manager_unix.go 0.00% <0.00%> (ø)
routers/web/repo/branch.go 56.80% <0.00%> (ø)
routers/web/repo/editor.go 24.15% <0.00%> (ø)
routers/web/repo/pull.go 30.54% <0.00%> (ø)
... and 14 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 9d943bf...a1e455f. Read the comment docs.

@wxiaoguang wxiaoguang merged commit 4da1d97 into go-gitea:main Dec 15, 2021
@wxiaoguang wxiaoguang deleted the refactor-http-context branch December 15, 2021 07:00
Chianina pushed a commit to Chianina/gitea that referenced this pull request Mar 28, 2022
@go-gitea go-gitea locked and limited conversation to collaborators Apr 28, 2022
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. skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. type/refactoring Existing code has been cleaned up. There should be no new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants