From d1237d1d5f115fe3ef7556af88ac4e15571cc76b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marcin=20Cie=C5=9Blak?= Date: Mon, 30 Apr 2018 00:38:04 +0000 Subject: [PATCH] tests: IRC notificator should accept UTF-8 --- scripts/test/appveyor-irc-notify.py | 100 ++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 56 deletions(-) diff --git a/scripts/test/appveyor-irc-notify.py b/scripts/test/appveyor-irc-notify.py index a9b06e7c98..0cfe046969 100644 --- a/scripts/test/appveyor-irc-notify.py +++ b/scripts/test/appveyor-irc-notify.py @@ -1,10 +1,10 @@ # Copyright (C) 2015-2016 Christopher R. Wood # Copyright (c) 2018 The Tor Project # Copyright (c) 2018 isis agora lovecruft -# +# # From: https://raw.githubusercontent.com/gridsync/gridsync/def54f8166089b733d166665fdabcad4cdc526d8/misc/irc-notify.py # and: https://github.com/gridsync/gridsync -# +# # Modified by nexB on October 2016: # - rework the handling of environment variables. # - made the script use functions @@ -20,11 +20,11 @@ # 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. @@ -52,7 +52,7 @@ export APPVEYOR_REPO_COMMIT_MESSAGE="some IRC test" export APPVEYOR_ACCOUNT_NAME=isislovecruft export APPVEYOR_PULL_REQUEST_NUMBER=pull_request_number export APPVEYOR_REPO_NAME=isislovecruft/tor -python ./appveyor-irc-notify.py irc.oftc.net:6697 tor-ci '{repo_name} {color_white}{branch}{color_reset} {short_commit} - {author}: {message}','Build #{build_version} {color_green}passed{color_reset}. Details: {color_blue}{build_url}{color_reset} | Commit: {color_blue}{commit_url}{color_reset}' +python ./appveyor-irc-notify.py irc.oftc.net:6697 tor-ci '{repo_name} {color_white}{repo_branch}{color_reset} {short_commit} - {repo_commit_author}: {repo_commit_message}','Build #{build_version} {color_green}passed{color_reset}. Details: {color_blue}{build_url}{color_reset} | Commit: {color_blue}{commit_url}{color_reset}' See also https://github.com/gridsync/gridsync/blob/master/appveyor.yml for examples in Appveyor's YAML: @@ -67,7 +67,6 @@ from __future__ import print_function from __future__ import absolute_import import os -from os import environ import random import socket import ssl @@ -80,50 +79,38 @@ def appveyor_vars(): Return a dict of key value carfted from appveyor environment variables. """ - appveyor_url = environ.get('APPVEYOR_URL') - message_extended = environ.get('APPVEYOR_REPO_COMMIT_MESSAGE_EXTENDED') - branch = environ.get('APPVEYOR_REPO_BRANCH') - author = environ.get('APPVEYOR_REPO_COMMIT_AUTHOR') - author_email = environ.get('APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL') - timestamp = environ.get('APPVEYOR_REPO_COMMIT_TIMESTAMP') - repo_provider = environ.get('APPVEYOR_REPO_PROVIDER') - project_name = environ.get('APPVEYOR_PROJECT_NAME') - pull_request_title = environ.get('APPVEYOR_PULL_REQUEST_TITLE') - build_version = environ.get('APPVEYOR_BUILD_VERSION') - commit = environ.get('APPVEYOR_REPO_COMMIT') - message = environ.get('APPVEYOR_REPO_COMMIT_MESSAGE') - account_name = environ.get('APPVEYOR_ACCOUNT_NAME') - pull_request_number = environ.get('APPVEYOR_PULL_REQUEST_NUMBER') - repo_name = environ.get('APPVEYOR_REPO_NAME') - - short_commit = commit[:7] - build_url = '{appveyor_url}/project/{account_name}/{project_name}/build/{build_version}'.format(**locals()) - commit_url = 'https://{repo_provider}.com/{repo_name}/commit/{short_commit}'.format(**locals()) - - vars = dict( - appveyor_url=appveyor_url, - account_name=account_name, - project_name=project_name, - build_version=build_version, - - build_url=build_url, - - repo_provider=repo_provider, - repo_name=repo_name, - branch=branch, - author=author, - author_email=author_email, - timestamp=timestamp, - commit=commit, - short_commit=short_commit, - message=message, - message_extended=message_extended, - - pull_request_title=pull_request_title, - pull_request_number=pull_request_number, - - commit_url=commit_url, - + vars = dict([ + ( + v.replace('APPVEYOR_', '').lower(), + os.getenv(v, '').decode('utf-8') + ) for v in [ + 'APPVEYOR_URL', + 'APPVEYOR_REPO_COMMIT_MESSAGE_EXTENDED', + 'APPVEYOR_REPO_BRANCH', + 'APPVEYOR_REPO_COMMIT_AUTHOR', + 'APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL', + 'APPVEYOR_REPO_COMMIT_TIMESTAMP', + 'APPVEYOR_REPO_PROVIDER', + 'APPVEYOR_PROJECT_NAME', + 'APPVEYOR_PULL_REQUEST_TITLE', + 'APPVEYOR_BUILD_VERSION', + 'APPVEYOR_REPO_COMMIT', + 'APPVEYOR_REPO_COMMIT_MESSAGE', + 'APPVEYOR_ACCOUNT_NAME', + 'APPVEYOR_PULL_REQUEST_NUMBER', + 'APPVEYOR_REPO_NAME' + ] + ]) + + BUILD_FMT = u'{url}/project/{account_name}/{project_name}/build/{build_version}' + COMMIT_FMT = u'https://{repo_provider}.com/{repo_name}/commit/{repo_commit}' + + print(vars) + + vars.update( + build_url=BUILD_FMT.format(**vars), + commit_url=COMMIT_FMT.format(**vars), + short_commit=vars["repo_commit"][:7], color_white='\x030', color_blue='\x032', color_green='\x033', @@ -146,17 +133,18 @@ def notify(): if success or failure: messages = [] - messages.append("{repo_name} {color_white}{branch}{color_reset} {short_commit} - {author}: {message}") + messages.append(u"{repo_name} {color_white}{repo_branch}{color_reset} {short_commit} - {repo_commit_author}: {repo_commit_message}") if success: - messages.append("Build #{build_version} {color_green}passed{color_reset}. Details: {color_blue}{build_url}{color_reset} Commit: {color_blue}{commit_url}{color_reset}") + messages.append(u"Build #{build_version} {color_green}passed{color_reset}. Details: {color_blue}{build_url}{color_reset} Commit: {color_blue}{commit_url}{color_reset}") if failure: - messages.append("Build #{build_version} {color_red}failed{color_reset}. Details: {color_blue}{build_url}{color_reset} Commit: {color_blue}{commit_url}{color_reset}") + messages.append(u"Build #{build_version} {color_red}failed{color_reset}. Details: {color_blue}{build_url}{color_reset} Commit: {color_blue}{commit_url}{color_reset}") else: messages = sys.argv[3:] messages = ' '.join(messages) - messages = messages.split(',') + messages = messages.decode("utf-8").split(',') + print(repr(apvy_vars)) messages = [msg.format(**apvy_vars).strip() for msg in messages] irc_username = 'appveyor-ci' @@ -184,8 +172,8 @@ def notify(): time.sleep(5) # send notification for msg in messages: - print('PRIVMSG #{} :{}'.format(channel, msg)) - irc_sock.send('PRIVMSG #{} :{}\r\n'.format(channel, msg).encode()) + print(u'PRIVMSG #{} :{}'.format(channel, msg).encode("utf-8")) + irc_sock.send(u'PRIVMSG #{} :{}\r\n'.format(channel, msg).encode("utf-8")) time.sleep(5) return -- 2.11.4.GIT