Skip to content

Commit

Permalink
remove ansi character Error message
Browse files Browse the repository at this point in the history
  • Loading branch information
razzkumar committed Sep 24, 2019
1 parent 71e6f11 commit aa25ded
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
14 changes: 14 additions & 0 deletions deployment/utils/escape/escape.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package escape

import (
"regexp"
)

const ansi = "[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"

var re = regexp.MustCompile(ansi)

// Strip returns the same string by removeing ansi char.
func Strip(str string) string {
return re.ReplaceAllString(str, "")
}
11 changes: 7 additions & 4 deletions deployment/utils/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"os"
"os/exec"

"github.com/leapfrogtechnology/shift/deployment/utils/escape"
)

// Execute runs the process with the supplied environment.
Expand All @@ -21,11 +23,12 @@ func Execute(command string) error {
cmd.Stdout = os.Stdout

err := cmd.Run()

if err != nil {
fmt.Println("ERROR :" + stderr.String())
return errors.New(fmt.Sprint(err) + ":- " + stderr.String())
}
fmt.Println(stderr.String())

errorMessage := escape.Strip(err.Error() + " :- " + stderr.String())

return errors.New(errorMessage)
}
return nil
}
12 changes: 10 additions & 2 deletions deployment/utils/slack/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@ package slack

import (
"fmt"
"strings"

"github.com/leapfrogtechnology/shift/deployment/utils/http"
)

// Notify sends data to slack webhook url
func Notify(url string, text string, color string) {
http.Client.R().

message := strings.Replace(text, "\"", "'", -1)

content := fmt.Sprintf(`{"attachments": [{"text": %q, "color": "%s"}]}`, "@here\n"+message, color)

resp, _ := http.Client.R().
SetHeader("Content-Type", "application/json").
SetBody([]byte(fmt.Sprintf(`{"attachments": [{"text": "%s", "color": "%s"}]}`, text, color))).
SetBody([]byte(content)).
Post(url)

fmt.Println("Slack Hook:- " + resp.String())
}

0 comments on commit aa25ded

Please sign in to comment.