Files
pmg/internal/analytics/ci.go
0e17378d3e feat: add posthog analytics support (#52)
* 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>
2025-06-30 09:47:14 +05:30

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()
}
}