forked from SAP/jenkins-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransportRequestReqIDFromGit.go
52 lines (39 loc) · 1.54 KB
/
transportRequestReqIDFromGit.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
package cmd
import (
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/telemetry"
"github.com/SAP/jenkins-library/pkg/transportrequest"
)
// mocking framework. Allows to redirect the containing methods
type gitIDInRangeFinder interface {
FindIDInRange(label, from, to string) (string, error)
}
type gitIDInRange struct {
}
func (*gitIDInRange) FindIDInRange(label, from, to string) (string, error) {
return transportrequest.FindIDInRange(label, from, to)
}
func transportRequestReqIDFromGit(config transportRequestReqIDFromGitOptions,
telemetryData *telemetry.CustomData,
commonPipelineEnvironment *transportRequestReqIDFromGitCommonPipelineEnvironment) {
err := runTransportRequestReqIDFromGit(&config, telemetryData, &gitIDInRange{}, commonPipelineEnvironment)
if err != nil {
log.Entry().WithError(err).Fatal("step execution failed")
}
}
func runTransportRequestReqIDFromGit(config *transportRequestReqIDFromGitOptions,
telemetryData *telemetry.CustomData,
trUtils gitIDInRangeFinder,
commonPipelineEnvironment *transportRequestReqIDFromGitCommonPipelineEnvironment) error {
trID, err := getTransportRequestID(config, trUtils)
if err != nil {
return err
}
commonPipelineEnvironment.custom.transportRequestID = trID
log.Entry().Infof("Retrieved transport request ID '%s' from Git.", trID)
return nil
}
func getTransportRequestID(config *transportRequestReqIDFromGitOptions,
trUtils gitIDInRangeFinder) (string, error) {
return trUtils.FindIDInRange(config.TransportRequestLabel, config.GitFrom, config.GitTo)
}