Fix some pending problems (#29985)

These changes are quite independent and trivial, so I don't want to open
too many PRs.

* https://github.com/go-gitea/gitea/pull/29882#discussion_r1529607091
    * the `f.Close` should be called properly
* the error message could be more meaningful
(https://github.com/go-gitea/gitea/pull/29882#pullrequestreview-1942557935)
*
https://github.com/go-gitea/gitea/pull/29859#pullrequestreview-1942324716
    * the new translation strings don't take arguments
* https://github.com/go-gitea/gitea/pull/28710#discussion_r1443778807
    * stale for long time
*  #28140 
    * a form was forgotten to be changed to work with backend code
This commit is contained in:
wxiaoguang 2024-03-22 19:17:30 +08:00 committed by GitHub
parent 2f060c5834
commit 226231ea27
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 37 additions and 47 deletions

View File

@ -139,6 +139,8 @@ func RegeneratePublicKeys(ctx context.Context, t io.StringWriter) error {
if err != nil { if err != nil {
return err return err
} }
defer f.Close()
scanner := bufio.NewScanner(f) scanner := bufio.NewScanner(f)
for scanner.Scan() { for scanner.Scan() {
line := scanner.Text() line := scanner.Text()
@ -148,15 +150,12 @@ func RegeneratePublicKeys(ctx context.Context, t io.StringWriter) error {
} }
_, err = t.WriteString(line + "\n") _, err = t.WriteString(line + "\n")
if err != nil { if err != nil {
f.Close()
return err return err
} }
} }
err = scanner.Err() if err = scanner.Err(); err != nil {
if err != nil { return fmt.Errorf("RegeneratePublicKeys scan: %w", err)
return fmt.Errorf("scan: %w", err)
} }
f.Close()
} }
return nil return nil
} }

View File

@ -100,7 +100,7 @@ func ReadLogs(ctx context.Context, inStorage bool, filename string, offset, limi
} }
if err := scanner.Err(); err != nil { if err := scanner.Err(); err != nil {
return nil, fmt.Errorf("scan: %w", err) return nil, fmt.Errorf("ReadLogs scan: %w", err)
} }
return rows, nil return rows, nil

View File

@ -397,9 +397,8 @@ func (c *Commit) GetSubModules() (*ObjectCache, error) {
} }
} }
} }
err = scanner.Err() if err = scanner.Err(); err != nil {
if err != nil { return nil, fmt.Errorf("GetSubModules scan: %w", err)
return nil, fmt.Errorf("scan: %w", err)
} }
return c.submoduleCache, nil return c.submoduleCache, nil

View File

@ -124,9 +124,9 @@ func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string)
} }
} }
} }
err = scanner.Err() if err = scanner.Err(); err != nil {
if err != nil { _ = stdoutReader.Close()
return fmt.Errorf("scan: %w", err) return fmt.Errorf("GetCodeActivityStats scan: %w", err)
} }
a := make([]*CodeActivityAuthor, 0, len(authors)) a := make([]*CodeActivityAuthor, 0, len(authors))
for _, v := range authors { for _, v := range authors {

View File

@ -124,9 +124,8 @@ func (Renderer) fallbackRender(input io.Reader, tmpBlock *bufio.Writer) error {
return err return err
} }
} }
err = scan.Err() if err = scan.Err(); err != nil {
if err != nil { return fmt.Errorf("fallbackRender scan: %w", err)
return fmt.Errorf("scan: %w", err)
} }
_, err = tmpBlock.WriteString("</pre>") _, err = tmpBlock.WriteString("</pre>")

View File

@ -980,9 +980,8 @@ func getExcerptLines(commit *git.Commit, filePath string, idxLeft, idxRight, chu
} }
diffLines = append(diffLines, diffLine) diffLines = append(diffLines, diffLine)
} }
err = scanner.Err() if err = scanner.Err(); err != nil {
if err != nil { return nil, fmt.Errorf("getExcerptLines scan: %w", err)
return nil, fmt.Errorf("scan: %w", err)
} }
return diffLines, nil return diffLines, nil
} }

