mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
* feat: add posthog analytics events * Update internal/analytics/analytics.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Sahil Bansal <bansalsahil315@gmail.com> --------- Signed-off-by: Sahil Bansal <bansalsahil315@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package analytics
|
|
|
|
import "os"
|
|
|
|
type environmentType string
|
|
|
|
const (
|
|
environmentTypeGitHubActions environmentType = "github_actions"
|
|
environmentTypeGitLabCI environmentType = "gitlab_ci"
|
|
environmentTypeDocker environmentType = "docker"
|
|
)
|
|
|
|
// Map of environment variables which if set will determine environments
|
|
var ciEnvVars = map[string]environmentType{
|
|
"GITHUB_ACTION": environmentTypeGitHubActions,
|
|
"GITHUB_WORKFLOW": environmentTypeGitHubActions,
|
|
"GITLAB_CI": environmentTypeGitLabCI,
|
|
"CI_COMMIT_BRANCH": environmentTypeGitLabCI,
|
|
}
|
|
|
|
func TrackCI() {
|
|
uniqueTypes := make(map[environmentType]bool)
|
|
for envVar, envVarType := range ciEnvVars {
|
|
if os.Getenv(envVar) != "" {
|
|
uniqueTypes[envVarType] = true
|
|
}
|
|
}
|
|
|
|
for envVarType := range uniqueTypes {
|
|
trackCiEvent(envVarType)
|
|
}
|
|
}
|
|
|
|
func trackCiEvent(envVarType environmentType) {
|
|
switch envVarType {
|
|
case environmentTypeGitHubActions:
|
|
TrackCommandGenerateEnvGitHubActions()
|
|
case environmentTypeGitLabCI:
|
|
TrackCommandGenerateEnvGitLabCI()
|
|
case environmentTypeDocker:
|
|
TrackCommandGenerateEnvDocker()
|
|
}
|
|
}
|