36 lines
1.3 KiB
Python
36 lines
1.3 KiB
Python
import discord
|
|
from typing import *
|
|
from discord.ui import *
|
|
|
|
from main import create_commit_embed, fetch_commit_files
|
|
from CommitsActionView import CommitActionsView
|
|
|
|
class CommitSelectMenu(Select):
|
|
"""Dropdown menu for selecting a commit"""
|
|
def __init__(self, commits: List[Dict]):
|
|
options = [
|
|
discord.SelectOption(
|
|
label=f"{commit['sha'][:7]} - {commit['commit']['message'].split('\n')[0][:45]}",
|
|
value=str(i),
|
|
description=f"by {commit['commit']['author']['name']}"
|
|
)
|
|
for i, commit in enumerate(commits[:25]) # Discord limit: 25 options
|
|
]
|
|
super().__init__(
|
|
placeholder="📝 Select a commit to view details...",
|
|
min_values=1,
|
|
max_values=1,
|
|
options=options
|
|
)
|
|
self.commits = commits
|
|
|
|
async def callback(self, interaction: discord.Interaction):
|
|
selected_idx = int(self.values[0])
|
|
commit = self.commits[selected_idx]
|
|
|
|
# Fetch file info
|
|
files = await fetch_commit_files(commit['sha'])
|
|
|
|
embed = create_commit_embed(commit, files)
|
|
view = CommitActionsView(commit, files)
|
|
await interaction.response.send_message(embed=embed, view=view, ephemeral=True) |