1
0
mirror of https://github.com/strongdm/comply synced 2024-07-02 23:14:22 +00:00

getGitApprovalInfo early exit if approvedBranch unspecified.

go fmt.
This commit is contained in:
Justin McCarthy 2018-08-29 15:47:02 -07:00
parent c5868fa544
commit 2e9f6cf270
No known key found for this signature in database
GPG Key ID: 900437410E142A48

View File

@ -11,10 +11,11 @@ import (
"text/template"
"time"
"os/exec"
"github.com/pkg/errors"
"github.com/strongdm/comply/internal/config"
"github.com/strongdm/comply/internal/model"
"os/exec"
)
// TODO: refactor and eliminate duplication among narrative, policy renderers
@ -57,6 +58,11 @@ func renderToFilesystem(wg *sync.WaitGroup, errOutputCh chan error, data *render
func getGitApprovalInfo(pol *model.Document) (string, error) {
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
gitBranchArgs := []string{"rev-parse", "--abbrev-ref", "HEAD"}
gitBranchCmd := exec.Command("git", gitBranchArgs...)
@ -66,9 +72,8 @@ func getGitApprovalInfo(pol *model.Document) (string, error) {
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 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
}
@ -125,7 +130,6 @@ func preprocessDoc(data *renderData, pol *model.Document, fullPath string) error
return err
}
doc := fmt.Sprintf(`%% %s
%% %s
%% %s