示例#1
0
    def buildMessage(self, name, builds, results):
        patches = []
        logs = []
        body = ""
        subject = None
        msgtype = None
        users = set()
        for build in builds:
            if self.addPatch:
                ss_list = build['buildset']['sourcestamps']

                for ss in ss_list:
                    if 'patch' in ss and ss['patch'] is not None:
                        patches.append(ss['patch'])
            if self.addLogs:
                build_logs = yield self.getLogsForBuild(build)
                logs.extend(build_logs)

            if 'prev_build' in build and build['prev_build'] is not None:
                previous_results = build['prev_build']['results']
            else:
                previous_results = None
            blamelist = yield utils.getResponsibleUsersForBuild(self.master, build['buildid'])
            buildmsg = yield self.messageFormatter.formatMessageForBuildResults(
                self.mode, name, build['buildset'], build, self.master,
                previous_results, blamelist)
            users.update(set(blamelist))
            msgtype = buildmsg['type']
            body += buildmsg['body']
            if 'subject' in buildmsg:
                subject = buildmsg['subject']

        yield self.sendMessage(body, subject, msgtype, name, results, builds,
                               list(users), patches, logs)
示例#2
0
    def buildMessage(self, name, builds, results):
        patches = []
        logs = []
        body = ""
        subject = None
        msgtype = None
        users = set()
        for build in builds:
            if self.addPatch:
                ss_list = build['buildset']['sourcestamps']

                for ss in ss_list:
                    if 'patch' in ss and ss['patch'] is not None:
                        patches.append(ss['patch'])
            if self.addLogs:
                build_logs = yield self.getLogsForBuild(build)
                logs.extend(build_logs)

            if 'prev_build' in build and build['prev_build'] is not None:
                previous_results = build['prev_build']['results']
            else:
                previous_results = None
            blamelist = yield utils.getResponsibleUsersForBuild(
                self.master, build['buildid'])
            buildmsg = yield self.messageFormatter.formatMessageForBuildResults(
                self.mode, name, build['buildset'], build, self.master,
                previous_results, blamelist)
            users.update(set(blamelist))
            msgtype = buildmsg['type']
            body += buildmsg['body']
            if 'subject' in buildmsg:
                subject = buildmsg['subject']

        yield self.sendMessage(body, subject, msgtype, name, results, builds,
                               list(users), patches, logs)
示例#3
0
    def getAttachments(self, build, key):
        sourcestamps = build["buildset"]["sourcestamps"]
        attachments = []

        for sourcestamp in sourcestamps:
            sha = sourcestamp["revision"]

            title = "Build #{buildid}".format(buildid=build["buildid"])
            project = sourcestamp["project"]
            if project:
                title += " for {project} {sha}".format(project=project,
                                                       sha=sha)
            sub_build = bool(build["buildset"]["parent_buildid"])
            if sub_build:
                title += " {relationship}: #{parent_build_id}".format(
                    relationship=build["buildset"]["parent_relationship"],
                    parent_build_id=build["buildset"]["parent_buildid"],
                )

            fields = []
            if not sub_build:
                branch_name = sourcestamp["branch"]
                if branch_name:
                    fields.append({
                        "title": "Branch",
                        "value": branch_name,
                        "short": True
                    })
                repositories = sourcestamp["repository"]
                if repositories:
                    fields.append({
                        "title": "Repository",
                        "value": repositories,
                        "short": True
                    })
                responsible_users = yield utils.getResponsibleUsersForBuild(
                    self.master, build["buildid"])
                if responsible_users:
                    fields.append({
                        "title": "Commiters",
                        "value": ", ".join(responsible_users),
                        "short": True,
                    })
            attachments.append({
                "title":
                title,
                "title_link":
                build["url"],
                "fallback":
                "{}: <{}>".format(title, build["url"]),
                "text":
                "Status: *{status}*".format(
                    status=statusToString(build["results"])),
                "color":
                STATUS_COLORS.get(statusToString(build["results"]), ""),
                "mrkdwn_in": ["text", "title", "fallback"],
                "fields":
                fields,
            })
        return attachments
 def test_getResponsibleUsersForBuildWithOwners(self):
     self.setupDb()
     self.db.insertTestData([
         fakedb.BuildProperty(
             buildid=20, name="owners", value=["him", "her"]),
     ])
     res = yield utils.getResponsibleUsersForBuild(self.master, 20)
     self.assertEqual(sorted(res), sorted(["me@foo", "him", "her"]))
 def test_getResponsibleUsersForBuildWithOwners(self):
     self.setupDb()
     self.db.insertTestData([
         fakedb.BuildProperty(
             buildid=20, name="owners", value=["him", "her"]),
     ])
     res = yield utils.getResponsibleUsersForBuild(self.master, 20)
     self.assertEqual(sorted(res), sorted(["me@foo", "him", "her"]))
 def test_getResponsibleUsersForBuildWithBadOwner(self):
     self.setUpLogging()
     self.setupDb()
     self.db.insertTestData([
         fakedb.BuildProperty(buildid=20, name="owner", value=["him"]),
     ])
     res = yield utils.getResponsibleUsersForBuild(self.master, 20)
     self.assertLogged("Please report a bug")
     self.assertEqual(sorted(res), sorted(["me@foo", "him"]))
 def test_getResponsibleUsersForBuildWithBadOwner(self):
     self.setUpLogging()
     self.setupDb()
     self.db.insertTestData([
         fakedb.BuildProperty(
             buildid=20, name="owner", value=["him"]),
     ])
     res = yield utils.getResponsibleUsersForBuild(self.master, 20)
     self.assertLogged("Please report a bug")
     self.assertEqual(sorted(res), sorted(["me@foo", "him"]))
