Changeset View
Changeset View
Standalone View
Standalone View
blender_bot_helper.py
- This file was added.
| # ##### BEGIN GPL LICENSE BLOCK ##### | |||||
| # | |||||
| # This program is free software; you can redistribute it and/or | |||||
| # modify it under the terms of the GNU General Public License | |||||
| # as published by the Free Software Foundation; either version 2 | |||||
| # of the License, or (at your option) any later version. | |||||
| # | |||||
| # This program is distributed in the hope that it will be useful, | |||||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
| # GNU General Public License for more details. | |||||
| # | |||||
| # You should have received a copy of the GNU General Public License | |||||
| # along with this program; if not, write to the Free Software Foundation, | |||||
| # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
| # | |||||
| # ##### END GPL LICENSE BLOCK ##### | |||||
| # <pep8 compliant> | |||||
| from buildbot.reporters.http import HttpStatusPushBase | |||||
| from twisted.internet import defer | |||||
| from buildbot.process.results import Results | |||||
| from buildbot.util.logger import Logger | |||||
| import requests | |||||
| import json | |||||
| log = Logger() | |||||
| # REST API doc for Rocket chat: https://docs.rocket.chat/api/rest-api | |||||
| URL = 'https://blender.chat/api/v1/chat.sendMessage' | |||||
brecht: Where does this value come from? At least mention it in a comment.
Probably a better variable… | |||||
| # CHANNEL_ID for #blender-coders channel can get this from | |||||
| # /api/v1/channels.list endpoint | |||||
| CHANNEL_ID = '9p9NPvT7yFseE8ivA' | |||||
| BOT_AUTH_TOKEN = '' | |||||
| BOT_USER_ID = '' | |||||
| class BlenderChatStatusPush(HttpStatusPushBase): | |||||
| name = "BlenderChatStatusPush" | |||||
| @defer.inlineCallbacks | |||||
| def sendMessage(self, reports): | |||||
| build = reports[0]['builds'][0] | |||||
Done Inline ActionsDon't list every platform since we'll soon add more and then this breaks. Instead just check if custom_branch is part of the name. brecht: Don't list every platform since we'll soon add more and then this breaks.
Instead just check… | |||||
| result = build['results'] | |||||
| if result is None: | |||||
| return | |||||
| build_result = Results[result] | |||||
| builder_name = build['builder']['name'] | |||||
| build_number = build['number'] | |||||
| buildbot_url = build['url'] | |||||
| # Exclude status reporting of "custom branches". | |||||
| branch_type = "custom_branch" | |||||
| # Send a notification to Blender chat in case of a failure or exception. | |||||
| if (build_result == "failure" or build_result == "exception") and branch_type not in builder_name: | |||||
| if build_result == "exception": | |||||
| indefinite_article = "an" | |||||
| else: | |||||
| indefinite_article = "a" | |||||
| status_msg = f"Build [{build_number}]({buildbot_url}) running on `{builder_name}` had {indefinite_article} " \ | |||||
Done Inline ActionsCheck this earlier in the function. brecht: Check this earlier in the function. | |||||
| f"{build_result}." | |||||
Not Done Inline ActionsAre there exceptions to be handled here? We wouldn't want blender.chat being offline to also bring down the buildbot. brecht: Are there exceptions to be handled here?
We wouldn't want blender.chat being offline to also… | |||||
Done Inline ActionsNo, buildbot won't be affected, if its offline, the status will be logged in twistd.log file by default. calra: No, buildbot won't be affected, if its offline, the status will be logged in `twistd.log` file… | |||||
| payload = {'message': {'rid': CHANNEL_ID, 'msg': status_msg}} | |||||
| headers = {'content-type': 'application/json', | |||||
| 'X-Auth-Token': BOT_AUTH_TOKEN, | |||||
| 'X-User-Id': BOT_USER_ID, | |||||
| } | |||||
| response = yield requests.post(URL, data=json.dumps(payload), headers=headers) | |||||
| if response.status_code != 200: | |||||
| content = yield response.text | |||||
| log.error("{code}: unable to upload status: {content}", | |||||
| code=response.status_code, content=content) | |||||
Where does this value come from? At least mention it in a comment.
Probably a better variable name is something like ÇHANNEL_ID.