Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 6 additions & 2 deletions github/data_source_github_ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package github
import (
"context"
"errors"
"log"
"net/http"

"github.com/google/go-github/v84/github"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down Expand Up @@ -56,7 +56,11 @@ func dataSourceGithubRefRead(ctx context.Context, d *schema.ResourceData, meta a
var ghErr *github.ErrorResponse
if errors.As(err, &ghErr) {
if ghErr.Response.StatusCode == http.StatusNotFound {
log.Printf("[DEBUG] Missing GitHub ref %s/%s (%s)", owner, repoName, ref)
tflog.Debug(ctx, "Missing GitHub ref", map[string]any{
"owner": owner,
"repoName": repoName,
"ref": ref,
})
d.SetId("")
return nil
}
Expand Down
7 changes: 5 additions & 2 deletions github/data_source_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"context"
"errors"
"fmt"
"log"
"net/http"
"strings"

"github.com/google/go-github/v84/github"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down Expand Up @@ -370,7 +370,10 @@ func dataSourceGithubRepositoryRead(ctx context.Context, d *schema.ResourceData,
var ghErr *github.ErrorResponse
if errors.As(err, &ghErr) {
if ghErr.Response.StatusCode == http.StatusNotFound {
log.Printf("[DEBUG] Missing GitHub repository %s/%s", owner, repoName)
tflog.Debug(ctx, "Missing GitHub repository", map[string]any{
"owner": owner,
"repo": repoName,
})
d.SetId("")
return nil
}
Expand Down
30 changes: 24 additions & 6 deletions github/data_source_github_repository_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"context"
"errors"
"fmt"
"log"
"net/http"
"net/url"
"strings"

"github.com/google/go-github/v84/github"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down Expand Up @@ -83,11 +83,16 @@ func dataSourceGithubRepositoryFileRead(ctx context.Context, d *schema.ResourceD
// split and replace owner and repo
parts := strings.Split(repo, "/")
if len(parts) == 2 {
log.Printf("[DEBUG] repo has a slash, extracting owner from: %s", repo)
tflog.Debug(ctx, "repo has a slash, extracting owner from", map[string]any{
"repo": repo,
})
owner = parts[0]
repo = parts[1]

log.Printf("[DEBUG] owner: %s repo:%s", owner, repo)
tflog.Debug(ctx, "owner and repo", map[string]any{
"owner": owner,
"repo": repo,
})
}

file := d.Get("file").(string)
Expand All @@ -102,7 +107,11 @@ func dataSourceGithubRepositoryFileRead(ctx context.Context, d *schema.ResourceD
var ghErr *github.ErrorResponse
if errors.As(err, &ghErr) {
if ghErr.Response.StatusCode == http.StatusNotFound {
log.Printf("[DEBUG] Missing GitHub repository file %s/%s/%s", owner, repo, file)
tflog.Debug(ctx, "Missing GitHub repository file", map[string]any{
"owner": owner,
"repo": repo,
"file": file,
})
d.SetId("")
return nil
}
Expand Down Expand Up @@ -145,12 +154,21 @@ func dataSourceGithubRepositoryFileRead(ctx context.Context, d *schema.ResourceD
})
}

log.Printf("[DEBUG] Data Source fetching commit info for repository file: %s/%s/%s", owner, repo, file)
tflog.Debug(ctx, "Data Source fetching commit info for repository file", map[string]any{
"owner": owner,
"repo": repo,
"file": file,
})
commit, err := getFileCommit(ctx, client, owner, repo, file, ref)
if err != nil {
return diag.FromErr(err)
}
log.Printf("[DEBUG] Found file: %s/%s/%s, in commit SHA: %s ", owner, repo, file, commit.GetSHA())
tflog.Debug(ctx, "Found file, in commit SHA", map[string]any{
"owner": owner,
"repo": repo,
"file": file,
"sha": commit.GetSHA(),
})

if err = d.Set("commit_sha", commit.GetSHA()); err != nil {
return diag.FromErr(err)
Expand Down