ronantakizawa/codereview-bench huggingface dataset:
Repository: go-gitea/gitea
File: modules/git/gitcmd/command.go (Go)

Code before:
	// This is because Windows does not have signal checking when terminating the process.
	// It always returns exit code 1, unlike Linux, which has many exit codes for signals.
	// `err.Error()` returns "exit status 1" when using the `git check-attr` command after the context is canceled.
	if runtime.GOOS == "windows" &&
		err != nil &&
		(err.Error() == "" || err.Error() == "exit status 1") &&
		cmd.ProcessState.ExitCode() == 1 &&
		ctx.Err() == context.Canceled {
		return ctx.Err()
	}

	if err != nil && ctx.Err() != context.DeadlineExceeded {
		return err
	}

	return ctx.Err()
}

type RunStdError interface {
	error
	Unwrap() error
	Stderr() string
}

type runStdError struct {
	err    error  // usually the low-level error like exec.ExitError
	stderr string // git command's stderr output
	errMsg string // the cached error message for Error() method
}

func (r *runStdError) Error() string {
	// FIXME: GIT-CMD-STDERR: it is a bad design, the stderr should not be put in the error message
	// But a lof of code only checks `strings.Contains(err.Error(), "git error")`
	if r.errMsg == "" {
		r.errMsg = ConcatenateError(r.err, r.stderr).Error()
	}
	return r.errMsg
}

func (r *runStdError) Unwrap() error {
	return r.err
}

func (r *runStdError) Stderr() string {
	return r.stderr
}

