package logger import ( "edge-infra.dev/pkg/lib/logging" "github.com/google/go-github/v47/github" ) const ( LogKeyEventType string = "github_event_type" LogKeyDeliveryID string = "github_delivery_id" LogKeyRepositoryName string = "github_repository_name" LogKeyRepositoryOwner string = "github_repository_owner" LogKeyIssueNumber string = "github_issue_number" LogKeyPRNumber string = "github_pr_number" LogKeyInstallationID string = "github_installation_id" ) func PrepareRepoContext() logging.EdgeLogger { log := *logging.NewLogger() // log = attachInstallationLogKeys(log, installationID) // log = attachRepoLogKeys(log, repo) return log } func PreparePushContext(installationID int64, repo *github.PushEventRepository) logging.EdgeLogger { log := *logging.NewLogger() log = attachInstallationLogKeys(log, installationID) log = attachPushRepoLogKeys(log, repo) return log } func PrepareStatusContext(installationID int64, repo *github.Repository) logging.EdgeLogger { log := *logging.NewLogger() log = attachInstallationLogKeys(log, installationID) log = attachRepoLogKeys(log, repo) return log } func PrepareIssueContext(installationID int64, repo *github.Repository) logging.EdgeLogger { log := *logging.NewLogger() log = attachInstallationLogKeys(log, installationID) log = attachRepoLogKeys(log, repo) return log } func PreparePullRequestContext(installationID int64, pr *github.PullRequest, repo *github.Repository) logging.EdgeLogger { log := *logging.NewLogger() log = attachInstallationLogKeys(log, installationID) log = attachRepoLogKeys(log, repo) log = attachPullRequestLogKeys(log, pr.GetNumber()) return log } func attachInstallationLogKeys(log logging.EdgeLogger, installID int64) logging.EdgeLogger { if installID > 0 { return *log.WithValues(LogKeyInstallationID, installID) } return log } func attachRepoLogKeys(log logging.EdgeLogger, repo *github.Repository) logging.EdgeLogger { if repo != nil { return *log.WithValues(LogKeyRepositoryOwner, repo.GetOwner().GetLogin(), LogKeyRepositoryName, repo.GetName()) } return log } func attachPushRepoLogKeys(log logging.EdgeLogger, repo *github.PushEventRepository) logging.EdgeLogger { if repo != nil { return *log.WithValues(LogKeyRepositoryOwner, repo.GetOwner().GetLogin(), LogKeyRepositoryName, repo.GetName()) } return log } //func attachIssueNumberLogKeys(log logging.EdgeLogger, number int) logging.EdgeLogger { // if number > 0 { // return *log.WithValues(LogKeyIssueNumber, number) // } // return log //} func attachPullRequestLogKeys(log logging.EdgeLogger, number int) logging.EdgeLogger { if number > 0 { return *log.WithValues(LogKeyPRNumber, number) } return log }