...

Source file src/edge-infra.dev/pkg/f8n/devinfra/jack/logger/log.go

Documentation: edge-infra.dev/pkg/f8n/devinfra/jack/logger

     1  package logger
     2  
     3  import (
     4  	"edge-infra.dev/pkg/lib/logging"
     5  
     6  	"github.com/google/go-github/v47/github"
     7  )
     8  
     9  const (
    10  	LogKeyEventType       string = "github_event_type"
    11  	LogKeyDeliveryID      string = "github_delivery_id"
    12  	LogKeyRepositoryName  string = "github_repository_name"
    13  	LogKeyRepositoryOwner string = "github_repository_owner"
    14  	LogKeyIssueNumber     string = "github_issue_number"
    15  	LogKeyPRNumber        string = "github_pr_number"
    16  	LogKeyInstallationID  string = "github_installation_id"
    17  )
    18  
    19  func PrepareRepoContext() logging.EdgeLogger {
    20  	log := *logging.NewLogger()
    21  
    22  	// log = attachInstallationLogKeys(log, installationID)
    23  	// log = attachRepoLogKeys(log, repo)
    24  
    25  	return log
    26  }
    27  
    28  func PreparePushContext(installationID int64, repo *github.PushEventRepository) logging.EdgeLogger {
    29  	log := *logging.NewLogger()
    30  
    31  	log = attachInstallationLogKeys(log, installationID)
    32  	log = attachPushRepoLogKeys(log, repo)
    33  
    34  	return log
    35  }
    36  
    37  func PrepareStatusContext(installationID int64, repo *github.Repository) logging.EdgeLogger {
    38  	log := *logging.NewLogger()
    39  
    40  	log = attachInstallationLogKeys(log, installationID)
    41  	log = attachRepoLogKeys(log, repo)
    42  
    43  	return log
    44  }
    45  
    46  func PrepareIssueContext(installationID int64, repo *github.Repository) logging.EdgeLogger {
    47  	log := *logging.NewLogger()
    48  
    49  	log = attachInstallationLogKeys(log, installationID)
    50  	log = attachRepoLogKeys(log, repo)
    51  
    52  	return log
    53  }
    54  
    55  func PreparePullRequestContext(installationID int64, pr *github.PullRequest, repo *github.Repository) logging.EdgeLogger {
    56  	log := *logging.NewLogger()
    57  
    58  	log = attachInstallationLogKeys(log, installationID)
    59  	log = attachRepoLogKeys(log, repo)
    60  
    61  	log = attachPullRequestLogKeys(log, pr.GetNumber())
    62  
    63  	return log
    64  }
    65  
    66  func attachInstallationLogKeys(log logging.EdgeLogger, installID int64) logging.EdgeLogger {
    67  	if installID > 0 {
    68  		return *log.WithValues(LogKeyInstallationID, installID)
    69  	}
    70  	return log
    71  }
    72  
    73  func attachRepoLogKeys(log logging.EdgeLogger, repo *github.Repository) logging.EdgeLogger {
    74  	if repo != nil {
    75  		return *log.WithValues(LogKeyRepositoryOwner, repo.GetOwner().GetLogin(), LogKeyRepositoryName, repo.GetName())
    76  	}
    77  	return log
    78  }
    79  
    80  func attachPushRepoLogKeys(log logging.EdgeLogger, repo *github.PushEventRepository) logging.EdgeLogger {
    81  	if repo != nil {
    82  		return *log.WithValues(LogKeyRepositoryOwner, repo.GetOwner().GetLogin(), LogKeyRepositoryName, repo.GetName())
    83  	}
    84  	return log
    85  }
    86  
    87  //func attachIssueNumberLogKeys(log logging.EdgeLogger, number int) logging.EdgeLogger {
    88  //	if number > 0 {
    89  //		return *log.WithValues(LogKeyIssueNumber, number)
    90  //	}
    91  //	return log
    92  //}
    93  
    94  func attachPullRequestLogKeys(log logging.EdgeLogger, number int) logging.EdgeLogger {
    95  	if number > 0 {
    96  		return *log.WithValues(LogKeyPRNumber, number)
    97  	}
    98  	return log
    99  }
   100  

View as plain text