func ErrorAsStderr(err error) (string, bool) {
	var runErr RunStdError
	if errors.As(err, &runErr) {
		return runErr.Stderr(), true

Review comment (suggestion):
```suggestion
	err    error  // usually the low-level error like `*exec.ExitError`
```

Code after:
	// This is because Windows does not have signal checking when terminating the process.
	// It always returns exit code 1, unlike Linux, which has many exit codes for signals.
	// `err.Error()` returns "exit status 1" when using the `git check-attr` command after the context is canceled.
	if runtime.GOOS == "windows" &&
		err != nil &&
		(err.Error() == "" || err.Error() == "exit status 1") &&
		cmd.ProcessState.ExitCode() == 1 &&
		ctx.Err() == context.Canceled {
		return ctx.Err()
	}

	if err != nil && ctx.Err() != context.DeadlineExceeded {
		return err
	}

	return ctx.Err()
}

type RunStdError interface {
	error
	Unwrap() error
	Stderr() string
}

type runStdError struct {
	err    error  // usually the low-level error like `*exec.ExitError`
	stderr string // git command's stderr output
	errMsg string // the cached error message for Error() method
}

func (r *runStdError) Error() string {
	// FIXME: GIT-CMD-STDERR: it is a bad design, the stderr should not be put in the error message
	// But a lof of code only checks `strings.Contains(err.Error(), "git error")`
	if r.errMsg == "" {
		r.errMsg = ConcatenateError(r.err, r.stderr).Error()
	}
	return r.errMsg
}

func (r *runStdError) Unwrap() error {
	return r.err
}

func (r *runStdError) Stderr() string {
	return r.stderr
}

func ErrorAsStderr(err error) (string, bool) {
	var runErr RunStdError
	if errors.As(err, &runErr) {
		return runErr.Stderr(), true
Repository: go-gitea/gitea
File: web_src/js/components/RepoFileSearch.vue (Vue)

Code before:
                <span v-for="(part, index) in result.matchResult" :key="index">{{ part }}</span>
              </span>
            </div>
          </div>
          <div v-else-if="isLoadingFileList">
            <div class="is-loading"/>
          </div>
          <div v-else class="tw-p-4">
            {{ props.noResultsText }}
          </div>
        </template>
      </div>
    </Teleport>
  </div>
</template>

<style scoped>
.repo-file-search-input-wrapper {
  position: relative;
}

.repo-file-search-input-wrapper input {
  padding-right: 32px !important;
  border-right: 1px solid var(--color-input-border) !important;
  border-top-right-radius: 0.28571429rem !important;
  border-bottom-right-radius: 0.28571429rem !important;
}

.repo-file-search-input-wrapper input:focus {
  border-color: var(--color-primary) !important;
}

.repo-file-search-shortcut-hint {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-block;
  padding: 2px 5px;
  font-size: 11px;
  line-height: 12px;
  color: var(--color-text-light-2);
  background-color: var(--color-box-body);
  border: 1px solid var(--color-secondary);
  border-radius: 3px;
  pointer-events: none;
}

/* Hide kbd when input is focused so it doesn't interfere with focus border */
.repo-file-search-input-wrapper input:focus + .repo-file-search-shortcut-hint {
  display: none;

Review comment (suggestion):
```suggestion
  border-top-right-radius: var(--border-radius) !important;
  border-bottom-right-radius: var(--border-radius) !important;
```

Code after:
          </div>
          <div v-else-if="isLoadingFileList">
            <div class="is-loading"/>
          </div>
          <div v-else class="tw-p-4">
            {{ props.noResultsText }}
          </div>
        </template>
      </div>
    </Teleport>
  </div>
</template>

<style scoped>
.file-search-popup {
  position: absolute;
  background: var(--color-box-body);
  border: 1px solid var(--color-secondary);
  border-radius: var(--border-radius);
  width: max-content;
  max-height: min(calc(100vw - 20px), 300px);
  max-width: min(calc(100vw - 40px), 600px);
  overflow-y: auto;
}

.file-search-popup .is-loading {
  width: 200px;
  height: 200px;
}

.file-search-results .item {
  align-items: flex-start;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  border-bottom: 1px solid var(--color-secondary);
}

.file-search-results .item:last-child {
  border-bottom: none;
}

.file-search-results .item:hover,
.file-search-results .item.selected {
  background-color: var(--color-hover);
}

.file-search-results .item .file-icon {
  flex-shrink: 0;
  margin-top: 0.125rem;
}
Repository: go-gitea/gitea
File: models/repo/pull_request_default.go (Go)

Code before:
// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package repo

import (
	"context"
	"fmt"
	"strings"

	"code.gitea.io/gitea/models/db"
	"code.gitea.io/gitea/models/unit"
	"code.gitea.io/gitea/modules/util"
)

// ErrDefaultPRBaseBranchNotExist represents an error that branch with such name does not exist.
type ErrDefaultPRBaseBranchNotExist struct {
	RepoID     int64
	BranchName string
}

// IsErrDefaultPRBaseBranchNotExist checks if an error is an ErrDefaultPRBaseBranchNotExist.
func IsErrDefaultPRBaseBranchNotExist(err error) bool {
	_, ok := err.(ErrDefaultPRBaseBranchNotExist)
	return ok
}

func (err ErrDefaultPRBaseBranchNotExist) Error() string {
	return fmt.Sprintf("default PR base branch does not exist [repo_id: %d name: %s]", err.RepoID, err.BranchName)
}

func (err ErrDefaultPRBaseBranchNotExist) Unwrap() error {
	return util.ErrNotExist
}

// GetDefaultPRBaseBranchSetting returns the configured base branch for new pull requests.
// It returns an empty string when unset or pull requests are disabled.
func (repo *Repository) GetDefaultPRBaseBranchSetting(ctx context.Context) string {
	prUnit, err := repo.GetUnit(ctx, unit.TypePullRequests)
	if err != nil {
		return ""
	}
	cfg := prUnit.PullRequestsConfig()
	if cfg == nil {
		return ""
	}
	return strings.TrimSpace(cfg.DefaultPRBaseBranch)
}


Review comment (suggestion):
Such error check will cause problems, it doesn't work with `errors.Is`

`ErrDefaultPRBaseBranchNotExist` can be removed, just use `util.NewNotExistErrorf` and use `errors.Is`

Code after:
// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package repo

import (
	"context"

	"code.gitea.io/gitea/models/unit"
	"code.gitea.io/gitea/modules/util"
)

func (repo *Repository) GetPullRequestTargetBranch(ctx context.Context) string {
	unitPRConfig := repo.MustGetUnit(ctx, unit.TypePullRequests).PullRequestsConfig()
	return util.IfZero(unitPRConfig.DefaultTargetBranch, repo.DefaultBranch)
}
Repository: go-gitea/gitea
File: routers/api/v1/repo/pull_review.go (Go)

Code before:
			ctx.APIErrorNotFound("GetCommentByID", err)
		} else {
			ctx.APIErrorInternal(err)
		}
		return
	}

	if err = comment.LoadIssue(ctx); err != nil {
		ctx.APIErrorInternal(err)
		return
	}

	if comment.Issue.RepoID != ctx.Repo.Repository.ID {
		ctx.APIErrorNotFound("CommentNotInRepo")
		return
	}

	if !comment.Issue.IsPull {
		ctx.APIError(http.StatusBadRequest, "comment does not belong to a pull request")
		return
	}

	if comment.Issue.Index != ctx.PathParamInt64("index") {
		ctx.APIErrorNotFound("CommentNotInPullRequest")
		return
	}

	if comment.Type != issues_model.CommentTypeCode {
		ctx.APIError(http.StatusBadRequest, "comment is not a review comment")
		return
	}

	permResult, err := issues_model.CanMarkConversation(ctx, comment.Issue, ctx.Doer)
	if err != nil {
		ctx.APIErrorInternal(err)
		return
	}
	if !permResult {
		ctx.APIError(http.StatusForbidden, "user should have permission to resolve comment")
		return
	}

	wasResolved := comment.ResolveDoerID != 0
	if err = issues_model.MarkConversation(ctx, comment, ctx.Doer, isResolve); err != nil {
		ctx.APIErrorInternal(err)
		return
	}

	if isResolve {
		if !wasResolved {
			comment.ResolveDoerID = ctx.Doer.ID

Review comment (refactor):
I think it needs a function like `GetCommentByRepoIssueIndex(repoID, issueIndex, commentID)` to simplify the logic, and I think there have been many similar usages.

Code after:
		ctx.APIErrorInternal(err)
		return
	}

	ctx.Status(http.StatusNoContent)
}

func getPullReviewCommentToResolve(ctx *context.APIContext) *issues_model.Comment {
	comment, err := issues_model.GetCommentWithRepoID(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("id"))
	if err != nil {
		if issues_model.IsErrCommentNotExist(err) {
			ctx.APIErrorNotFound("GetCommentByID", err)
		} else {
			ctx.APIErrorInternal(err)
		}
		return nil
	}

	if !comment.Issue.IsPull {
		ctx.APIError(http.StatusBadRequest, "comment does not belong to a pull request")
		return nil
	}

	if comment.Type != issues_model.CommentTypeCode {
		ctx.APIError(http.StatusBadRequest, "comment is not a review comment")
		return nil
	}

	return comment
}

// DeletePullReview delete a specific review from a pull request
func DeletePullReview(ctx *context.APIContext) {
	// swagger:operation DELETE /repos/{owner}/{repo}/pulls/{index}/reviews/{id} repository repoDeletePullReview
	// ---
	// summary: Delete a specific review from a pull request
	// produces:
	// - application/json
	// parameters:
	// - name: owner
	//   in: path
	//   description: owner of the repo
	//   type: string
	//   required: true
	// - name: repo
	//   in: path
	//   description: name of the repo
	//   type: string
	//   required: true
	// - name: index
	//   in: path
Repository: go-gitea/gitea
File: routers/api/v1/repo/pull_review.go (Go)

Code before:
	//   required: true
	// responses:
	//   "200":
	//     "$ref": "#/responses/PullReviewCommentList"
	//   "404":
	//     "$ref": "#/responses/notFound"

	review, _, statusSet := prepareSingleReview(ctx)
	if statusSet {
		return
	}

	apiComments, err := convert.ToPullReviewCommentList(ctx, review, ctx.Doer)
	if err != nil {
		ctx.APIErrorInternal(err)
		return
	}

	ctx.JSON(http.StatusOK, apiComments)
}

// ResolvePullReviewComment resolves a review comment in a pull request
func ResolvePullReviewComment(ctx *context.APIContext) {
	// swagger:operation POST /repos/{owner}/{repo}/pulls/comments/{id}/resolve repository repoResolvePullReviewComment
	// ---
	// summary: Resolve a pull review comment
	// produces:
	// - application/json
	// parameters:
	// - name: owner
	//   in: path
	//   description: owner of the repo
	//   type: string
	//   required: true
	// - name: repo
	//   in: path
	//   description: name of the repo
	//   type: string
	//   required: true
	// - name: id
	//   in: path
	//   description: id of the review comment
	//   type: integer
	//   format: int64
	//   required: true
	// responses:
	//   "204":
	//     "$ref": "#/responses/empty"
	//   "400":
	//     "$ref": "#/responses/validationError"
	//   "403":

Review comment (suggestion):
```suggestion
	// summary: Resolve a PR review comment
```

Code after:
	//   required: true
	// responses:
	//   "200":
	//     "$ref": "#/responses/PullReviewCommentList"
	//   "404":
	//     "$ref": "#/responses/notFound"

	review, _, statusSet := prepareSingleReview(ctx)
	if statusSet {
		return
	}

	apiComments, err := convert.ToPullReviewCommentList(ctx, review, ctx.Doer)
	if err != nil {
		ctx.APIErrorInternal(err)
		return
	}

	ctx.JSON(http.StatusOK, apiComments)
}

// ResolvePullReviewComment resolves a review comment in a pull request
func ResolvePullReviewComment(ctx *context.APIContext) {
	// swagger:operation POST /repos/{owner}/{repo}/pulls/comments/{id}/resolve repository repoResolvePullReviewComment
	// ---
	// summary: Resolve a pull request review comment
	// produces:
	// - application/json
	// parameters:
	// - name: owner
	//   in: path
	//   description: owner of the repo
	//   type: string
	//   required: true
	// - name: repo
	//   in: path
	//   description: name of the repo
	//   type: string
	//   required: true
	// - name: id
	//   in: path
	//   description: id of the review comment
	//   type: integer
	//   format: int64
	//   required: true
	// responses:
	//   "204":
	//     "$ref": "#/responses/empty"
	//   "400":
	//     "$ref": "#/responses/validationError"
	//   "403":
Repository: go-gitea/gitea
File: routers/api/v1/repo/pull_review.go (Go)

Code before:
	//   description: name of the repo
	//   type: string
	//   required: true
	// - name: id
	//   in: path
	//   description: id of the review comment
	//   type: integer
	//   format: int64
	//   required: true
	// responses:
	//   "204":
	//     "$ref": "#/responses/empty"
	//   "400":
	//     "$ref": "#/responses/validationError"
	//   "403":
	//     "$ref": "#/responses/forbidden"
	//   "404":
	//     "$ref": "#/responses/notFound"
	updatePullReviewCommentResolve(ctx, true)
}

// UnresolvePullReviewComment unresolves a review comment in a pull request
func UnresolvePullReviewComment(ctx *context.APIContext) {
	// swagger:operation POST /repos/{owner}/{repo}/pulls/comments/{id}/unresolve repository repoUnresolvePullReviewComment
	// ---
	// summary: Unresolve a pull review comment
	// produces:
	// - application/json
	// parameters:
	// - name: owner
	//   in: path
	//   description: owner of the repo
	//   type: string
	//   required: true
	// - name: repo
	//   in: path
	//   description: name of the repo
	//   type: string
	//   required: true
	// - name: id
	//   in: path
	//   description: id of the review comment
	//   type: integer
	//   format: int64
	//   required: true
	// responses:
	//   "204":
	//     "$ref": "#/responses/empty"
	//   "400":
	//     "$ref": "#/responses/validationError"
	//   "403":

Review comment (suggestion):
```suggestion
	// summary: Unresolve a PR review comment
```

Code after:
	//   description: name of the repo
	//   type: string
	//   required: true
	// - name: id
	//   in: path
	//   description: id of the review comment
	//   type: integer
	//   format: int64
	//   required: true
	// responses:
	//   "204":
	//     "$ref": "#/responses/empty"
	//   "400":
	//     "$ref": "#/responses/validationError"
	//   "403":
	//     "$ref": "#/responses/forbidden"
	//   "404":
	//     "$ref": "#/responses/notFound"
	updatePullReviewCommentResolve(ctx, true)
}

// UnresolvePullReviewComment unresolves a review comment in a pull request
func UnresolvePullReviewComment(ctx *context.APIContext) {
	// swagger:operation POST /repos/{owner}/{repo}/pulls/comments/{id}/unresolve repository repoUnresolvePullReviewComment
	// ---
	// summary: Unresolve a pull request review comment
	// produces:
	// - application/json
	// parameters:
	// - name: owner
	//   in: path
	//   description: owner of the repo
	//   type: string
	//   required: true
	// - name: repo
	//   in: path
	//   description: name of the repo
	//   type: string
	//   required: true
	// - name: id
	//   in: path
	//   description: id of the review comment
	//   type: integer
	//   format: int64
	//   required: true
	// responses:
	//   "204":
	//     "$ref": "#/responses/empty"
	//   "400":
	//     "$ref": "#/responses/validationError"
	//   "403":
Repository: go-gitea/gitea
File: services/repository/create.go (Go)

Code before:
	}

	if setting.Service.AutoWatchNewRepos {
		if err = repo_model.WatchRepo(ctx, doer, repo, true); err != nil {
			return fmt.Errorf("WatchRepo: %w", err)
		}
	}

	if err = webhook.CopyDefaultWebhooksToRepo(ctx, repo.ID); err != nil {
		return fmt.Errorf("CopyDefaultWebhooksToRepo: %w", err)
	}

	return nil
}

func cleanupRepository(repoID int64) {
	ctx := graceful.GetManager().ShutdownContext()
	if errDelete := DeleteRepositoryDirectly(ctx, repoID); errDelete != nil {
		log.Error("cleanupRepository failed: %v", errDelete)
		// Try to get repository name for better error message
		repoIdentifier := fmt.Sprintf("[%d]", repoID)
		if repo, err := repo_model.GetRepositoryByID(ctx, repoID); err == nil {
			repoIdentifier = fmt.Sprintf("(%s)", repo.FullName())
		}
		// add system notice
		if err := system_model.CreateRepositoryNotice("DeleteRepositoryDirectly failed when cleanup repository %s: %v", repoIdentifier, errDelete); err != nil {
			log.Error("CreateRepositoryNotice: %v", err)
		}
	}
}

func updateGitRepoAfterCreate(ctx context.Context, repo *repo_model.Repository) error {
	if err := CheckDaemonExportOK(ctx, repo); err != nil {
		return fmt.Errorf("checkDaemonExportOK: %w", err)
	}

	if stdout, _, err := gitrepo.RunCmdString(ctx, repo,
		gitcmd.NewCommand("update-server-info")); err != nil {
		log.Error("CreateRepository(git update-server-info) in %v: Stdout: %s\nError: %v", repo, stdout, err)
		return fmt.Errorf("CreateRepository(git update-server-info): %w", err)
	}
	return nil
}


Review comment (suggestion):
When calling `cleanupRepository`, there is always a "repo" object (struct)

So there is no need to load the repo again.

Code after:
	}

	if setting.Service.AutoWatchNewRepos {
		if err = repo_model.WatchRepo(ctx, doer, repo, true); err != nil {
			return fmt.Errorf("WatchRepo: %w", err)
		}
	}

	if err = webhook.CopyDefaultWebhooksToRepo(ctx, repo.ID); err != nil {
		return fmt.Errorf("CopyDefaultWebhooksToRepo: %w", err)
	}

	return nil
}

