lunemec/nanny

View on GitHub

Showing 25 of 25 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

func (w *webhookNotifier) Notify(msg Message) error {
    postBody, _ := json.Marshal(map[string]interface{}{
        "message": msg.Format(),
        "meta":    msg.Meta,
    })
Severity: Major
Found in pkg/notifier/webhook.go and 1 other location - About 3 hrs to fix
pkg/notifier/webhook.go on lines 89..113

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 288.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

func (w *webhookNotifier) NotifyAllClear(msg Message) error {
    postBody, _ := json.Marshal(map[string]interface{}{
        "message": msg.FormatAllClear(),
        "meta":    msg.Meta,
    })
Severity: Major
Found in pkg/notifier/webhook.go and 1 other location - About 3 hrs to fix
pkg/notifier/webhook.go on lines 62..86

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 288.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

func (s *slackNotifier) Notify(msg Message) error {
    msgText := msg.Format()
    hexRed := "#FF0000"
    attachment := slack.Attachment{
        Fallback: &msgText,
Severity: Major
Found in pkg/notifier/slack.go and 1 other location - About 3 hrs to fix
pkg/notifier/slack.go on lines 58..85

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 258.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

func (s *slackNotifier) NotifyAllClear(msg Message) error {
    msgText := msg.FormatAllClear()
    hexGreen := "#00FF00"
    attachment := slack.Attachment{
        Fallback: &msgText,
Severity: Major
Found in pkg/notifier/slack.go and 1 other location - About 3 hrs to fix
pkg/notifier/slack.go on lines 28..55

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 258.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

func (x *xmppNotifier) Notify(msg Message) error {
    options := xmpp.Options{
        Host:     x.Server + ":" + strconv.Itoa(x.Port),
        User:     x.User,
        Password: x.Password,
Severity: Major
Found in pkg/notifier/xmpp.go and 1 other location - About 2 hrs to fix
pkg/notifier/xmpp.go on lines 80..105

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 237.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

func (x *xmppNotifier) NotifyAllClear(msg Message) error {
    options := xmpp.Options{
        Host:     x.Server + ":" + strconv.Itoa(x.Port),
        User:     x.User,
        Password: x.Password,
Severity: Major
Found in pkg/notifier/xmpp.go and 1 other location - About 2 hrs to fix
pkg/notifier/xmpp.go on lines 52..77

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 237.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

func (n *Email) NotifyAllClear(msg Message) error {
    m := gomail.NewMessage()
    m.SetHeader("From", n.From)
    m.SetHeader("To", n.To...)
    m.SetHeader("Subject", fmt.Sprintf(n.SubjectAllClear, msg.Program))
Severity: Major
Found in pkg/notifier/email.go and 1 other location - About 2 hrs to fix
pkg/notifier/email.go on lines 27..40

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 191.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

func (n *Email) Notify(msg Message) error {
    m := gomail.NewMessage()
    m.SetHeader("From", n.From)
    m.SetHeader("To", n.To...)
    m.SetHeader("Subject", fmt.Sprintf(n.Subject, msg.Program))
Severity: Major
Found in pkg/notifier/email.go and 1 other location - About 2 hrs to fix
pkg/notifier/email.go on lines 42..55

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 191.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

func (n *twilio) Notify(msg Message) error {
    resp, exc, err := n.t.SendSMS(n.from, n.to, msg.Format(), "", n.appSid)
    if err != nil {
        return errors.Wrap(err, "unable to send SMS via twilio")
    }
Severity: Major
Found in pkg/notifier/twilio.go and 1 other location - About 1 hr to fix
pkg/notifier/twilio.go on lines 46..63

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 183.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

func (n *twilio) NotifyAllClear(msg Message) error {
    resp, exc, err := n.t.SendSMS(n.from, n.to, msg.FormatAllClear(), "", n.appSid)
    if err != nil {
        return errors.Wrap(err, "unable to send SMS via twilio")
    }
Severity: Major
Found in pkg/notifier/twilio.go and 1 other location - About 1 hr to fix
pkg/notifier/twilio.go on lines 26..43

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 183.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function makeNotifiers has 69 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func makeNotifiers() (map[string]notifier.Notifier, error) {
    notifiers := make(map[string]notifier.Notifier)
    if config.Stderr.Enabled {
        notifiers["stderr"] = &notifier.StdErr{}
    }
Severity: Minor
Found in cmd/root.go - About 1 hr to fix

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    func (nt *Timer) notifyAllClear() error {
        nt.lock.Lock()
        defer nt.lock.Unlock()
        name := "Nanny"
        if nt.nanny.Name != "" {
    Severity: Major
    Found in pkg/nanny/timer.go and 1 other location - About 1 hr to fix
    pkg/nanny/timer.go on lines 103..117

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 158.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    func (nt *Timer) notify() error {
        nt.lock.Lock()
        defer nt.lock.Unlock()
        name := "Nanny"
        if nt.nanny.Name != "" {
    Severity: Major
    Found in pkg/nanny/timer.go and 1 other location - About 1 hr to fix
    pkg/nanny/timer.go on lines 119..133

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 158.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Function main has 58 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func main() {
        http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
            webhookSecret := ""
    
            if r.Method != http.MethodPost {
    Severity: Minor
    Found in receiver_examples/webhook_receiver_example.go - About 1 hr to fix

      Function NewXmpp has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      func NewXmpp(To []string,
          Server string,
          Port int,
          User string,
          Password string,
      Severity: Major
      Found in pkg/notifier/xmpp.go - About 50 mins to fix

        Function main has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
        Open

        func main() {
            http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
                webhookSecret := ""
        
                if r.Method != http.MethodPost {
        Severity: Minor
        Found in receiver_examples/webhook_receiver_example.go - About 45 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function main has 7 return statements (exceeds 4 allowed).
        Open

        func main() {
            http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
                webhookSecret := ""
        
                if r.Method != http.MethodPost {
        Severity: Major
        Found in receiver_examples/webhook_receiver_example.go - About 45 mins to fix

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

          func (n *StdErr) Notify(msg Message) error {
              text := fmt.Sprintf("%s: %s (Meta: %v)\n", time.Now().Format(time.RFC3339), msg.Format(), msg.Meta)
              _, err := os.Stderr.WriteString(text)
              return errors.Wrap(err, "unable to notify via stderr")
          }
          Severity: Minor
          Found in pkg/notifier/stderr.go and 1 other location - About 40 mins to fix
          pkg/notifier/stderr.go on lines 22..26

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 110.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

          func (n *StdErr) NotifyAllClear(msg Message) error {
              text := fmt.Sprintf("%s: %s (Meta: %v)\n", time.Now().Format(time.RFC3339), msg.FormatAllClear(), msg.Meta)
              _, err := os.Stderr.WriteString(text)
              return errors.Wrap(err, "unable to notify via stderr")
          }
          Severity: Minor
          Found in pkg/notifier/stderr.go and 1 other location - About 40 mins to fix
          pkg/notifier/stderr.go on lines 15..19

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 110.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Function getSignalsHandler has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          func getSignalsHandler(n *nanny.Nanny, notifiers notifiers, store storage.Storage, w http.ResponseWriter, req *http.Request) error {
          Severity: Minor
          Found in api/api.go - About 35 mins to fix
            Severity
            Category
            Status
            Source
            Language