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

Index repositories after adoption #14304

Closed
4 tasks
LukeMauldin opened this issue Jan 11, 2021 · 3 comments · Fixed by #25497
Closed
4 tasks

Index repositories after adoption #14304

LukeMauldin opened this issue Jan 11, 2021 · 3 comments · Fixed by #25497
Labels
Milestone

Comments

@LukeMauldin
Copy link

  • Gitea version (or commit ref): 1.13.1

  • Git version: 2.29

  • Operating system: RHEL8

  • Database (use [x]):

    • [ X ] PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:

    • Yes (provide example URL)
    • [ X ] No

Description

Provide a way to manually trigger source code indexing of repositories. In my scenario, I have used the Adopt functionality to import a large number of repositories (over 500) but they are not indexed. If I make a commit then it does appear the indexing functionality is working as expected but it is not practical to make commits to 500+ repos. Need an admin API that would trigger the indexing process.
As an enhancement to the adoption process, indexing could/should be triggered as a part of that process too.

@zeripath
Copy link
Contributor

zeripath commented Jan 11, 2021

mea culpa - probably need to ensure that something like:

func HookPostReceive(ctx *macaron.Context, opts private.HookOptions) {
ownerName := ctx.Params(":owner")
repoName := ctx.Params(":repo")
var repo *models.Repository
updates := make([]*repo_module.PushUpdateOptions, 0, len(opts.OldCommitIDs))
wasEmpty := false
for i := range opts.OldCommitIDs {
refFullName := opts.RefFullNames[i]
// Only trigger activity updates for changes to branches or
// tags. Updates to other refs (eg, refs/notes, refs/changes,
// or other less-standard refs spaces are ignored since there
// may be a very large number of them).
if strings.HasPrefix(refFullName, git.BranchPrefix) || strings.HasPrefix(refFullName, git.TagPrefix) {
if repo == nil {
var err error
repo, err = models.GetRepositoryByOwnerAndName(ownerName, repoName)
if err != nil {
log.Error("Failed to get repository: %s/%s Error: %v", ownerName, repoName, err)
ctx.JSON(http.StatusInternalServerError, private.HookPostReceiveResult{
Err: fmt.Sprintf("Failed to get repository: %s/%s Error: %v", ownerName, repoName, err),
})
return
}
if repo.OwnerName == "" {
repo.OwnerName = ownerName
}
wasEmpty = repo.IsEmpty
}
option := repo_module.PushUpdateOptions{
RefFullName: refFullName,
OldCommitID: opts.OldCommitIDs[i],
NewCommitID: opts.NewCommitIDs[i],
PusherID: opts.UserID,
PusherName: opts.UserName,
RepoUserName: ownerName,
RepoName: repoName,
}
updates = append(updates, &option)
if repo.IsEmpty && option.IsBranch() && (option.BranchName() == "master" || option.BranchName() == "main") {
// put the master/main branch first
copy(updates[1:], updates)
updates[0] = &option
}
}
}
if repo != nil && len(updates) > 0 {
if err := repo_service.PushUpdates(updates); err != nil {
log.Error("Failed to Update: %s/%s Total Updates: %d", ownerName, repoName, len(updates))
for i, update := range updates {
log.Error("Failed to Update: %s/%s Update: %d/%d: Branch: %s", ownerName, repoName, i, len(updates), update.BranchName())
}
log.Error("Failed to Update: %s/%s Error: %v", ownerName, repoName, err)
ctx.JSON(http.StatusInternalServerError, private.HookPostReceiveResult{
Err: fmt.Sprintf("Failed to Update: %s/%s Error: %v", ownerName, repoName, err),
})
return
}
}

is called for each branch in the adopted repo.

@LukeMauldin
Copy link
Author

Is there any work around after I have imported them?

@zeripath
Copy link
Contributor

Push an empty commit should do it

@noerw noerw added the type/bug label Jan 17, 2021
@lunny lunny added this to the 1.20.0 milestone Jun 25, 2023
techknowlogick pushed a commit that referenced this issue Jun 26, 2023
GiteaBot pushed a commit to GiteaBot/gitea that referenced this issue Jun 26, 2023
silverwind pushed a commit that referenced this issue Jun 26, 2023
Backport #25497 by @lunny

Fix #14304

Co-authored-by: Lunny Xiao <[email protected]>
Co-authored-by: delvh <[email protected]>
Co-authored-by: KN4CK3R <[email protected]>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants