1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/cmd/transportRequestReqIDFromGit.go
Roland Stengel 02dd60c0c8
Split git commit message scan from solman upload (#2773)
* Split git commit message scan from solman upload
2021-05-21 08:54:43 +02:00

53 lines
1.5 KiB
Go

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)
}