示例#8
0
    def buildMessage(self, name, builds, results):
        patches = []
        logs = []
        msgdict = {"body": ""}
        users = set()
        for build in builds:
            if self.addPatch:
                ss_list = build['buildset']['sourcestamps']

                for ss in ss_list:
                    if 'patch' in ss and ss['patch'] is not None:
                        patches.append(ss['patch'])
            if self.addLogs:
                build_logs = yield self.getLogsForBuild(build)
                logs.extend(build_logs)

            if 'prev_build' in build and build['prev_build'] is not None:
                previous_results = build['prev_build']['results']
            else:
                previous_results = None
            blamelist = yield utils.getResponsibleUsersForBuild(
                self.master, build['buildid'])
            build_msgdict = self.messageFormatter(self.mode, name,
                                                  build['buildset'], build,
                                                  self.master,
                                                  previous_results, blamelist)
            users.update(set(blamelist))
            msgdict['type'] = build_msgdict['type']
            msgdict['body'] += build_msgdict['body']
            if 'subject' in build_msgdict:
                msgdict['subject'] = build_msgdict['subject']
            # ensure msgbody ends with double cariage return
            if not msgdict['body'].endswith("\n\n"):
                msgdict['body'] += '\n\n'

        m = yield self.createEmail(msgdict, name, self.master.config.title,
                                   results, builds, patches, logs)

        # now, who is this message going to?
        recipients = yield self.findInterrestedUsersEmails(list(users))
        all_recipients = self.processRecipients(recipients, m)
        yield self.sendMessage(m, all_recipients)
示例#9
0
    def getAttachments(self, build, key):
        sourcestamps = build["buildset"]["sourcestamps"]
        attachments = []

        for sourcestamp in sourcestamps:
            title = "<{url}|Build #{buildid}> - *{status}*".format(
                url=build["url"], buildid=build["buildid"], status=statusToString(build["results"])
            )
            
            blocks = []
            blocks.append(
                {
                    "type": "section",
                    "text": {
                        "type": "mrkdwn",
                        "text": title
                    }
                }
            )

            if build["results"] != results.SUCCESS:
                responsible_users = yield utils.getResponsibleUsersForBuild(self.master, build["buildid"])
                if responsible_users:
                    commiters = "*Commiters:*\n{}".format(", ".join(responsible_users))
                    blocks.append(
                        {
                            "type": "section",
                            "text": {
                                "type": "mrkdwn",
                                "text": commiters
                            }
                        }
                    )

            attachments.append(
                {
                    "color": STATUS_COLORS.get(statusToString(build["results"]), ""),
                    "blocks": blocks,
                }
            )
        return attachments
