Skip to content

feat: Add line-specific comments functionality #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

gary-van-woerkens
Copy link
Contributor

No description provided.

@gary-van-woerkens gary-van-woerkens marked this pull request as draft April 25, 2025 22:29
Copy link

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedzod@​3.24.310010010096100

View full report

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarQube Cloud

Copy link
Contributor

@RealVidy RealVidy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Très cool si ça fonctionne ça !

J'ai fait pas mal de commentaires mais dans l'ensemble je suis aligné. Merci !

- A comprehensive overall summary of the PR in the "summary" field
- Multiple specific comments targeting different issues with accurate file paths and line numbers
- Detailed explanations in each comment's body
- Code suggestions where appropriate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Il faut peut-être lui fournir un exemple de "code suggestion" parce que c'est dépendant de la plateforme où est faite la PR. Pas sûr que gitlab et github utilisent le même format en gros.

Là comme on lui dit pas que c'est du github en plus, il va pas forcément savoir quoi faire.

// Extract response from tool use
// Find content blocks that are tool_use type
for (const content of message.content) {
if (content.type === 'tool_use') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si c'est pas content.type === 'tool_use' on veut peut-être log une erreur ou un warning ?

Aussi, je viens de voir le fallback à partir de la ligne 94. Je me suis fait un peu surprendre parce que je me serait attendu à voir le fallback direct dans cette premier boucle sur les message.content.

Là on fait 2 boucles, ce qui n'est pas bien grave mais qui est (je trouve) inattendu.

// Find content blocks that are tool_use type
for (const content of message.content) {
if (content.type === 'tool_use') {
if (content.name === 'provide_code_review' && content.input) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pareil ici, si il nous fait utiliser un outil qui n'existe pas ou que input est vide, on peut peut-être log ça.

Aussi, provide_code_review devrait peut-être venir d'un enum de tools histoire de rendre les changements de noms de tools plus simple ? J'ai pas d'énorme conviction là dessus, je trouve juste que c'est un poil plus propre, je te laisse décider.

content: prompt
}
],
tools: [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je me dis que ça pourrait être bien d'avoir un tool utils capable de construire un objet JSON "anthropicToolDefinition" (ou openAI, Mistral, LLaMa plus tard) automatiquement. Sinon on va devoir réécrire et maintenir cet objet dans chaque sender qui communique avec anthropic et dès qu'un tool va changer un peu ça risque de devenir embêtant à maintenir et source d'erreurs.

On peut commencer simple avec une fonction qui renvoie simplement :

{
        name: 'provide_code_review',
        description:
          'Provide structured code review with line-specific comments',
        [Reste de l'objet...]
}

Comment on lines +4 to +12
interface CodeReviewResponse {
summary: string
comments: Array<{
path: string
line: number
body: string
suggestion?: string
}>
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je pense que j'aurais plutôt mis ça dans le même fichier que le tool "provide_code_review" vu que c'est lié à ça plutôt qu'au lineCommentsSender, non ?

* @param prompt - The prompt to send to Anthropic
* @returns The text response from Anthropic
*/
export async function defaultSender(prompt: string): Promise<string> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'ai fait un commentaire plus bas qui permettrait d'éliminer ce defaultSender et de le remplacer par un "anthropicSender" avec les "tools" en paramètre optionnel.

// Schémas de validation pour garantir le bon format de la réponse
const CommentSchema = z.object({
path: z.string(),
line: z.number().int().positive(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je flag ça juste une fois maintenant : Là on bosse sur une seule ligne mais est-ce qu'on voudra mettre le temps nécessaire à la gestion d'un interval de lignes plutôt qu'une seule ?

Si oui, ça peut valoir le coup de prévoir des maintenant une "startLine" et une "endLine" peut-être ?


if (!validationResult.success) {
console.error(
"Validation de l'analyse échouée:",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Il devrait y avoir une espace avant et après le ":" en français.

Comment on lines +114 to +129
const existingSummary = await findExistingSummaryComment(context, prNumber)
if (existingSummary) {
// Update existing summary
await context.octokit.issues.updateComment({
...repo,
comment_id: existingSummary.id,
body: formattedSummary
})
} else {
// Create new summary
await context.octokit.issues.createComment({
...repo,
issue_number: prNumber,
body: formattedSummary
})
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le summary comment c'est la même chose que le global comment finalement non ? Est-ce qu'on réécrit pas du code pour rien ici par conséquent ?

repositoryUrl: string,
branch: string,
templatePath?: string,
token?: string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si c'est un "githubAccessToken" autant l'appeler comme ça pour être clair peut-être ?

@gary-van-woerkens gary-van-woerkens linked an issue Apr 28, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inline comments
2 participants