Skip to content

Commit

Permalink
🧹 use languages to detect terraform in github (#4613)
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev authored Aug 29, 2024
1 parent 1bc6b93 commit 38cfc2e
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions providers/github/resources/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,31 +341,14 @@ func discoverTerraform(conn *connection.GithubConnection, repo *mqlGithubReposit

// hasTerraformHcl will check if the repository contains terraform files
func hasTerraformHcl(ctx context.Context, client *github.Client, repo *mqlGithubRepository) (bool, error) {
query := "repo:" + repo.FullName.Data + " extension:tf"
res, _, err := client.Search.Code(ctx, query, &github.SearchOptions{})
languages, _, err := client.Repositories.ListLanguages(ctx, repo.Owner.Data.Login.Data, repo.Name.Data)
if err != nil {
return false, err
}

// Ignore tf files that are hidden or are in a hidden folder
nonHiddenTf := 0
for _, code := range res.CodeResults {
fragments := strings.Split(code.GetPath(), "/")
// skip hidden files
isHidden := false
for _, fragment := range fragments {
if strings.HasPrefix(fragment, ".") {
isHidden = true
break
}
}

if !isHidden {
nonHiddenTf++
}
if languages["HCL"] > 0 {
return true, nil
}

return nonHiddenTf > 0, nil
return false, nil
}

func discoverK8sManifests(conn *connection.GithubConnection, repo *mqlGithubRepository) ([]*inventory.Asset, error) {
Expand Down

0 comments on commit 38cfc2e

Please sign in to comment.