示例#10
0
文件: mail.py 项目: nand0p/buildbot
    def buildMessage(self, name, builds, results):
        patches = []
        logs = []
        msgdict = {"body": ""}
        users = set()
        for build in builds:
            if self.addPatch:
                ss_list = build['buildset']['sourcestamps']

                for ss in ss_list:
                    if 'patch' in ss and ss['patch'] is not None:
                        patches.append(ss['patch'])
            if self.addLogs:
                build_logs = yield self.getLogsForBuild(build)
                logs.extend(build_logs)

            if 'prev_build' in build and build['prev_build'] is not None:
                previous_results = build['prev_build']['results']
            else:
                previous_results = None
            blamelist = yield utils.getResponsibleUsersForBuild(self.master, build['buildid'])
            build_msgdict = yield self.messageFormatter.formatMessageForBuildResults(
                self.mode, name, build['buildset'], build, self.master,
                previous_results, blamelist)
            users.update(set(blamelist))
            msgdict['type'] = build_msgdict['type']
            msgdict['body'] += build_msgdict['body']
            if 'subject' in build_msgdict:
                msgdict['subject'] = build_msgdict['subject']
            # ensure msgbody ends with double cariage return
            if not msgdict['body'].endswith("\n\n"):
                msgdict['body'] += '\n\n'

        m = yield self.createEmail(msgdict, name, self.master.config.title,
                                   results, builds, patches, logs)

        # now, who is this message going to?
        recipients = yield self.findInterrestedUsersEmails(list(users))
        all_recipients = self.processRecipients(recipients, m)
        yield self.sendMessage(m, all_recipients)
 def test_getResponsibleUsersForBuild(self):
     self.setupDb()
     res = yield utils.getResponsibleUsersForBuild(self.master, 20)
     self.assertEqual(sorted(res), sorted(["me@foo", "him"]))
示例#12
0
 def getResponsibleUsersForBuild(self, master, buildid):
     # Use library method but subclassers may want to override that
     return utils.getResponsibleUsersForBuild(master, buildid)
示例#13
0
 def getResponsibleUsersForBuild(self, master, buildid):
     # Use library method but subclassers may want to override that
     return utils.getResponsibleUsersForBuild(master, buildid)
示例#14
0
 def test_getResponsibleUsersForBuild(self):
     self.setupDb()
     res = yield utils.getResponsibleUsersForBuild(self.master, 20)
     self.assertEqual(res, ["me@foo"])
示例#15
0
    def buildFinished(self, key, build):
        yield utils.getDetailsForBuild(self.master,
                                       build,
                                       wantProperties=True,
                                       wantSteps=True,
                                       wantPreviousBuild=False,
                                       wantLogs=False)
        prop = lambda name: build['properties'].get(name, [None])[0]

        build_url = build['url']
        source_stamps = build['buildset']['sourcestamps']
        branch = prop('branch')
        build_name = prop('build_name')
        variant_name = prop('variant_name')
        buildername = prop('buildername')
        if not buildername.startswith('build-'):
            return
        buildername = buildername[len('build-'):]
        buildnumber = prop('buildnumber')
        worker = prop('workername')
        rev = prop('got_revision')
        repository_name = prop('repository_name')
        repository_url = prop('repository_url')
        blamelist = yield utils.getResponsibleUsersForBuild(
            self.master, build['buildid'])
        responsible_users = '\n'.join(blamelist)
        status = Results[build['results']]

        if build['results'] == SUCCESS:
            color = "good"
        elif build['results'] == FAILURE:
            color = "#EE3435"
        else:
            color = '#AB12EF'

        message = "Build <{url}|#{buildnumber} {build_name} {variant_name} on {worker}> finished".format(
            url=build_url,
            buildnumber=buildnumber,
            build_name=build_name,
            variant_name=variant_name,
            worker=worker,
        )

        fields = [{
            'title': 'Status',
            'value': status,
            'short': True,
        }, {
            "title":
            "Repository",
            "value":
            self.templates['repository'].format(repository=repository_name),
            "short":
            True
        }]
        if responsible_users:
            fields.append({
                "title": "Responsible users",
                "value": responsible_users,
                'rev_short': True,
            })

        if branch:
            fields.append({
                "title":
                "Branch",
                "value":
                self.templates['branch'].format(
                    repository=repository_name,
                    branch=branch,
                ),
                "short":
                True
            })

        if rev:
            fields.append({
                "title":
                "Revision",
                "value":
                self.templates['revision'].format(repository=repository_name,
                                                  revision=rev,
                                                  revision_short=rev[:8]),
                "short":
                True
            })

        payload = {
            "attachments": [{
                "text":
                message,
                "color":
                color,
                "mrkdwn_in": ["text", "title", "fallback", "fields"],
                "fields":
                fields
            }],
            'mrkdwn':
            True,
        }

        if self.username:
            payload['username'] = self.username

        if self.icon:
            if self.icon.startswith(':'):
                payload['icon_emoji'] = self.icon
            else:
                payload['icon_url'] = self.icon

        response = yield self._http.post("", json=payload)
        if response.code != 200:
            content = yield response.content()
            log.error("{code}: unable to upload status: {content}",
                      code=response.code,
                      content=content)
