import PaginatedView from CommitsSelectMenu import CommitSelectMenu from typing import * import datetime from discord.ui import Select, SelectOption import discord BRANCH = "main" class CommitsPaginatedView(PaginatedView): """Paginated view for commits""" def __init__(self, commits: List[Dict], repo_info: str): super().__init__(commits, page_size=5) self.repo_info = repo_info self.commits = commits # Add file selection button self.add_item(CommitSelectMenu(self.commits)) async def update_message(self, interaction: discord.Interaction): embed = self.create_embed() await interaction.response.edit_message(embed=embed, view=self) def create_embed(self): embed = discord.Embed( title=f"šŸ“š Commits ({self.current_page + 1}/{self.total_pages})", description=f"**Repository:** {self.repo_info}\n**Branch:** {BRANCH}", color=discord.Color.blue() ) page_data = self.get_page_data() for i, commit in enumerate(page_data, start=self.current_page * self.page_size): msg = commit['commit']['message'].split('\n')[0][:80] author = commit['commit']['author']['name'] sha = commit['sha'][:7] date = datetime.fromisoformat(commit['commit']['committer']['date'].replace('Z', '+00:00')) embed.add_field( name=f"{i+1}. `{sha}` by {author}", value=f"```{msg}```\nšŸ•’ {discord.utils.format_dt(date, 'R')}", inline=False ) embed.set_footer(text="Select a commit from the dropdown below to view details") return embed