forked from edgexfoundry/git-semver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscope.go
72 lines (59 loc) · 1.59 KB
/
scope.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright (c) 2019 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
// Package scope encapsulates ambit of the git-semver functionality.
package scope
import (
"io/ioutil"
golog "log"
"os"
"strconv"
"strings"
"github.com/blang/semver"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/storage/filesystem"
)
var (
log = golog.New(ioutil.Discard, "", 0)
)
func init() {
if s, ok := os.LookupEnv("SEMVER_DEBUG"); ok {
if b, _ := strconv.ParseBool(s); b || strings.ToLower(s) == "on" {
log.SetOutput(os.Stderr)
}
}
}
var (
// RemoteName is the name of the remote that this tooling should work with.
RemoteName = GetEnv("SEMVER_REMOTE_NAME", git.DefaultRemoteName)
// PrePrefix is the default value for the pre-axis.
PrePrefix = GetEnv("SEMVER_PRE_PREFIX", "pre")
// UserEmail is the value for the git config user.email in the local semver repository.
UserEmail = GetEnv("SEMVER_USER_EMAIL",
GetEnv("GIT_AUTHOR_EMAIL",
),
)
// UserName is the value for the git config user.name in the local semver repository.
UserName = GetEnv("SEMVER_USER_NAME",
GetEnv("GIT_AUTHOR_NAME",
GetEnv("GIT_COMMITTER_NAME", "semver"),
),
)
)
// Extent is an Open()'ed GIT repository.
type Extent struct {
Store *filesystem.Storage
Repo *git.Repository
Tree *git.Worktree
Branch string
}
// Version type alias
type Version = semver.Version
// GetEnv attempt os.LookupEnv returning the default if the key is not found.
func GetEnv(key, def string) string {
if val, ok := os.LookupEnv(key); ok {
return val
}
return def
}