View File

@ -333,9 +333,9 @@ func editFilePost(ctx *context.Context, form forms.EditRepoFileForm, isNewFile b
ctx.Error(http.StatusInternalServerError, err.Error()) ctx.Error(http.StatusInternalServerError, err.Error())
} }
} else if models.IsErrCommitIDDoesNotMatch(err) { } else if models.IsErrCommitIDDoesNotMatch(err) {
ctx.RenderWithErr(ctx.Tr("repo.editor.commit_id_not_matching", ctx.Repo.RepoLink+"/compare/"+util.PathEscapeSegments(form.LastCommit)+"..."+util.PathEscapeSegments(ctx.Repo.CommitID)), tplEditFile, &form) ctx.RenderWithErr(ctx.Tr("repo.editor.commit_id_not_matching"), tplEditFile, &form)
} else if git.IsErrPushOutOfDate(err) { } else if git.IsErrPushOutOfDate(err) {
ctx.RenderWithErr(ctx.Tr("repo.editor.push_out_of_date", ctx.Repo.RepoLink+"/compare/"+util.PathEscapeSegments(form.LastCommit)+"..."+util.PathEscapeSegments(form.NewBranchName)), tplEditFile, &form) ctx.RenderWithErr(ctx.Tr("repo.editor.push_out_of_date"), tplEditFile, &form)
} else if git.IsErrPushRejected(err) { } else if git.IsErrPushRejected(err) {
errPushRej := err.(*git.ErrPushRejected) errPushRej := err.(*git.ErrPushRejected)
if len(errPushRej.Message) == 0 { if len(errPushRej.Message) == 0 {

View File

@ -109,6 +109,8 @@ func regeneratePrincipalKeys(ctx context.Context, t io.StringWriter) error {
if err != nil { if err != nil {
return err return err
} }
defer f.Close()
scanner := bufio.NewScanner(f) scanner := bufio.NewScanner(f)
for scanner.Scan() { for scanner.Scan() {
line := scanner.Text() line := scanner.Text()
@ -118,15 +120,12 @@ func regeneratePrincipalKeys(ctx context.Context, t io.StringWriter) error {
} }
_, err = t.WriteString(line + "\n") _, err = t.WriteString(line + "\n")
if err != nil { if err != nil {
f.Close()
return err return err
} }
} }
err = scanner.Err() if err = scanner.Err(); err != nil {
if err != nil { return fmt.Errorf("regeneratePrincipalKeys scan: %w", err)
return fmt.Errorf("scan: %w", err)
} }
f.Close()
} }
return nil return nil
} }

View File

@ -51,11 +51,11 @@ func checkAuthorizedKeys(ctx context.Context, logger log.Logger, autofix bool) e
} }
linesInAuthorizedKeys.Add(line) linesInAuthorizedKeys.Add(line)
} }
err = scanner.Err() if err = scanner.Err(); err != nil {
if err != nil {
return fmt.Errorf("scan: %w", err) return fmt.Errorf("scan: %w", err)
} }
f.Close() // although there is a "defer close" above, here close explicitly before the generating, because it needs to open the file for writing again
_ = f.Close()
// now we regenerate and check if there are any lines missing // now we regenerate and check if there are any lines missing
regenerated := &bytes.Buffer{} regenerated := &bytes.Buffer{}

View File

