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,14 +72,13 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
// Grab information related to commit, so that we can put approval information in the document
|
// Grab information related to commit, so that we can put approval information in the document
|
||||||
gitArgs := []string{"log", "-n", "1", "--pretty=format:Last edit made by %an (%aE) on %aD.\n\nApproved by %cn (%cE) on %cD in commit %H.", "--", pol.FullPath}
|
gitArgs := []string{"log", "-n", "1", "--pretty=format:Last edit made by %an (%aE) on %aD.\n\nApproved by %cn (%cE) on %cD in commit %H.", "--", pol.FullPath}
|
||||||
cmd := exec.Command("git", gitArgs...)
|
cmd := exec.Command("git", gitArgs...)
|
||||||
gitApprovalInfo, err := cmd.CombinedOutput()
|
gitApprovalInfo, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -81,7 +86,7 @@ func getGitApprovalInfo(pol *model.Document) (string, error) {
|
|||||||
return "", errors.Wrap(err, "error looking up git committer and author data")
|
return "", errors.Wrap(err, "error looking up git committer and author data")
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("%s\n%s", "# Authorship and Approval", gitApprovalInfo), nil
|
return fmt.Sprintf("%s\n%s", "# Authorship and Approval", gitApprovalInfo), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func preprocessDoc(data *renderData, pol *model.Document, fullPath string) error {
|
func preprocessDoc(data *renderData, pol *model.Document, fullPath string) error {
|
||||||
@ -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