diff --git a/.github/workflows/deploy.yml b/.github/workflows/main-deploy.yml similarity index 96% rename from .github/workflows/deploy.yml rename to .github/workflows/main-deploy.yml index 334a96d..e311db8 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/main-deploy.yml @@ -1,4 +1,4 @@ -name: CI/CD Pipeline +name: Main Deploy Pipeline on: push: @@ -6,7 +6,7 @@ on: - main jobs: - deploy: + main-deploy: runs-on: ubuntu-latest steps: - name: Checkout Code diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml new file mode 100644 index 0000000..61d1e18 --- /dev/null +++ b/.github/workflows/pr-checks.yml @@ -0,0 +1,35 @@ +name: PR Checks + +on: + pull_request: + branches: + - main + +jobs: + pr-checks: + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.10" + + - name: Set up Poetry + run: | + curl -sSL https://install.python-poetry.org | python3 - + echo "export PATH=\$HOME/.local/bin:\$PATH" >> $GITHUB_ENV + + - name: Install dependencies + run: poetry install + + - name: Run Tests + run: poetry run pytest tests/unit/ + + - name: Lint Code + run: | + poetry run flake8 --version + poetry run flake8 . + \ No newline at end of file diff --git a/meowbot/application/models/music_queue.py b/meowbot/application/models/music_queue.py index 93adeea..604f438 100644 --- a/meowbot/application/models/music_queue.py +++ b/meowbot/application/models/music_queue.py @@ -1,6 +1,7 @@ from collections import deque -class MusicQueue(): + +class MusicQueue: def __init__(self): self.queue = deque() self.current_song = None @@ -8,19 +9,17 @@ def __init__(self): def add_to_queue(self, song): self.queue.append(song) return len(self.queue) - + def remove_from_queue(self): if self.queue: return self.queue.popleft() self.current_song = None return None - + def is_empty(self): return len(self.queue) == 0 def clear(self): self.queue.clear() self.current_song = None - - \ No newline at end of file diff --git a/meowbot/application/services/command_handler_service.py b/meowbot/application/services/command_handler_service.py index 10c7b55..1cd9ae9 100644 --- a/meowbot/application/services/command_handler_service.py +++ b/meowbot/application/services/command_handler_service.py @@ -1,11 +1,11 @@ -from discord.ext import commands from meowbot.utils import logging, setup_logger + class CommandHandlerService: def __init__(self): self.logger = setup_logger(name="service.command.handler", level=logging.INFO) self.commands_tally = {} - + # TODO: can be improved by metric firing on command usage def serve_on_command_event(self, ctx): if ctx.command is not None: @@ -14,4 +14,3 @@ def serve_on_command_event(self, ctx): else: self.commands_tally[ctx.command.name] = 1 self.logger.info(f"{ctx.command.name} was served.") - \ No newline at end of file diff --git a/meowbot/bot/cogs/voice.py b/meowbot/bot/cogs/voice.py index 33e7cfa..e2ea144 100644 --- a/meowbot/bot/cogs/voice.py +++ b/meowbot/bot/cogs/voice.py @@ -97,7 +97,7 @@ async def play(self, ctx, *, url): except Exception as e: self.logger.error(f"Error when trying to play {url}: {e}") return - + position = self.music_queue.add_to_queue(player) if position == 1 and not ctx.voice_client.is_playing(): self.start_playback(ctx.voice_client, player) @@ -117,7 +117,7 @@ def start_playback(self, voice_client, player): if not player or not isinstance(player, discord.AudioSource): self.logger.error("Invalid audio source.") return - + self.logger.info(f"Type of player: {type(player)}") def after_playback(error): @@ -128,14 +128,11 @@ def after_playback(error): else: self.logger.info(f"Finished playing: {player.title}") self.play_next(voice_client) - - voice_client.play( - player, - after=after_playback - ) + + voice_client.play(player, after=after_playback) voice_client.source.volume = 0.10 self.logger.info(f"Now playing: {player.title}") - + def play_next(self, voice_client): if not self.music_queue.is_empty(): next_song = self.music_queue.remove_from_queue() @@ -167,13 +164,13 @@ async def queue(self, ctx): embed.add_field(name=f"Song {i+1}", value=song.title, inline=False) await ctx.send(embed=embed) self.logger.info("Queue displayed.") - + @commands.hybrid_command(name="clear", description="Clears the current queue") async def clear(self, ctx): self.music_queue.clear() await ctx.send("Queue has been cleared!") self.logger.info("Queue has been cleared.") - + @commands.hybrid_command(name="skip", description="Skips the current song") async def skip(self, ctx): if ctx.voice_client.is_playing():