Repository: go-gitea/gitea
File: services/repository/repository.go (Go)

Code before:
			return fmt.Errorf("getRepositoriesByForkID: %w", err)
		}
		for i := range forkRepos {
			if err = MakeRepoPrivate(ctx, forkRepos[i]); err != nil {
				return fmt.Errorf("MakeRepoPrivate[%d]: %w", forkRepos[i].ID, err)
			}
		}

		// If visibility is changed, we need to update the issue indexer.
		// Since the data in the issue indexer have field to indicate if the repo is public or not.
		issue_indexer.UpdateRepoIndexer(ctx, repo.ID)

		return nil
	})
}

// LinkedRepository returns the linked repo if any
func LinkedRepository(ctx context.Context, a *repo_model.Attachment) (*repo_model.Repository, unit.Type, error) {
	if a.IssueID != 0 {
		iss, err := issues_model.GetIssueByID(ctx, a.IssueID)
		if err != nil {
			return nil, unit.TypeIssues, err
		}
		if iss.RepoID != a.RepoID {
			return nil, -1, errors.New("attachment and issue belong to different repositories")
		}
		repo, err := repo_model.GetRepositoryByID(ctx, iss.RepoID)
		unitType := unit.TypeIssues
		if iss.IsPull {
			unitType = unit.TypePullRequests
		}
		return repo, unitType, err
	} else if a.ReleaseID != 0 {
		rel, err := repo_model.GetReleaseByID(ctx, a.ReleaseID)
		if err != nil {
			return nil, unit.TypeReleases, err
		}
		if rel.RepoID != a.RepoID {
			return nil, -1, errors.New("attachment and release belong to different repositories")
		}
		repo, err := repo_model.GetRepositoryByID(ctx, a.RepoID)
		return repo, unit.TypeReleases, err
	}
	return nil, -1, nil
}

// CheckDaemonExportOK creates/removes git-daemon-export-ok for git-daemon...
func CheckDaemonExportOK(ctx context.Context, repo *repo_model.Repository) error {
	if err := repo.LoadOwner(ctx); err != nil {
		return err
	}

Review comment (bug):
Attachment already has its own "RepoID" field. Issue has its own RepoID.

Why it makes sense to check them again and again?

In which case these two RepoIDs would mismatch? Isn't is a more serious bug?

Code after:
		}

		forkRepos, err := repo_model.GetRepositoriesByForkID(ctx, repo.ID)
		if err != nil {
			return fmt.Errorf("getRepositoriesByForkID: %w", err)
		}
		for i := range forkRepos {
			if err = MakeRepoPrivate(ctx, forkRepos[i]); err != nil {
				return fmt.Errorf("MakeRepoPrivate[%d]: %w", forkRepos[i].ID, err)
			}
		}

		// If visibility is changed, we need to update the issue indexer.
		// Since the data in the issue indexer have field to indicate if the repo is public or not.
		issue_indexer.UpdateRepoIndexer(ctx, repo.ID)

		return nil
	})
}

// GetAttachmentLinkedType returns the linked type of attachment if any
func GetAttachmentLinkedType(ctx context.Context, a *repo_model.Attachment) (unit.Type, error) {
	if a.IssueID != 0 {
		iss, err := issues_model.GetIssueByID(ctx, a.IssueID)
		if err != nil {
			return unit.TypeIssues, err
		}
		unitType := unit.TypeIssues
		if iss.IsPull {
			unitType = unit.TypePullRequests
		}
		return unitType, nil
	}

	if a.ReleaseID != 0 {
		_, err := repo_model.GetReleaseByID(ctx, a.ReleaseID)
		return unit.TypeReleases, err
	}
	return unit.TypeInvalid, nil
}

// CheckDaemonExportOK creates/removes git-daemon-export-ok for git-daemon...
func CheckDaemonExportOK(ctx context.Context, repo *repo_model.Repository) error {
	if err := repo.LoadOwner(ctx); err != nil {
		return err
	}

	// Create/Remove git-daemon-export-ok for git-daemon...
	daemonExportFile := `git-daemon-export-ok`
	isExist, err := gitrepo.IsRepoFileExist(ctx, repo, daemonExportFile)
	if err != nil {