func cleanupRepository(repo *repo_model.Repository) {
	ctx := graceful.GetManager().ShutdownContext()
	if errDelete := DeleteRepositoryDirectly(ctx, repo.ID); errDelete != nil {
		log.Error("cleanupRepository failed: %v", errDelete)
		if err := system_model.CreateRepositoryNotice("DeleteRepositoryDirectly failed when cleanup repository (%s)", repo.FullName(), errDelete); err != nil {
			log.Error("CreateRepositoryNotice: %v", err)
		}
	}
}

func updateGitRepoAfterCreate(ctx context.Context, repo *repo_model.Repository) error {
	if err := CheckDaemonExportOK(ctx, repo); err != nil {
		return fmt.Errorf("checkDaemonExportOK: %w", err)
	}

	if stdout, _, err := gitrepo.RunCmdString(ctx, repo,
		gitcmd.NewCommand("update-server-info")); err != nil {
		log.Error("CreateRepository(git update-server-info) in %v: Stdout: %s\nError: %v", repo, stdout, err)
		return fmt.Errorf("CreateRepository(git update-server-info): %w", err)
	}
	return nil
}
Repository: go-gitea/gitea
File: modules/fileicon/render_test.go (Go)

Code before:
// Copyright 2025 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package fileicon_test

import (
	"testing"

	"code.gitea.io/gitea/modules/fileicon"
	"code.gitea.io/gitea/modules/git"
	"code.gitea.io/gitea/modules/setting"
	"code.gitea.io/gitea/modules/test"

	"github.com/stretchr/testify/assert"
)

