-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocal_state.go
94 lines (74 loc) · 1.83 KB
/
local_state.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package simver
import (
"context"
"gitlab.com/tozd/go/errors"
)
var _ Execution = &LocalProjectState{}
type LocalProjectState struct {
Commit string
Branch string
Tags Tags
Dirty bool
}
func NewLocalProjectState(ctx context.Context, gp GitProvider, tr TagReader) (Execution, error) {
commit, err := gp.GetHeadRef(ctx)
if err != nil {
return nil, errors.Errorf("getting parent commit: %w", err)
}
branch, err := gp.Branch(ctx)
if err != nil {
return nil, errors.Errorf("getting branch: %w", err)
}
tags, err := tr.TagsFromBranch(ctx, branch)
if err != nil {
return nil, errors.Errorf("getting tags from branch: %w", err)
}
dirty, err := gp.Dirty(ctx)
if err != nil {
return nil, errors.Errorf("getting dirty: %w", err)
}
return &LocalProjectState{
Commit: commit,
Branch: branch,
Tags: tags,
Dirty: dirty,
}, nil
}
// BaseBranchTags implements Execution.
func (me *LocalProjectState) BaseBranchTags() Tags {
return me.Tags
}
// HeadBranchTags implements Execution.
func (me *LocalProjectState) HeadBranchTags() Tags {
return me.Tags
}
// HeadCommitTags implements Execution.
func (*LocalProjectState) HeadCommitTags() Tags {
return []Tag{}
}
// IsMerge implements Execution.
func (*LocalProjectState) IsMerge() bool {
return false
}
// IsTargetingRoot implements Execution.
func (me *LocalProjectState) IsTargetingRoot() bool {
return me.Branch == "main"
}
// PR implements Execution.
func (*LocalProjectState) PR() int {
return -1
}
// ProvideRefs implements Execution.
func (me *LocalProjectState) ProvideRefs() RefProvider {
return &SingleRefProvider{Ref: me.Commit}
}
// RootBranchTags implements Execution.
func (*LocalProjectState) RootBranchTags() Tags {
return []Tag{}
}
func (me *LocalProjectState) IsDirty() bool {
return me.Dirty
}
func (me *LocalProjectState) IsLocal() bool {
return true
}