示例#16
0
 def test_getResponsibleUsersForBuild(self):
     self.setupDb()
     res = yield utils.getResponsibleUsersForBuild(self.master, 20)
     self.assertEqual(res, ["me@foo"])
示例#17
0
    def getExtraParams(self, build, event_name):
        result = {}

        state_message = build['state_string']  # // build text
        build_url = build['url']
        builder_name = build['builder']['name']
        build_number = build['number']

        result['slack_message'] = {
            "channel":
            "",
            "attachments": [{
                "fallback":
                "%s - %s" % (state_message, build_url),
                "text":
                "<%s|%s # %s> - %s" %
                (build_url, builder_name, build_number, state_message),
                "color":
                self.BUILD_RESULT[statusToString(build['results'])]
            }]
        }

        # basic message for new event
        if event_name == 'new':
            defer.returnValue(result)

        # build finished message
        build_properties = build.get('properties')
        if build_properties is not None:
            #warning please use util.GetBuildPropertyValue(build_property, property_name)

            build_commit_description = util.GetBuildPropertyValue(
                build_properties, 'commit-description')

            build_worker_name = util.GetBuildPropertyValue(
                build_properties, 'workername')  # for environment

            #https://api.slack.com/docs/messages#how_to_send_messages
            result['slack_message']['attachments'][0]['fields'] = []

            message_fields = result['slack_message']['attachments'][0][
                'fields']
            if build_commit_description is not None:
                commit_field = {
                    "title": "Tag",
                    "value": build_commit_description,
                    "short": "true"
                }
                message_fields.append(commit_field)

            if build_worker_name is not None:
                worker_name_field = {
                    "title": "Worker",
                    "value": build_worker_name,
                    "short": "true"
                }
                message_fields.append(worker_name_field)

            #add custom property
            custom_message_properties = yield self.getCustomMessageProperties(
                build, event_name)
            if custom_message_properties is not None:
                for custom_property in custom_message_properties:
                    custom_property_value = util.GetBuildPropertyValue(
                        build_properties, custom_property)  # for environment
                    custom_property_field = {
                        "title": custom_property,
                        "value": custom_property_value,
                        "short": "true"
                    }
                    message_fields.append(custom_property_field)

            # Add Reponsable Users Field
            blamelist = yield utils.getResponsibleUsersForBuild(
                self.master, build['buildid'])
            if len(blamelist) > 0:
                blamelist_str = ''.join(blamelist)

                blameField = {
                    "title": "Responsable Users",
                    "value": blamelist_str,
                    "short": "true"
                }
                message_fields.append(blameField)
        defer.returnValue(result)
示例#18
0
 def test_getResponsibleUsersForBuild(self):
     self.setupDb()
     res = yield utils.getResponsibleUsersForBuild(self.master, 20)
     self.assertEqual(sorted(res), sorted(["me@foo", "him"]))