github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/cmd/transportRequestReqIDFromGit.go (about) 1 package cmd 2 3 import ( 4 "github.com/SAP/jenkins-library/pkg/log" 5 "github.com/SAP/jenkins-library/pkg/telemetry" 6 "github.com/SAP/jenkins-library/pkg/transportrequest" 7 ) 8 9 // mocking framework. Allows to redirect the containing methods 10 type gitIDInRangeFinder interface { 11 FindIDInRange(label, from, to string) (string, error) 12 } 13 14 type gitIDInRange struct { 15 } 16 17 func (*gitIDInRange) FindIDInRange(label, from, to string) (string, error) { 18 return transportrequest.FindIDInRange(label, from, to) 19 } 20 21 func transportRequestReqIDFromGit(config transportRequestReqIDFromGitOptions, 22 telemetryData *telemetry.CustomData, 23 commonPipelineEnvironment *transportRequestReqIDFromGitCommonPipelineEnvironment) { 24 25 err := runTransportRequestReqIDFromGit(&config, telemetryData, &gitIDInRange{}, commonPipelineEnvironment) 26 if err != nil { 27 log.Entry().WithError(err).Fatal("step execution failed") 28 } 29 } 30 31 func runTransportRequestReqIDFromGit(config *transportRequestReqIDFromGitOptions, 32 telemetryData *telemetry.CustomData, 33 trUtils gitIDInRangeFinder, 34 commonPipelineEnvironment *transportRequestReqIDFromGitCommonPipelineEnvironment) error { 35 36 trID, err := getTransportRequestID(config, trUtils) 37 if err != nil { 38 return err 39 } 40 41 commonPipelineEnvironment.custom.transportRequestID = trID 42 43 log.Entry().Infof("Retrieved transport request ID '%s' from Git.", trID) 44 45 return nil 46 } 47 48 func getTransportRequestID(config *transportRequestReqIDFromGitOptions, 49 trUtils gitIDInRangeFinder) (string, error) { 50 51 return trUtils.FindIDInRange(config.TransportRequestLabel, config.GitFrom, config.GitTo) 52 }