func TestRenderEntryIconHTML_WithDifferentThemes(t *testing.T) {
	// Test that folder icons use the folder theme
	t.Run("FolderUsesBasicTheme", func(t *testing.T) {
		defer test.MockVariableValue(&setting.UI.FileIconTheme, "material")()
		defer test.MockVariableValue(&setting.UI.FolderIconTheme, "basic")()

		folderEntry := &fileicon.EntryInfo{
			BaseName:  "testfolder",
			EntryMode: git.EntryModeTree,
		}

Review comment (security):
```suggestion
// Copyright 2026 The Gitea Authors. All rights reserved.
```

Code after:
// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package fileicon_test

import (
	"testing"

	"code.gitea.io/gitea/modules/fileicon"
	"code.gitea.io/gitea/modules/git"
	"code.gitea.io/gitea/modules/setting"
	"code.gitea.io/gitea/modules/test"

	"github.com/stretchr/testify/assert"
)

func TestRenderEntryIconHTML_WithDifferentThemes(t *testing.T) {
	// Test that folder icons use the folder theme
	t.Run("FolderUsesBasicTheme", func(t *testing.T) {
		defer test.MockVariableValue(&setting.UI.FileIconTheme, "material")()
		defer test.MockVariableValue(&setting.UI.FolderIconTheme, "basic")()

		folderEntry := &fileicon.EntryInfo{
			BaseName:  "testfolder",
			EntryMode: git.EntryModeTree,
		}
Repository: go-gitea/gitea
File: modules/analyze/vendor.go (Go)

Code before:
package analyze

import (
	"path/filepath"
	"strings"

	"github.com/go-enry/go-enry/v2"
)

// IsVendor returns whether or not path is a vendor path.
// It uses go-enry's IsVendor function but overrides its detection for certain
// special cases that shouldn't be marked as vendored in the diff view.
// See https://github.com/go-gitea/gitea/issues/22618
func IsVendor(path string) bool {
	if !enry.IsVendor(path) {
		return false
	}

	// go-enry marks certain files as "vendored" for language statistics purposes,
	// but these shouldn't show as "Vendored" in Gitea's diff view.
	// Override detection for these special cases.
	basename := filepath.Base(path)
	switch basename {
	case ".gitignore", ".gitattributes", ".gitmodules":
		return false
	}

	// Files in .github/ directory shouldn't be marked as vendored
	if strings.HasPrefix(path, ".github/") || strings.Contains(path, "/.github/") {
		return false
	}

	return true
}


Review comment (suggestion):
@copilot

1. also include the `.gitea` directory here
2. check if both conditions are actually needed. If `path` is relative to the repo root, the only needed condition should be `strings.HasPrefix(path, ".github/")`.

Code after:
package analyze

import (
	"path"
	"strings"

	"github.com/go-enry/go-enry/v2"
)

// IsVendor returns whether the path is a vendor path.
// It uses go-enry's IsVendor function but overrides its detection for certain
// special cases that shouldn't be marked as vendored in the diff view.
func IsVendor(treePath string) bool {
	if !enry.IsVendor(treePath) {
		return false
	}

	// Override detection for single files
	basename := path.Base(treePath)
	switch basename {
	case ".gitignore", ".gitattributes", ".gitmodules":
		return false
	}
	if strings.HasPrefix(treePath, ".github/") || strings.HasPrefix(treePath, ".gitea/") {
		return false
	}
	return true
}