diff --git a/pkgs/sdk_triage_bot/lib/src/common.dart b/pkgs/sdk_triage_bot/lib/src/common.dart index 45bd9cdc..e9b34c1a 100644 --- a/pkgs/sdk_triage_bot/lib/src/common.dart +++ b/pkgs/sdk_triage_bot/lib/src/common.dart @@ -37,9 +37,11 @@ String get geminiKey { return token; } -/// Don't return more than 4k of text for an issue body. +/// Don't return more than 5k of text for an issue body. String trimmedBody(String body) { - return body.length > 4096 ? body = body.substring(0, 4096) : body; + const textLimit = 5 * 1024; + + return body.length > textLimit ? body = body.substring(0, textLimit) : body; } class Logger { diff --git a/pkgs/sdk_triage_bot/lib/src/github.dart b/pkgs/sdk_triage_bot/lib/src/github.dart index 4f0b75a3..a6a5e081 100644 --- a/pkgs/sdk_triage_bot/lib/src/github.dart +++ b/pkgs/sdk_triage_bot/lib/src/github.dart @@ -19,8 +19,15 @@ class GithubService { return result.map((item) => item.name).toList(); } - Future fetchIssue(RepositorySlug sdkSlug, int issueNumber) async { - return await _gitHub.issues.get(sdkSlug, issueNumber); + Future fetchIssue(RepositorySlug slug, int issueNumber) async { + return await _gitHub.issues.get(slug, issueNumber); + } + + Future> fetchIssueComments( + RepositorySlug slug, Issue issue) async { + return await _gitHub.issues + .listCommentsByIssue(slug, issue.number) + .toList(); } Future createComment( @@ -145,3 +152,10 @@ GraphQLClient _initGraphQLClient() { link: auth.concat(HttpLink('https://api.github.com/graphql')), ); } + +extension IssueExtension on Issue { + /// Returns whether this issue has any comments. + /// + /// Note that the original text for the issue is returned in the `body` field. + bool get hasComments => commentsCount > 0; +} diff --git a/pkgs/sdk_triage_bot/lib/src/prompts.dart b/pkgs/sdk_triage_bot/lib/src/prompts.dart index 2b40cf4a..e363949a 100644 --- a/pkgs/sdk_triage_bot/lib/src/prompts.dart +++ b/pkgs/sdk_triage_bot/lib/src/prompts.dart @@ -5,6 +5,7 @@ String assignAreaPrompt({ required String title, required String body, + String? lastComment, }) { return ''' You are a software engineer on the Dart team at Google. You are responsible for @@ -36,6 +37,7 @@ area-web: Use area-web for Dart web related issues, including the DDC and dart2j Don't make up a new area. Don't use more than one area- label. If it's not clear which area the issue should go in, don't apply an area- label. +Take your time when considering which area to triage the issue into. If the issue is clearly a feature request, then also apply the label 'type-enhancement'. If the issue is clearly a bug report, then also apply the label 'type-bug'. @@ -48,7 +50,10 @@ Issue follows: $title -$body'''; +$body + +${lastComment ?? ''}''' + .trim(); } String summarizeIssuePrompt({ diff --git a/pkgs/sdk_triage_bot/lib/triage.dart b/pkgs/sdk_triage_bot/lib/triage.dart index e6f42e1f..94f1fa9c 100644 --- a/pkgs/sdk_triage_bot/lib/triage.dart +++ b/pkgs/sdk_triage_bot/lib/triage.dart @@ -46,6 +46,22 @@ Future triage( } logger.log(''); + // If the issue has any comments, retrieve and include the last comment in the + // prompt. + String? lastComment; + if (issue.hasComments) { + final comments = await githubService.fetchIssueComments(sdkSlug, issue); + final comment = comments.last; + + lastComment = ''' +--- + +Here is the last comment on the issue (by user @${comment.user?.login}): + +${trimmedBody(comment.body ?? '')} +'''; + } + // decide if we should triage final alreadyTriaged = labels.any((l) => l.startsWith('area-')); if (alreadyTriaged && !force) { @@ -76,7 +92,8 @@ Future triage( try { // Failures here can include things like gemini safety issues, ... classification = await geminiService.classify( - assignAreaPrompt(title: issue.title, body: bodyTrimmed), + assignAreaPrompt( + title: issue.title, body: bodyTrimmed, lastComment: lastComment), ); } on GenerativeAIException catch (e) { stderr.writeln('gemini: $e'); @@ -121,7 +138,7 @@ Future triage( logger.log(''); logger.log('---'); logger.log(''); - logger.log('Triaged ${issue.htmlUrl}.'); + logger.log('Triaged ${issue.htmlUrl}'); } List filterExistingLabels( diff --git a/pkgs/sdk_triage_bot/test/fakes.dart b/pkgs/sdk_triage_bot/test/fakes.dart index 2248043a..53e110fb 100644 --- a/pkgs/sdk_triage_bot/test/fakes.dart +++ b/pkgs/sdk_triage_bot/test/fakes.dart @@ -29,6 +29,12 @@ class GithubServiceMock implements GithubService { return returnedIssue; } + @override + Future> fetchIssueComments( + RepositorySlug slug, Issue issue) { + return Future.value([]); + } + String? updatedComment; @override