Skip to content

Commit

Permalink
🧹 handle case where gitlab project has no commit yet (#1981)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-rock authored Sep 29, 2023
1 parent 50b6865 commit 1fde3ba
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions providers/gitlab/provider/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (s *Service) discoverTerraform(root *inventory.Asset, conn *connection.GitL
project := projects[i]
files, err := discoverTerraformHcl(conn.Client(), project.ID)
if err != nil {
log.Error().Err(err).Msg("failed to discover terraform repo in gitlab")
log.Error().Err(err).Str("project", project.PathWithNamespace).Msg("failed to discover terraform repo in gitlab")
} else if len(files) != 0 {
res = append(res, &inventory.Asset{
Connections: []*inventory.Config{{
Expand Down Expand Up @@ -206,7 +206,10 @@ func discoverTerraformHcl(client *gitlab.Client, pid interface{}) ([]string, err
nodes := []*gitlab.TreeNode{}
for {
data, resp, err := client.Repositories.ListTree(pid, opts)
if err != nil {
if err != nil && resp.StatusCode == 404 {
// this case can happen when you have a new project with no commits / files
break
} else if err != nil {
return nil, err
}
nodes = append(nodes, data...)
Expand Down

0 comments on commit 1fde3ba

Please sign in to comment.