Skip to content
This repository was archived by the owner on Mar 6, 2024. It is now read-only.

Commit fe67bb5

Browse files
authored
add summary only flag (#114)
1 parent 8107663 commit fe67bb5

File tree

7 files changed

+70
-32
lines changed

7 files changed

+70
-32
lines changed

.gitignore

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,28 @@ Thumbs.db
9898
__tests__/runner/*
9999
lib/**/*
100100

101+
### Tags
102+
# Ignore tags created by etags, ctags, gtags (GNU global) and cscope
103+
TAGS
104+
.TAGS
105+
!TAGS/
106+
tags
107+
.tags
108+
!tags/
109+
gtags.files
110+
GTAGS
111+
GRTAGS
112+
GPATH
113+
GSYMS
114+
cscope.files
115+
cscope.out
116+
cscope.in.out
117+
cscope.po.out
118+
tags.temp
119+
tags.lock
120+
121+
101122
# Local testing
102123
.env
103124
.secrets
104125
bin/act
105-

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ inputs:
5353
!**/_gen/**
5454
!**/generated/**
5555
!**/vendor/**
56+
summary_only:
57+
required: false
58+
description: 'Only provide the summary and skip the code review.'
59+
default: 'false'
5660
openai_light_model:
5761
required: false
5862
description:

dist/index.js

Lines changed: 22 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {codeReview} from './review.js'
77
async function run(): Promise<void> {
88
const options: Options = new Options(
99
core.getBooleanInput('debug'),
10+
core.getBooleanInput('summary_only'),
1011
core.getInput('max_files_to_summarize'),
1112
core.getInput('max_files_to_review'),
1213
core.getBooleanInput('review_comment_lgtm'),
@@ -37,10 +38,7 @@ async function run(): Promise<void> {
3738
try {
3839
lightBot = new Bot(
3940
options,
40-
new OpenAIOptions(
41-
options.openai_light_model,
42-
options.summary_token_limits
43-
)
41+
new OpenAIOptions(options.openai_light_model, options.light_token_limits)
4442
)
4543
} catch (e: any) {
4644
core.warning(
@@ -53,7 +51,7 @@ async function run(): Promise<void> {
5351
try {
5452
heavyBot = new Bot(
5553
options,
56-
new OpenAIOptions(options.openai_heavy_model, options.review_token_limits)
54+
new OpenAIOptions(options.openai_heavy_model, options.heavy_token_limits)
5755
)
5856
} catch (e: any) {
5957
core.warning(

src/options.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ export class OpenAIOptions {
180180

181181
export class Options {
182182
debug: boolean
183+
summary_only: boolean
183184
max_files_to_summarize: number
184185
max_files_to_review: number
185186
review_comment_lgtm: boolean
@@ -191,11 +192,12 @@ export class Options {
191192
openai_retries: number
192193
openai_timeout_ms: number
193194
openai_concurrency_limit: number
194-
summary_token_limits: TokenLimits
195-
review_token_limits: TokenLimits
195+
light_token_limits: TokenLimits
196+
heavy_token_limits: TokenLimits
196197

197198
constructor(
198199
debug: boolean,
200+
summary_only: boolean,
199201
max_files_to_summarize = '40',
200202
max_files_to_review = '0',
201203
review_comment_lgtm = false,
@@ -209,6 +211,7 @@ export class Options {
209211
openai_concurrency_limit = '4'
210212
) {
211213
this.debug = debug
214+
this.summary_only = summary_only
212215
this.max_files_to_summarize = parseInt(max_files_to_summarize)
213216
this.max_files_to_review = parseInt(max_files_to_review)
214217
this.review_comment_lgtm = review_comment_lgtm
@@ -220,13 +223,14 @@ export class Options {
220223
this.openai_retries = parseInt(openai_retries)
221224
this.openai_timeout_ms = parseInt(openai_timeout_ms)
222225
this.openai_concurrency_limit = parseInt(openai_concurrency_limit)
223-
this.summary_token_limits = new TokenLimits(openai_light_model)
224-
this.review_token_limits = new TokenLimits(openai_heavy_model)
226+
this.light_token_limits = new TokenLimits(openai_light_model)
227+
this.heavy_token_limits = new TokenLimits(openai_heavy_model)
225228
}
226229

227230
// print all options using core.info
228231
print(): void {
229232
core.info(`debug: ${this.debug}`)
233+
core.info(`summary_only: ${this.summary_only}`)
230234
core.info(`max_files_to_summarize: ${this.max_files_to_summarize}`)
231235
core.info(`max_files_to_review: ${this.max_files_to_review}`)
232236
core.info(`review_comment_lgtm: ${this.review_comment_lgtm}`)
@@ -238,8 +242,8 @@ export class Options {
238242
core.info(`openai_retries: ${this.openai_retries}`)
239243
core.info(`openai_timeout_ms: ${this.openai_timeout_ms}`)
240244
core.info(`openai_concurrency_limit: ${this.openai_concurrency_limit}`)
241-
core.info(`summary_token_limits: ${this.summary_token_limits.string()}`)
242-
core.info(`review_token_limits: ${this.review_token_limits.string()}`)
245+
core.info(`summary_token_limits: ${this.light_token_limits.string()}`)
246+
core.info(`review_token_limits: ${this.heavy_token_limits.string()}`)
243247
}
244248

245249
check_path(path: string): boolean {

src/review-comment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export const handleReviewComment = async (
137137
if (file_content.length > 0) {
138138
const file_content_tokens = tokenizer.get_token_count(file_content)
139139
if (
140-
file_content_tokens < options.review_token_limits.extra_content_tokens
140+
file_content_tokens < options.heavy_token_limits.extra_content_tokens
141141
) {
142142
inputs.file_content = file_content
143143
}
@@ -150,7 +150,7 @@ export const handleReviewComment = async (
150150
}
151151
const file_diff_tokens = tokenizer.get_token_count(file_diff)
152152
if (
153-
file_diff_tokens < options.review_token_limits.extra_content_tokens
153+
file_diff_tokens < options.heavy_token_limits.extra_content_tokens
154154
) {
155155
inputs.file_diff = file_diff
156156
}

src/review.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export const codeReview = async (
147147
if (file_content.length > 0) {
148148
if (
149149
tokenizer.get_token_count(file_content) <
150-
options.summary_token_limits.extra_content_tokens
150+
options.light_token_limits.extra_content_tokens
151151
) {
152152
ins.file_content = file_content
153153
}
@@ -163,7 +163,7 @@ export const codeReview = async (
163163

164164
if (
165165
!ins.file_diff ||
166-
file_diff_tokens < options.summary_token_limits.extra_content_tokens
166+
file_diff_tokens < options.light_token_limits.extra_content_tokens
167167
) {
168168
// summarize content
169169
try {
@@ -292,6 +292,11 @@ ${
292292
}
293293
}
294294

295+
if (options.summary_only === true) {
296+
core.info('summary_only is true, exiting')
297+
return
298+
}
299+
295300
const review = async (
296301
filename: string,
297302
file_content: string,
@@ -305,7 +310,7 @@ ${
305310
if (file_content.length > 0) {
306311
const file_content_tokens = tokenizer.get_token_count(file_content)
307312
if (
308-
file_content_tokens < options.review_token_limits.extra_content_tokens
313+
file_content_tokens < options.heavy_token_limits.extra_content_tokens
309314
) {
310315
ins.file_content = file_content
311316
} else {

0 commit comments

Comments
 (0)