mirror of
https://github.com/strongdm/comply
synced 2024-11-22 07:34:54 +00:00
getGitApprovalInfo early exit if approvedBranch unspecified.
go fmt.
This commit is contained in:
parent
c5868fa544
commit
2e9f6cf270
@ -11,10 +11,11 @@ import (
|
|||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"os/exec"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/strongdm/comply/internal/config"
|
"github.com/strongdm/comply/internal/config"
|
||||||
"github.com/strongdm/comply/internal/model"
|
"github.com/strongdm/comply/internal/model"
|
||||||
"os/exec"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: refactor and eliminate duplication among narrative, policy renderers
|
// TODO: refactor and eliminate duplication among narrative, policy renderers
|
||||||
@ -57,8 +58,13 @@ func renderToFilesystem(wg *sync.WaitGroup, errOutputCh chan error, data *render
|
|||||||
func getGitApprovalInfo(pol *model.Document) (string, error) {
|
func getGitApprovalInfo(pol *model.Document) (string, error) {
|
||||||
cfg := config.Config()
|
cfg := config.Config()
|
||||||
|
|
||||||
|
// if no approved branch specified in config.yaml, then nothing gets added to the document
|
||||||
|
if cfg.ApprovedBranch == "" {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
// Decide whether we are on the git branch that contains the approved policies
|
// Decide whether we are on the git branch that contains the approved policies
|
||||||
gitBranchArgs := []string{"rev-parse","--abbrev-ref", "HEAD"}
|
gitBranchArgs := []string{"rev-parse", "--abbrev-ref", "HEAD"}
|
||||||
gitBranchCmd := exec.Command("git", gitBranchArgs...)
|
gitBranchCmd := exec.Command("git", gitBranchArgs...)
|
||||||
gitBranchInfo, err := gitBranchCmd.CombinedOutput()
|
gitBranchInfo, err := gitBranchCmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -66,9 +72,8 @@ func getGitApprovalInfo(pol *model.Document) (string, error) {
|
|||||||
return "", errors.Wrap(err, "error looking up git branch")
|
return "", errors.Wrap(err, "error looking up git branch")
|
||||||
}
|
}
|
||||||
|
|
||||||
// if no approved branch specified in config.yaml, then nothing gets added to the document
|
|
||||||
// if on a different branch than the approved branch, then nothing gets added to the document
|
// if on a different branch than the approved branch, then nothing gets added to the document
|
||||||
if len(cfg.ApprovedBranch) == 0 || strings.Compare(strings.TrimSpace(fmt.Sprintf("%s",gitBranchInfo)), cfg.ApprovedBranch ) != 0 {
|
if strings.Compare(strings.TrimSpace(fmt.Sprintf("%s", gitBranchInfo)), cfg.ApprovedBranch) != 0 {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +130,6 @@ func preprocessDoc(data *renderData, pol *model.Document, fullPath string) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
doc := fmt.Sprintf(`%% %s
|
doc := fmt.Sprintf(`%% %s
|
||||||
%% %s
|
%% %s
|
||||||
%% %s
|
%% %s
|
||||||
|
Loading…
Reference in New Issue
Block a user