-
Notifications
You must be signed in to change notification settings - Fork 96
Fixed Repo delete by name #6336
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,7 +40,11 @@ func (s *Server) RegisterRepository( | |
| in *pb.RegisterRepositoryRequest, | ||
| ) (*pb.RegisterRepositoryResponse, error) { | ||
| projectID := GetProjectID(ctx) | ||
| providerName := GetProviderName(ctx) | ||
|
|
||
| if in.GetContext() == nil || in.GetContext().GetProvider() == "" { | ||
| return nil, util.UserVisibleError(codes.InvalidArgument, "provider name must be specified when registering a repository") | ||
| } | ||
| providerName := in.GetContext().GetProvider() | ||
|
|
||
| var fetchByProps *properties.Properties | ||
| var provider *db.Provider | ||
|
|
@@ -137,10 +141,15 @@ func (s *Server) repoCreateInfoFromUpstreamEntityRef( | |
| // This function will typically be called by the client to get a list of | ||
| // repositories that are registered present in the minder database | ||
| func (s *Server) ListRepositories(ctx context.Context, | ||
| _ *pb.ListRepositoriesRequest) (*pb.ListRepositoriesResponse, error) { | ||
| in *pb.ListRepositoriesRequest) (*pb.ListRepositoriesResponse, error) { | ||
|
|
||
| if in.GetContext() == nil || in.GetContext().GetProvider() == "" { | ||
| return nil, util.UserVisibleError(codes.InvalidArgument, "provider name must be specified when listing repositories") | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't seem to crash or cause a problem today: $ ./bin/minder repo list
OWNER │ NAME │ PROVIDER │ UPSTREAM ID
────────────────────┼───────────┼─────────────────────────────────┼────────────────
a-random-sandbox │ colorls │ github-app-a-random-sandbox │ 693510024
├───────────┤ ├────────────────
│ doitlive │ │ 693507178
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With $ curl -H "Authorization: Bearer $(jq -r .access_token ~/.config/minder/127.0.0.1_8090.json)" 'http://localhost:8080/api/v1/repositories/provider/' | jq '.results[] | .name'
...
"colorls"
"doitlive" |
||
|
|
||
| entityCtx := engcontext.EntityFromContext(ctx) | ||
| projectID := entityCtx.Project.ID | ||
| providerName := entityCtx.Provider.Name | ||
| providerName := in.GetContext().GetProvider() | ||
|
|
||
| logger.BusinessRecord(ctx).Provider = providerName | ||
| logger.BusinessRecord(ctx).Project = projectID | ||
|
|
@@ -239,9 +248,13 @@ func (s *Server) GetRepositoryByName(ctx context.Context, | |
| return nil, util.UserVisibleError(codes.InvalidArgument, "invalid repository name, needs to have the format: owner/name") | ||
| } | ||
|
|
||
| if in.GetContext() == nil || in.GetContext().GetProvider() == "" { | ||
| return nil, util.UserVisibleError(codes.InvalidArgument, "provider name must be specified when getting a repository by name") | ||
| } | ||
|
|
||
| entityCtx := engcontext.EntityFromContext(ctx) | ||
| projectID := entityCtx.Project.ID | ||
| providerName := entityCtx.Provider.Name | ||
| providerName := in.GetContext().GetProvider() | ||
|
|
||
| // Use the service to fetch the repository | ||
| repo, err := s.repos.GetRepositoryByName(ctx, fragments[0], fragments[1], projectID, providerName) | ||
|
|
@@ -298,7 +311,12 @@ func (s *Server) DeleteRepositoryByName( | |
| } | ||
|
|
||
| projectID := GetProjectID(ctx) | ||
| providerName := GetProviderName(ctx) | ||
|
|
||
| if in.GetContext() == nil || in.GetContext().GetProvider() == "" { | ||
| return nil, util.UserVisibleError(codes.InvalidArgument, "provider name must be specified when deleting a repository by name") | ||
| } | ||
|
Comment on lines
+315
to
+317
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't seem to crash today: $ ./bin/minder repo delete -n a-random-sandbox/.github
Successfully deleted repo with name: a-random-sandbox/.github |
||
|
|
||
| providerName := in.GetContext().GetProvider() | ||
|
|
||
| err := s.repos.DeleteByName(ctx, fragments[0], fragments[1], projectID, providerName) | ||
| if errors.Is(err, sql.ErrNoRows) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetProvider()already handles being called on anil*Context-- using the proto getters will automatically handle empty / missing fields by returning the default (zero) value.