From 0be7977e0ea893ef36bcf891fe2668a9304a4e14 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 6 Jun 2018 18:36:18 +0100 Subject: [CI] Build on GitLab --- .travis.yml | 30 ------------------------------ gitlab-ci.yml | 40 ++++++++++++++++++++++++++++++++++++++++ scripts/deploy.sh | 2 +- 3 files changed, 41 insertions(+), 31 deletions(-) delete mode 100644 .travis.yml create mode 100644 gitlab-ci.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 4d70f870e..000000000 --- a/.travis.yml +++ /dev/null @@ -1,30 +0,0 @@ -language: python -python: - - "3.6" - -branches: - only: - - "master" - -sudo: required - -services: - - docker - -env: - global: - - PIPENV_VENV_IN_PROJECT=1 - - PIPENV_IGNORE_VIRTUALENVS=1 - -install: - - pip install pipenv - - pipenv sync --dev --three -script: - - pipenv run python -m flake8 -after_success: - - bash scripts/deploy.sh - -cache: pip - -notifications: - email: false diff --git a/gitlab-ci.yml b/gitlab-ci.yml new file mode 100644 index 000000000..0b7ffbc56 --- /dev/null +++ b/gitlab-ci.yml @@ -0,0 +1,40 @@ +image: python:3.6-alpine3.7 + +variables: + PIPENV_VENV_IN_PROJECT: 1 + PIPENV_IGNORE_VIRTUALENVS: 1 + + +before_script: + - apk add --update tini + - apk add --update build-base + - apk add --update libffi-dev + - apk add --update zlib + - apk add --update jpeg-dev + - apk add --update libxml2 libxml2-dev libxslt-dev + - apk add --update zlib-dev + - apk add --update freetype-dev + +stages: + - test + - build + +test: + stage: test + cache: + paths: + - ".venv" + + script: + - pip install pipenv + - pipenv sync --dev --three + - pipenv run python -m flake8 + +build: + services: + - docker:dind + + stage: build + script: + - apk add docker curl + - sh scripts/deploy.sh diff --git a/scripts/deploy.sh b/scripts/deploy.sh index d8a5a0176..50ec87f59 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -1,7 +1,7 @@ #!/bin/bash # Build and deploy on master branch -if [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then +if [[ $CI_COMMIT_REF_SLUG == 'master' ]]; then echo "Connecting to docker hub" echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin -- cgit v1.2.3 From 99e4733491f61194b0b883102e98e2f462cffa52 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 6 Jun 2018 18:39:11 +0100 Subject: [CI] Misnamed YAML file --- .gitlab-ci.yml | 40 ++++++++++++++++++++++++++++++++++++++++ gitlab-ci.yml | 40 ---------------------------------------- 2 files changed, 40 insertions(+), 40 deletions(-) create mode 100644 .gitlab-ci.yml delete mode 100644 gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 000000000..0b7ffbc56 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,40 @@ +image: python:3.6-alpine3.7 + +variables: + PIPENV_VENV_IN_PROJECT: 1 + PIPENV_IGNORE_VIRTUALENVS: 1 + + +before_script: + - apk add --update tini + - apk add --update build-base + - apk add --update libffi-dev + - apk add --update zlib + - apk add --update jpeg-dev + - apk add --update libxml2 libxml2-dev libxslt-dev + - apk add --update zlib-dev + - apk add --update freetype-dev + +stages: + - test + - build + +test: + stage: test + cache: + paths: + - ".venv" + + script: + - pip install pipenv + - pipenv sync --dev --three + - pipenv run python -m flake8 + +build: + services: + - docker:dind + + stage: build + script: + - apk add docker curl + - sh scripts/deploy.sh diff --git a/gitlab-ci.yml b/gitlab-ci.yml deleted file mode 100644 index 0b7ffbc56..000000000 --- a/gitlab-ci.yml +++ /dev/null @@ -1,40 +0,0 @@ -image: python:3.6-alpine3.7 - -variables: - PIPENV_VENV_IN_PROJECT: 1 - PIPENV_IGNORE_VIRTUALENVS: 1 - - -before_script: - - apk add --update tini - - apk add --update build-base - - apk add --update libffi-dev - - apk add --update zlib - - apk add --update jpeg-dev - - apk add --update libxml2 libxml2-dev libxslt-dev - - apk add --update zlib-dev - - apk add --update freetype-dev - -stages: - - test - - build - -test: - stage: test - cache: - paths: - - ".venv" - - script: - - pip install pipenv - - pipenv sync --dev --three - - pipenv run python -m flake8 - -build: - services: - - docker:dind - - stage: build - script: - - apk add docker curl - - sh scripts/deploy.sh -- cgit v1.2.3 From 3621f466619c0a2061d6808473f5c2028ee68872 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 6 Jun 2018 19:09:27 +0100 Subject: RabbitMQ service discovery --- bot/__main__.py | 14 ++++++++++++-- bot/utils/service_discovery.py | 22 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 bot/utils/service_discovery.py diff --git a/bot/__main__.py b/bot/__main__.py index b1e9c61fa..d04be725c 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -7,6 +7,7 @@ from discord.ext.commands import Bot, when_mentioned_or from bot.constants import Bot as BotConfig, ClickUp from bot.formatter import Formatter +from bot.utils.service_discovery import wait_for_rmq log = logging.getLogger(__name__) @@ -36,13 +37,19 @@ bot.http_session = ClientSession( ) ) +log.info("Waiting for RabbitMQ...") +has_rmq = wait_for_rmq() + +if has_rmq: + log.info("RabbitMQ found") +else: + log.warning("Timed out while waiting for RabbitMQ") + # Internal/debug bot.load_extension("bot.cogs.logging") -bot.load_extension("bot.cogs.rmq") bot.load_extension("bot.cogs.security") bot.load_extension("bot.cogs.events") - # Commands, etc bot.load_extension("bot.cogs.bot") bot.load_extension("bot.cogs.cogs") @@ -64,6 +71,9 @@ bot.load_extension("bot.cogs.tags") bot.load_extension("bot.cogs.verification") bot.load_extension("bot.cogs.utils") +if has_rmq: + bot.load_extension("bot.cogs.rmq") + bot.run(BotConfig.token) bot.http_session.close() # Close the aiohttp session when the bot finishes running diff --git a/bot/utils/service_discovery.py b/bot/utils/service_discovery.py new file mode 100644 index 000000000..8d79096bd --- /dev/null +++ b/bot/utils/service_discovery.py @@ -0,0 +1,22 @@ +import datetime +import socket +import time +from contextlib import closing + +from bot.constants import RabbitMQ + +THIRTY_SECONDS = datetime.timedelta(seconds=30) + + +def wait_for_rmq(): + start = datetime.datetime.now() + + while True: + if datetime.datetime.now() - start > THIRTY_SECONDS: + return False + + with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock: + if sock.connect_ex((RabbitMQ.host, RabbitMQ.port)) == 0: + return True + + time.sleep(0.5) -- cgit v1.2.3 From 2d290f2236784adeac10863d593ad9468111772d Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 6 Jun 2018 20:15:28 +0100 Subject: Log JSON to stderr when not in debug mode --- bot/__init__.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/bot/__init__.py b/bot/__init__.py index a8272981c..43356efca 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -1,3 +1,5 @@ +import os + import ast import logging import re @@ -30,12 +32,23 @@ Logger.trace = monkeypatch_trace # Set up logging logging_handlers = [] +# We can't import this yet, so we have to define it ourselves +DEBUG_MODE = True if 'local' in os.environ.get("SITE_URL", "local") else False + + +if DEBUG_MODE: + logging_handlers.append(StreamHandler(stream=sys.stderr)) + + json_handler = logging.FileHandler(filename="log.json", mode="w") + json_handler.formatter = JsonFormatter() + logging_handlers.append(json_handler) +else: + logging_handlers.append(logging.FileHandler(filename="log.txt", mode="w")) -logging_handlers.append(StreamHandler(stream=sys.stderr)) + json_handler = logging.StreamHandler(stream=sys.stderr) + json_handler.formatter = JsonFormatter() + logging_handlers.append(json_handler) -json_handler = logging.FileHandler(filename="log.json", mode="w") -json_handler.formatter = JsonFormatter() -logging_handlers.append(json_handler) logging.basicConfig( format="%(asctime)s pd.beardfist.com Bot: | %(name)30s | %(levelname)8s | %(message)s", -- cgit v1.2.3 From 86feb8228b095308defe55b79c109fcfb047b8dd Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 6 Jun 2018 20:21:35 +0100 Subject: Let's not log TRACE/DEBUG in prod --- bot/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/__init__.py b/bot/__init__.py index 43356efca..d65aac752 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -53,7 +53,7 @@ else: logging.basicConfig( format="%(asctime)s pd.beardfist.com Bot: | %(name)30s | %(levelname)8s | %(message)s", datefmt="%b %d %H:%M:%S", - level=logging.TRACE, + level=logging.TRACE if DEBUG_MODE else logging.info, handlers=logging_handlers ) -- cgit v1.2.3 From 6d12015e6c1a33c92a15385a6f93d0e45a5e01f3 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 6 Jun 2018 20:23:01 +0100 Subject: Linting --- bot/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bot/__init__.py b/bot/__init__.py index d65aac752..8f870bdf6 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -1,6 +1,5 @@ -import os - import ast +import os import logging import re import sys -- cgit v1.2.3 From 829443f256defc0c09bb7c8f3175651f4ee25a8e Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 6 Jun 2018 20:29:20 +0100 Subject: Lint, and add "docker" tag to builds --- .gitlab-ci.yml | 6 ++++++ bot/__init__.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0b7ffbc56..47a08a02a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -20,6 +20,9 @@ stages: - build test: + tags: + - docker + stage: test cache: paths: @@ -31,6 +34,9 @@ test: - pipenv run python -m flake8 build: + tags: + - docker + services: - docker:dind diff --git a/bot/__init__.py b/bot/__init__.py index 8f870bdf6..0a2196674 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -1,6 +1,6 @@ import ast -import os import logging +import os import re import sys from logging import Logger, StreamHandler -- cgit v1.2.3 From 892f60fcbf5b541498f08f45f6b3041d9ffe10c5 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 6 Jun 2018 20:45:26 +0100 Subject: [Logging] Fix dumb mistake --- bot/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/__init__.py b/bot/__init__.py index 0a2196674..8780292a1 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -52,7 +52,7 @@ else: logging.basicConfig( format="%(asctime)s pd.beardfist.com Bot: | %(name)30s | %(levelname)8s | %(message)s", datefmt="%b %d %H:%M:%S", - level=logging.TRACE if DEBUG_MODE else logging.info, + level=logging.TRACE if DEBUG_MODE else logging.INFO, handlers=logging_handlers ) -- cgit v1.2.3 From 7a47d57c4eb0e6c79fb41e7c12e2533d2b3dc9dd Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 6 Jun 2018 20:58:25 +0100 Subject: Use stdout for logging --- bot/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/__init__.py b/bot/__init__.py index 8780292a1..840c7b47c 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -36,7 +36,7 @@ DEBUG_MODE = True if 'local' in os.environ.get("SITE_URL", "local") else False if DEBUG_MODE: - logging_handlers.append(StreamHandler(stream=sys.stderr)) + logging_handlers.append(StreamHandler(stream=sys.stdout)) json_handler = logging.FileHandler(filename="log.json", mode="w") json_handler.formatter = JsonFormatter() @@ -44,7 +44,7 @@ if DEBUG_MODE: else: logging_handlers.append(logging.FileHandler(filename="log.txt", mode="w")) - json_handler = logging.StreamHandler(stream=sys.stderr) + json_handler = logging.StreamHandler(stream=sys.stdout) json_handler.formatter = JsonFormatter() logging_handlers.append(json_handler) -- cgit v1.2.3 From 0a3e5f5c2a3891c340514a2abe0e4aed27de9863 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Wed, 6 Jun 2018 21:02:57 +0100 Subject: Update gitignore for logfiles --- .gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 3202baa92..4321d9324 100644 --- a/.gitignore +++ b/.gitignore @@ -106,8 +106,8 @@ ENV/ # Vagrant .vagrant -# JSON logfile -log.json +# Logfiles +log.* # Custom user configuration config.yml -- cgit v1.2.3 From 0874f812def0f2cb3154ce1760a7c61fdc917a97 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Thu, 7 Jun 2018 12:09:09 +0100 Subject: Force all loggers to use our handlers, and disable papertrail --- bot/__init__.py | 28 +++++++++++++++++++--------- bot/constants.py | 7 ------- config-default.yml | 5 ----- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/bot/__init__.py b/bot/__init__.py index 840c7b47c..de3d4d782 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -4,7 +4,6 @@ import os import re import sys from logging import Logger, StreamHandler -from logging.handlers import SysLogHandler import discord.ext.commands.view from logmatic import JsonFormatter @@ -58,14 +57,25 @@ logging.basicConfig( log = logging.getLogger(__name__) -# We need to defer the import from `constants.py` -# because otherwise the logging config would not be applied -# to any logging done in the module. -from bot.constants import Papertrail # noqa -if Papertrail.address: - papertrail_handler = SysLogHandler(address=(Papertrail.address, Papertrail.port)) - papertrail_handler.setLevel(logging.DEBUG) - logging.getLogger('bot').addHandler(papertrail_handler) + +for key, value in logging.Logger.manager.loggerDict.items(): + # Force all existing loggers to the correct level and handlers + # This happens long before we instantiate our loggers, so + # those should still have the expected level + + if key == "bot": + continue + + if not isinstance(value, logging.Logger): + # There might be some logging.PlaceHolder objects in there + continue + + if DEBUG_MODE: + value.setLevel(logging.DEBUG) + else: + value.setLevel(logging.INFO) + + value.handlers = logging_handlers # Silence discord and websockets diff --git a/bot/constants.py b/bot/constants.py index 50a316d26..c512480c5 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -233,13 +233,6 @@ class ClickUp(metaclass=YAMLGetter): key: str -class Papertrail(metaclass=YAMLGetter): - section = "papertrail" - - address: str - port: str - - class RabbitMQ(metaclass=YAMLGetter): section = "rabbitmq" diff --git a/config-default.yml b/config-default.yml index e10150617..3a20d10c6 100644 --- a/config-default.yml +++ b/config-default.yml @@ -55,11 +55,6 @@ clickup: key: !ENV 'CLICKUP_KEY' -papertrail: - address: !ENV 'PAPERTRAIL_ADDRESS' - port: !ENV 'PAPERTRAIL_PORT' - - rabbitmq: host: "pdrmq" port: 5672 -- cgit v1.2.3 From 6c88fe8f0d8a75f1e4901eb50bae1fb68c3f6dd7 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Thu, 7 Jun 2018 19:53:24 +0100 Subject: GitHub -> GitLab --- .dockerignore | 1 + .github/CONTRIBUTING.md | 11 +++++------ bot/cogs/bot.py | 4 ++-- bot/cogs/cogs.py | 8 ++++---- bot/cogs/logging.py | 2 +- bot/cogs/snakes.py | 4 ++-- bot/constants.py | 2 +- config-default.yml | 2 +- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/.dockerignore b/.dockerignore index ae09cac97..e332b562d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,6 +5,7 @@ __pycache__ .vagrant .pytest_cache .github +.gitlab .cache Vagrantfile .coverage diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 8b803acad..36152fc5d 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -7,18 +7,17 @@ contributions may be rejected on the basis of a contributor failing to follow th ## Rules 1. **No force-pushes** or modifying the Git history in any way. -1. If you have direct access to the repository, **create a branch for your changes** and create a pull request for that branch. +1. If you have direct access to the repository, **create a branch for your changes** and create a merge request for that branch. If not, fork it and work on a separate branch there. * Some repositories require this and will reject any direct pushes to `master`. Make this a habit! -1. If someone is working on a pull request, **do not open your own pull request for the same task**. Instead, leave some comments - on the existing pull request. Communication is key, and there's no point in two separate implementations of the same thing. +1. If someone is working on a merge request, **do not open your own merge request for the same task**. Instead, leave some comments + on the existing merge request. Communication is key, and there's no point in two separate implementations of the same thing. * One option is to fork the other contributor's repository, and submit your changes to their branch with your - own pull request. If you do this, we suggest following these guidelines when interacting with their repository + own merge request. If you do this, we suggest following these guidelines when interacting with their repository as well. 1. **Adhere to the prevailing code style**, which we enforce using [flake8](http://flake8.pycqa.org/en/latest/index.html). * Additionally, run `flake8` against your code before you push it. Your commit will be rejected by the build server - if it fails to lint. For an automatic way to do this, check out - [our article on Git hooks](https://github.com/discord-python/site/wiki/Git-Hooks). + if it fails to lint. 1. **Don't fight the framework**. Every framework has its flaws, but the frameworks we've picked out have been carefully chosen for their particular merits. If you can avoid it, please resist reimplementing swathes of framework logic - the work has already been done for you! diff --git a/bot/cogs/bot.py b/bot/cogs/bot.py index 6d574d0b1..af9abd7cb 100644 --- a/bot/cogs/bot.py +++ b/bot/cogs/bot.py @@ -56,7 +56,7 @@ class Bot: embed = Embed( description="A utility bot designed just for the Python server! Try `bot.help()` for more info.", - url="https://github.com/discord-python/bot" + url="https://gitlab.com/discord-python/projects/bot" ) repo = Repo(".") @@ -67,7 +67,7 @@ class Bot: embed.set_author( name="Python Bot", - url="https://github.com/discord-python/bot", + url="https://gitlab.com/discord-python/projects/bot", icon_url=URLs.bot_avatar ) diff --git a/bot/cogs/cogs.py b/bot/cogs/cogs.py index 51693f9ef..7eaf5005c 100644 --- a/bot/cogs/cogs.py +++ b/bot/cogs/cogs.py @@ -51,7 +51,7 @@ class Cogs: embed.set_author( name="Python Bot (Cogs)", - url=URLs.github_bot_repo, + url=URLs.gitlab_bot_repo, icon_url=URLs.bot_avatar ) @@ -108,7 +108,7 @@ class Cogs: embed.set_author( name="Python Bot (Cogs)", - url=URLs.github_bot_repo, + url=URLs.gitlab_bot_repo, icon_url=URLs.bot_avatar ) @@ -163,7 +163,7 @@ class Cogs: embed.set_author( name="Python Bot (Cogs)", - url=URLs.github_bot_repo, + url=URLs.gitlab_bot_repo, icon_url=URLs.bot_avatar ) @@ -264,7 +264,7 @@ class Cogs: embed.colour = Colour.blurple() embed.set_author( name="Python Bot (Cogs)", - url=URLs.github_bot_repo, + url=URLs.gitlab_bot_repo, icon_url=URLs.bot_avatar ) diff --git a/bot/cogs/logging.py b/bot/cogs/logging.py index 05fed7042..67f09dc8a 100644 --- a/bot/cogs/logging.py +++ b/bot/cogs/logging.py @@ -23,7 +23,7 @@ class Logging: embed = Embed(description="Connected!") embed.set_author( name="Python Bot", - url="https://github.com/discord-python/bot", + url="https://gitlab.com/discord-python/projects/bot", icon_url="https://raw.githubusercontent.com/discord-python/branding/master/logos/logo_circle.png" ) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 78be08fab..ec32a119d 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -140,7 +140,7 @@ class Snakes: More information can be found in the code-jam-1 repo. - https://github.com/discord-python/code-jam-1 + https://gitlab_bot_repo.com/discord-python/code-jams/code-jam-1 """ wiki_brief = re.compile(r'(.*?)(=+ (.*?) =+)', flags=re.DOTALL) @@ -981,7 +981,7 @@ class Snakes: title="About the snake cog", description=( "The features in this cog were created by members of the community " - "during our first ever [code jam event](https://github.com/discord-python/code-jam-1). \n\n" + "during our first ever [code jam event](https://gitlab.com/discord-python/code-jams/code-jam-1). \n\n" "The event saw over 50 participants, who competed to write a discord bot cog with a snake theme over " "48 hours. The staff then selected the best features from all the best teams, and made modifications " "to ensure they would all work together before integrating them into the community bot.\n\n" diff --git a/bot/constants.py b/bot/constants.py index c512480c5..eec150d1a 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -256,7 +256,7 @@ class URLs(metaclass=YAMLGetter): site_names_api: str site_idioms_api: str site_special_api: str - github_bot_repo: str + gitlab_bot_repo: str bot_avatar: str omdb: str diff --git a/config-default.yml b/config-default.yml index 3a20d10c6..eb0f86d2f 100644 --- a/config-default.yml +++ b/config-default.yml @@ -75,6 +75,6 @@ urls: site_names_api: 'https://api.pythondiscord.com/bot/snake_names' site_idioms_api: 'https://api.pythondiscord.com/bot/snake_idioms' site_special_api: 'https://api.pythondiscord.com/bot/special_snakes' - github_bot_repo: 'https://github.com/discord-python/bot' + gitlab_bot_repo: 'https://gitlab.com/discord-python/projects/bot' bot_avatar: 'https://raw.githubusercontent.com/discord-python/branding/master/logos/logo_circle/logo_circle.png' omdb: 'http://omdbapi.com' -- cgit v1.2.3 From 414f1896736a9eb7fc5ded277bd0b4a0f98d71c3 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Thu, 7 Jun 2018 21:40:09 +0100 Subject: Move CONTRIBUTING.md --- .github/CONTRIBUTING.md | 41 ----------------------------------------- CONTRIBUTING.md | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 41 deletions(-) delete mode 100644 .github/CONTRIBUTING.md create mode 100644 CONTRIBUTING.md diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md deleted file mode 100644 index 36152fc5d..000000000 --- a/.github/CONTRIBUTING.md +++ /dev/null @@ -1,41 +0,0 @@ -# Contributing to one of our projects - -Our projects are open-source, and are deployed as commits are pushed to the `master` branch on each repository. -We've created a set of guidelines here in order to keep everything clean and in working order. Please note that -contributions may be rejected on the basis of a contributor failing to follow the guidelines. - -## Rules - -1. **No force-pushes** or modifying the Git history in any way. -1. If you have direct access to the repository, **create a branch for your changes** and create a merge request for that branch. - If not, fork it and work on a separate branch there. - * Some repositories require this and will reject any direct pushes to `master`. Make this a habit! -1. If someone is working on a merge request, **do not open your own merge request for the same task**. Instead, leave some comments - on the existing merge request. Communication is key, and there's no point in two separate implementations of the same thing. - * One option is to fork the other contributor's repository, and submit your changes to their branch with your - own merge request. If you do this, we suggest following these guidelines when interacting with their repository - as well. -1. **Adhere to the prevailing code style**, which we enforce using [flake8](http://flake8.pycqa.org/en/latest/index.html). - * Additionally, run `flake8` against your code before you push it. Your commit will be rejected by the build server - if it fails to lint. -1. **Don't fight the framework**. Every framework has its flaws, but the frameworks we've picked out have been carefully - chosen for their particular merits. If you can avoid it, please resist reimplementing swathes of framework logic - the - work has already been done for you! -1. **Work as a team** and cooperate where possible. Keep things friendly, and help each other out - these are shared - projects, and nobody likes to have their feet trodden on. -1. **Internal projects are internal**. As a contributor, you have access to information that the rest of the server - does not. With this trust comes responsibility - do not release any information you have learned as a result of - your contributor position. We are very strict about announcing things at specific times, and many staff members - will not appreciate a disruption of the announcement schedule. - -Above all, the needs of our community should come before the wants of an individual. Work together, build solutions to -problems and try to do so in a way that people can learn from easily. Abuse of our trust may result in the loss of your Contributor role, especially in relation to Rule 7. - -## Changes to this arrangement - -All projects evolve over time, and this contribution guide is no different. This document may also be subject to pull -requests or changes by contributors, where you believe you have something valuable to add or change. - -## Footnotes - -This document was inspired by the [Glowstone contribution guidelines](https://github.com/GlowstoneMC/Glowstone/blob/dev/docs/CONTRIBUTING.md). diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..36152fc5d --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,41 @@ +# Contributing to one of our projects + +Our projects are open-source, and are deployed as commits are pushed to the `master` branch on each repository. +We've created a set of guidelines here in order to keep everything clean and in working order. Please note that +contributions may be rejected on the basis of a contributor failing to follow the guidelines. + +## Rules + +1. **No force-pushes** or modifying the Git history in any way. +1. If you have direct access to the repository, **create a branch for your changes** and create a merge request for that branch. + If not, fork it and work on a separate branch there. + * Some repositories require this and will reject any direct pushes to `master`. Make this a habit! +1. If someone is working on a merge request, **do not open your own merge request for the same task**. Instead, leave some comments + on the existing merge request. Communication is key, and there's no point in two separate implementations of the same thing. + * One option is to fork the other contributor's repository, and submit your changes to their branch with your + own merge request. If you do this, we suggest following these guidelines when interacting with their repository + as well. +1. **Adhere to the prevailing code style**, which we enforce using [flake8](http://flake8.pycqa.org/en/latest/index.html). + * Additionally, run `flake8` against your code before you push it. Your commit will be rejected by the build server + if it fails to lint. +1. **Don't fight the framework**. Every framework has its flaws, but the frameworks we've picked out have been carefully + chosen for their particular merits. If you can avoid it, please resist reimplementing swathes of framework logic - the + work has already been done for you! +1. **Work as a team** and cooperate where possible. Keep things friendly, and help each other out - these are shared + projects, and nobody likes to have their feet trodden on. +1. **Internal projects are internal**. As a contributor, you have access to information that the rest of the server + does not. With this trust comes responsibility - do not release any information you have learned as a result of + your contributor position. We are very strict about announcing things at specific times, and many staff members + will not appreciate a disruption of the announcement schedule. + +Above all, the needs of our community should come before the wants of an individual. Work together, build solutions to +problems and try to do so in a way that people can learn from easily. Abuse of our trust may result in the loss of your Contributor role, especially in relation to Rule 7. + +## Changes to this arrangement + +All projects evolve over time, and this contribution guide is no different. This document may also be subject to pull +requests or changes by contributors, where you believe you have something valuable to add or change. + +## Footnotes + +This document was inspired by the [Glowstone contribution guidelines](https://github.com/GlowstoneMC/Glowstone/blob/dev/docs/CONTRIBUTING.md). -- cgit v1.2.3 From fde37c5bbcf3158ca07ff6677d01b4365348adbd Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Thu, 7 Jun 2018 22:00:41 +0100 Subject: Collect avatar URLs and send them to the site --- bot/cogs/events.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bot/cogs/events.py b/bot/cogs/events.py index 5345a63b0..53e58bd21 100644 --- a/bot/cogs/events.py +++ b/bot/cogs/events.py @@ -103,6 +103,7 @@ class Events: roles = [str(r.id) for r in member.roles] # type: List[int] users.append({ + "avatar": member.avatar_url_as(), "user_id": str(member.id), "roles": roles, "username": member.name, @@ -142,7 +143,11 @@ class Events: ) async def on_member_update(self, before: Member, after: Member): - if before.roles == after.roles and before.name == after.name and before.discriminator == after.discriminator: + if ( + before.roles == after.roles and + before.name == after.name and + before.discriminator == after.discriminator and + before.avatar == after.avatar): return before_role_names = [role.name for role in before.roles] # type: List[str] @@ -152,6 +157,7 @@ class Events: log.debug(f"{before.display_name} roles changing from {before_role_names} to {after_role_names}") changes = await self.send_updated_users({ + "avatar": after.avatar_url_as(), "user_id": str(after.id), "roles": role_ids, "username": after.name, @@ -164,6 +170,7 @@ class Events: role_ids = [str(r.id) for r in member.roles] # type: List[str] changes = await self.send_updated_users({ + "avatar": member.avatar_url_as(), "user_id": str(member.id), "roles": role_ids, "username": member.name, -- cgit v1.2.3 From 208cf58631b4b32a63cc2b876b994d7f905e21b4 Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Thu, 7 Jun 2018 22:20:18 +0100 Subject: Force redeploy --- CONTRIBUTING.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 36152fc5d..f8deaee04 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -39,3 +39,4 @@ requests or changes by contributors, where you believe you have something valuab ## Footnotes This document was inspired by the [Glowstone contribution guidelines](https://github.com/GlowstoneMC/Glowstone/blob/dev/docs/CONTRIBUTING.md). + -- cgit v1.2.3 From e526f9137133f64b58ed2c726b5d616d2c16122d Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Fri, 8 Jun 2018 20:24:35 +0100 Subject: Force logger handlers in a safer way --- bot/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bot/__init__.py b/bot/__init__.py index de3d4d782..9529902ab 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -75,7 +75,11 @@ for key, value in logging.Logger.manager.loggerDict.items(): else: value.setLevel(logging.INFO) - value.handlers = logging_handlers + for handler in value.handlers.copy(): + value.removeHandler(handler) + + for handler in logging_handlers: + value.addHandler(handler) # Silence discord and websockets -- cgit v1.2.3 From d92ca84751ef22a36db304e24602befcb34e623f Mon Sep 17 00:00:00 2001 From: Christopher Baklid Date: Sun, 10 Jun 2018 21:50:25 +0200 Subject: adds a ci container to speed up build times --- .gitlab-ci.yml | 23 +++-------------------- Pipfile | 3 +++ docker/ci.Dockerfile | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 20 deletions(-) create mode 100644 docker/ci.Dockerfile diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 47a08a02a..3d13ef5f1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,19 +1,4 @@ -image: python:3.6-alpine3.7 - -variables: - PIPENV_VENV_IN_PROJECT: 1 - PIPENV_IGNORE_VIRTUALENVS: 1 - - -before_script: - - apk add --update tini - - apk add --update build-base - - apk add --update libffi-dev - - apk add --update zlib - - apk add --update jpeg-dev - - apk add --update libxml2 libxml2-dev libxslt-dev - - apk add --update zlib-dev - - apk add --update freetype-dev +image: pythondiscord/bot-ci:latest stages: - test @@ -29,9 +14,8 @@ test: - ".venv" script: - - pip install pipenv - - pipenv sync --dev --three - - pipenv run python -m flake8 + - pipenv sync --dev + - pipenv run lint build: tags: @@ -42,5 +26,4 @@ build: stage: build script: - - apk add docker curl - sh scripts/deploy.sh diff --git a/Pipfile b/Pipfile index e6d1366c6..9b0e530ec 100644 --- a/Pipfile +++ b/Pipfile @@ -39,7 +39,10 @@ python_version = "3.6" [scripts] start = "python -m bot" +lint = "python -m flake8" build = "docker build -t pythondiscord/bot:latest -f docker/Dockerfile ." push = "docker push pythondiscord/bot:latest" buildbase = "docker build -t pythondiscord/bot-base:latest -f docker/Dockerfile.base ." pushbase = "docker push pythondiscord/bot-base:latest" +buildci = "docker build -t pythondiscord/bot-ci:latest -f docker/ci.Dockerfile ." +pushci = "docker push pythondiscord/bot-ci:latest" diff --git a/docker/ci.Dockerfile b/docker/ci.Dockerfile new file mode 100644 index 000000000..fd7e25239 --- /dev/null +++ b/docker/ci.Dockerfile @@ -0,0 +1,20 @@ +FROM python:3.6-alpine3.7 + +RUN apk add --update docker \ + curl \ + tini \ + build-base \ + libffi-dev \ + zlib \ + jpeg-dev \ + libxml2 libxml2-dev libxslt-dev \ + zlib-dev \ + freetype-dev + +RUN pip install pipenv + +ENV LIBRARY_PATH=/lib:/usr/lib +ENV PIPENV_VENV_IN_PROJECT=1 +ENV PIPENV_IGNORE_VIRTUALENVS=1 +ENV PIPENV_NOSPIN=1 +ENV PIPENV_HIDE_EMOJIS=1 -- cgit v1.2.3