Skip to content

Automatically connect source code repository to package on upload operation #27318

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

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions routers/api/packages/container/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/models/db"
packages_model "code.gitea.io/gitea/models/packages"
container_model "code.gitea.io/gitea/models/packages/container"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/log"
packages_module "code.gitea.io/gitea/modules/packages"
container_module "code.gitea.io/gitea/modules/packages/container"
Expand Down Expand Up @@ -119,6 +120,17 @@ func getOrCreateUploadVersion(ctx context.Context, pi *packages_service.PackageI
log.Error("Error setting package property: %v", err)
return err
}

repository, err := repo_model.GetRepositoryByOwnerAndName(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use package name as repository name to search the repository?

Copy link
Author

@ghost ghost Oct 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. 
Let's say "bob" have a git repository called "uno". This repository contains source code for the alpine/debian/rpm/container/etc package.
Once "bob" uploads a package (of any type) called "uno" a repository with the source code will be automatically connected to the package, search across repositories is made using package name.

image

ctx, pi.Owner.Name, p.Name,
)
if err == nil {
err = packages_model.SetRepositoryLink(ctx, p.ID, repository.ID)
if err != nil {
log.Error("Error linking source code repo to container: %v", err)
return err
}
}
}

pv := &packages_model.PackageVersion{
Expand Down
11 changes: 11 additions & 0 deletions services/packages/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,17 @@ func createPackageAndVersion(ctx context.Context, pvci *PackageCreationInfo, all
return nil, false, err
}
}

repository, err := repo_model.GetRepositoryByOwnerAndName(
ctx, pvci.Owner.Name, pvci.Name,
)
if err == nil {
err = packages_model.SetRepositoryLink(ctx, p.ID, repository.ID)
if err != nil {
log.Error("Error linking source code repo to package: %v", err)
return nil, false, err
}
}
}

metadataJSON, err := json.Marshal(pvci.Metadata)
Expand Down