Code Duplication    Length = 24-26 lines in 2 locations

ecs_deploy/slack.py 2 locations

@@ 105-130 (lines=26) @@
102
        if response.status_code != 200:
103
            raise SlackException('Notifying deployment failed')
104
105
    def notify_failure(self, cluster, error, service=None, rule=None):
106
        if not self.__url or not self.__service_match_re.search(service or rule):
107
            return
108
109
        duration = datetime.utcnow() - self.__timestamp_start
110
111
        messages = [
112
            ('Cluster', cluster),
113
        ]
114
115
        if service:
116
            messages.append(('Service', service))
117
        if rule:
118
            messages.append(('Scheduled Task', rule))
119
120
        messages.append(('Duration', str(duration)))
121
        messages.append(('Error', error))
122
123
        payload = self.get_payload('Deployment failed', messages, 'danger')
124
125
        response = requests.post(self.__url, json=payload)
126
127
        if response.status_code != 200:
128
            raise SlackException('Notifying deployment failed')
129
130
        return response
131
@@ 80-103 (lines=24) @@
77
78
        return response
79
80
    def notify_success(self, cluster, revision, service=None, rule=None):
81
        if not self.__url or not self.__service_match_re.search(service or rule):
82
            return
83
84
        duration = datetime.utcnow() - self.__timestamp_start
85
86
        messages = [
87
            ('Cluster', cluster),
88
        ]
89
90
        if service:
91
            messages.append(('Service', service))
92
        if rule:
93
            messages.append(('Scheduled Task', rule))
94
95
        messages.append(('Revision', revision))
96
        messages.append(('Duration', str(duration)))
97
98
        payload = self.get_payload('Deployment finished successfully', messages, 'good')
99
100
        response = requests.post(self.__url, json=payload)
101
102
        if response.status_code != 200:
103
            raise SlackException('Notifying deployment failed')
104
105
    def notify_failure(self, cluster, error, service=None, rule=None):
106
        if not self.__url or not self.__service_match_re.search(service or rule):