@ -374,8 +374,7 @@
*/}} */}}
{{if and $.StillCanManualMerge (not $showGeneralMergeForm)}} {{if and $.StillCanManualMerge (not $showGeneralMergeForm)}}
<div class="divider"></div> <div class="divider"></div>
<div class="ui form"> <form class="ui form form-fetch-action" action="{{.Link}}/merge" method="post">{{/* another similar form is in PullRequestMergeForm.vue*/}}
<form action="{{.Link}}/merge" method="post">
{{.CsrfTokenHtml}} {{.CsrfTokenHtml}}
<div class="field"> <div class="field">
<input type="text" name="merge_commit_id" placeholder="{{ctx.Locale.Tr "repo.pulls.merge_commit_id"}}"> <input type="text" name="merge_commit_id" placeholder="{{ctx.Locale.Tr "repo.pulls.merge_commit_id"}}">
@ -384,7 +383,6 @@
{{ctx.Locale.Tr "repo.pulls.merge_manually"}} {{ctx.Locale.Tr "repo.pulls.merge_manually"}}
</button> </button>
</form> </form>
</div>
{{end}} {{end}}
{{if and .Issue.PullRequest.HeadRepo (not .Issue.PullRequest.HasMerged) (not .Issue.IsClosed)}} {{if and .Issue.PullRequest.HeadRepo (not .Issue.PullRequest.HasMerged) (not .Issue.IsClosed)}}

View File

@ -1,14 +1,10 @@
{{template "base/head" .}} {{template "base/head" .}}
<div role="main" aria-label="{{.Title}}" class="page-content ui container center tw-w-screen {{if .IsRepo}}repository{{end}}"> <div role="main" aria-label="{{.Title}}" class="page-content {{if .IsRepo}}repository{{end}}">
{{if .IsRepo}}{{template "repo/header" .}}{{end}} {{if .IsRepo}}{{template "repo/header" .}}{{end}}
<div class="ui container center"> <div class="ui container tw-text-center">
<p style="margin-top: 100px"><img src="{{AssetUrlPrefix}}/img/404.png" alt="404"></p> <img class="tw-max-w-[80vw] tw-py-16" src="{{AssetUrlPrefix}}/img/404.png" alt="404">
<p>{{if .NotFoundPrompt}}{{.NotFoundPrompt}}{{else}}{{ctx.Locale.Tr "error404"}}{{end}}</p> <p>{{if .NotFoundPrompt}}{{.NotFoundPrompt}}{{else}}{{ctx.Locale.Tr "error404"}}{{end}}</p>
{{if .NotFoundGoBackURL}}<a class="ui button green" href="{{.NotFoundGoBackURL}}">{{ctx.Locale.Tr "go_back"}}</a>{{end}} {{if .NotFoundGoBackURL}}<a class="ui button" href="{{.NotFoundGoBackURL}}">{{ctx.Locale.Tr "go_back"}}</a>{{end}}
<div class="divider"></div>
<br>
{{if .ShowFooterVersion}}<p>{{ctx.Locale.Tr "admin.config.app_ver"}}: {{AppVer}}</p>{{end}}
</div> </div>
</div> </div>
{{template "base/footer" .}} {{template "base/footer" .}}

View File

@ -94,6 +94,7 @@ export default {
<!-- eslint-disable-next-line vue/no-v-html --> <!-- eslint-disable-next-line vue/no-v-html -->
<div v-if="mergeForm.hasPendingPullRequestMerge" v-html="mergeForm.hasPendingPullRequestMergeTip" class="ui info message"/> <div v-if="mergeForm.hasPendingPullRequestMerge" v-html="mergeForm.hasPendingPullRequestMergeTip" class="ui info message"/>
<!-- another similar form is in pull.tmpl (manual merge)-->
<form class="ui form form-fetch-action" v-if="showActionForm" :action="mergeForm.baseLink+'/merge'" method="post"> <form class="ui form form-fetch-action" v-if="showActionForm" :action="mergeForm.baseLink+'/merge'" method="post">
<input type="hidden" name="_csrf" :value="csrfToken"> <input type="hidden" name="_csrf" :value="csrfToken">
<input type="hidden" name="head_commit_id" v-model="mergeForm.pullHeadCommitID"> <input type="hidden" name="head_commit_id" v-model="mergeForm.pullHeadCommitID">