Skip to content

Commit 6720d44

Browse files
committed
[add] Using default git data if not provided via flags
1 parent 83e2872 commit 6720d44

File tree

650 files changed

+108
-288168
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

650 files changed

+108
-288168
lines changed

Makefile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ all: dist hash
2121
gofmt:
2222
@test -z $(shell gofmt -l -s $(SOURCE_DIRS) ./ | tee /dev/stderr) || (echo "[WARN] Fix formatting issues with 'make fmt'" && exit 1)
2323

24+
build:
25+
$(GOCMD) build .
26+
2427
fmt:
2528
$(GOFMT) ./...
2629

@@ -32,11 +35,11 @@ lint:
3235
dist:
3336
mkdir -p bin/
3437
rm -rf bin/pprof-exporter*
35-
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -mod=vendor -a -ldflags $(LDFLAGS) -installsuffix cgo -o bin/pprof-exporter
36-
CGO_ENABLED=0 GOARCH=amd64 GOOS=darwin go build -mod=vendor -a -ldflags $(LDFLAGS) -installsuffix cgo -o bin/pprof-exporter-darwin
37-
GOARM=6 GOARCH=arm CGO_ENABLED=0 GOOS=linux go build -mod=vendor -a -ldflags $(LDFLAGS) -installsuffix cgo -o bin/pprof-exporter-armhf
38-
GOARCH=arm64 CGO_ENABLED=0 GOOS=linux go build -mod=vendor -a -ldflags $(LDFLAGS) -installsuffix cgo -o bin/pprof-exporter-arm64
39-
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -mod=vendor -a -ldflags $(LDFLAGS) -installsuffix cgo -o bin/pprof-exporter.exe
38+
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -a -ldflags $(LDFLAGS) -installsuffix cgo -o bin/pprof-exporter
39+
CGO_ENABLED=0 GOARCH=amd64 GOOS=darwin go build -a -ldflags $(LDFLAGS) -installsuffix cgo -o bin/pprof-exporter-darwin
40+
GOARM=6 GOARCH=arm CGO_ENABLED=0 GOOS=linux go build -a -ldflags $(LDFLAGS) -installsuffix cgo -o bin/pprof-exporter-armhf
41+
GOARCH=arm64 CGO_ENABLED=0 GOOS=linux go build -a -ldflags $(LDFLAGS) -installsuffix cgo -o bin/pprof-exporter-arm64
42+
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -a -ldflags $(LDFLAGS) -installsuffix cgo -o bin/pprof-exporter.exe
4043

4144
.PHONY: hash
4245
hash:

cmd/export.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func exportLogic() func(cmd *cobra.Command, args []string) {
5959
log.Fatal(err)
6060
}
6161
}
62-
log.Printf("Successfully published profile data. Check it at: %s/#/gh/%s/%s/commit/%s/bench/%s/cpu", codeperfUrl, gitOrg, gitRepo, gitCommit, bench)
62+
log.Printf("Successfully published profile data. Check it at: %s/gh/%s/%s/commit/%s/bench/%s/cpu", codeperfUrl, gitOrg, gitRepo, gitCommit, bench)
6363
}
6464

6565
}

cmd/root.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ package cmd
1717

1818
import (
1919
"fmt"
20+
"github.com/go-git/go-git/v5"
21+
"log"
22+
"strings"
2023

2124
"github.com/spf13/cobra"
2225
"os"
@@ -57,6 +60,27 @@ func Execute() {
5760

5861
func init() {
5962
cobra.OnInitialize(initConfig)
63+
defaultGitOrg := ""
64+
defaultGitRepo := ""
65+
defaultGitCommit := ""
66+
67+
r, err := git.PlainOpen(".")
68+
if err != nil {
69+
log.Println("Unable to retrieve current repo git info. Use the --git-org, --git-repo, and --git-hash to properly fill the git info.")
70+
} else {
71+
ref, _ := r.Head()
72+
refHash := ref.Hash().String()
73+
remotes, _ := r.Remotes()
74+
remoteUsed := remotes[0].Config().URLs[0]
75+
fmt.Println(remoteUsed)
76+
toOrg := remoteUsed[:strings.LastIndex(remoteUsed, "/")]
77+
fmt.Println(toOrg)
78+
defaultGitOrg = toOrg[strings.LastIndexAny(toOrg, "/:")+1:]
79+
repoStartPos := strings.LastIndex(remoteUsed, "/") + 1
80+
defaultGitRepo = remoteUsed[repoStartPos : len(remoteUsed)-4]
81+
defaultGitCommit = refHash
82+
log.Printf("Using the following default git vars org=%s repo=%s hash=%s", defaultGitOrg, defaultGitRepo, defaultGitCommit)
83+
}
6084

6185
// Here you will define your flags and configuration settings.
6286
// Cobra supports persistent flags, which, if defined here,
@@ -65,9 +89,9 @@ func init() {
6589
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.pprof-exporter.yaml)")
6690
rootCmd.PersistentFlags().BoolVar(&local, "local", false, "don't push the data to https://codeperf.io")
6791
rootCmd.PersistentFlags().StringVar(&bench, "bench", "", "Benchmark name")
68-
rootCmd.PersistentFlags().StringVar(&gitOrg, "git-org", "", "git org")
69-
rootCmd.PersistentFlags().StringVar(&gitRepo, "git-repo", "", "git repo")
70-
rootCmd.PersistentFlags().StringVar(&gitCommit, "git-commit", "", "git commit hash")
92+
rootCmd.PersistentFlags().StringVar(&gitOrg, "git-org", defaultGitOrg, "git org")
93+
rootCmd.PersistentFlags().StringVar(&gitRepo, "git-repo", defaultGitRepo, "git repo")
94+
rootCmd.PersistentFlags().StringVar(&gitCommit, "git-hash", defaultGitCommit, "git commit hash")
7195
rootCmd.PersistentFlags().StringVar(&localFilename, "local-filename", "profile.json", "Local file to export the json to. Only used when the --local flag is set")
7296
rootCmd.PersistentFlags().StringVar(&codeperfUrl, "codeperf-url", "https://codeperf.io", "codeperf URL")
7397
rootCmd.MarkPersistentFlagRequired("bench")

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ module github.com/codeperfio/pprof-exporter
33
go 1.16
44

55
require (
6+
github.com/go-git/go-git/v5 v5.4.2
67
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1
8+
github.com/sergi/go-diff v1.2.0 // indirect
79
github.com/spf13/cobra v1.2.1
810
github.com/spf13/viper v1.9.0
911
)

0 commit comments

Comments
 (0)