cleanup
This commit is contained in:
57
CommitsActionView.py
Normal file
57
CommitsActionView.py
Normal file
@@ -0,0 +1,57 @@
|
||||
from typing import Dict, List
|
||||
import discord
|
||||
from discord.ui import View, Button
|
||||
from FileBrowserSelect import FileBrowserSelect
|
||||
|
||||
class CommitActionsView(View):
|
||||
"""Action buttons for a specific commit"""
|
||||
def __init__(self, commit: Dict, files: List[Dict], timeout: int = 60):
|
||||
super().__init__(timeout=timeout)
|
||||
self.commit = commit
|
||||
self.files = files
|
||||
self.commit_sha = commit['sha']
|
||||
self.commit_short = commit['sha'][:7]
|
||||
|
||||
# Link button that opens the commit in Gitea
|
||||
link_button = Button(
|
||||
label="🔗 Open in Gitea",
|
||||
style=discord.ButtonStyle.link,
|
||||
url=commit['html_url'],
|
||||
emoji="🔗"
|
||||
)
|
||||
self.add_item(link_button)
|
||||
|
||||
# Add a file browser select if files exist
|
||||
if files:
|
||||
self.add_item(FileBrowserSelect(files, self.commit_sha))
|
||||
|
||||
@discord.ui.button(label="📊 View Diff", style=discord.ButtonStyle.primary)
|
||||
async def view_diff(self, interaction: discord.Interaction, button: Button):
|
||||
# Import here to avoid circular import with main.py
|
||||
from main import show_commit_diff_interactive
|
||||
await show_commit_diff_interactive(interaction, self.commit_sha)
|
||||
|
||||
@discord.ui.button(label="📁 Browse Files", style=discord.ButtonStyle.secondary)
|
||||
async def browse_files(self, interaction: discord.Interaction, button: Button):
|
||||
if not self.files:
|
||||
await interaction.response.send_message("No files changed in this commit.", ephemeral=True)
|
||||
return
|
||||
|
||||
embed = discord.Embed(
|
||||
title=f"📁 Files in commit `{self.commit_short}`",
|
||||
description="Select a file to view its diff:",
|
||||
color=discord.Color.blue()
|
||||
)
|
||||
|
||||
file_list = "\n".join([
|
||||
f"• `{f['filename']}` (+{f.get('additions', 0)}/-{f.get('deletions', 0)})"
|
||||
for f in self.files[:10]
|
||||
])
|
||||
if len(self.files) > 10:
|
||||
file_list += f"\n... and {len(self.files) - 10} more"
|
||||
|
||||
embed.add_field(name="Changed Files", value=file_list, inline=False)
|
||||
|
||||
view = FileBrowserSelect(self.files, self.commit_sha)
|
||||
await interaction.response.send_message(embed=embed, view=view, ephemeral=True)
|
||||
|
||||
Reference in New Issue
Block a user