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

add summary only flag #114

Merged
merged 2 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,28 @@ Thumbs.db
__tests__/runner/*
lib/**/*

### Tags
# Ignore tags created by etags, ctags, gtags (GNU global) and cscope
TAGS
.TAGS
!TAGS/
tags
.tags
!tags/
gtags.files
GTAGS
GRTAGS
GPATH
GSYMS
cscope.files
cscope.out
cscope.in.out
cscope.po.out
tags.temp
tags.lock


# Local testing
.env
.secrets
bin/act

4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ inputs:
!**/_gen/**
!**/generated/**
!**/vendor/**
summary_only:
required: false
description: 'Only provide the summary and skip the code review.'
default: 'false'
openai_light_model:
required: false
description:
Expand Down
37 changes: 22 additions & 15 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {codeReview} from './review.js'
async function run(): Promise<void> {
const options: Options = new Options(
core.getBooleanInput('debug'),
core.getBooleanInput('summary_only'),
core.getInput('max_files_to_summarize'),
core.getInput('max_files_to_review'),
core.getBooleanInput('review_comment_lgtm'),
Expand Down Expand Up @@ -37,10 +38,7 @@ async function run(): Promise<void> {
try {
lightBot = new Bot(
options,
new OpenAIOptions(
options.openai_light_model,
options.summary_token_limits
)
new OpenAIOptions(options.openai_light_model, options.light_token_limits)
)
} catch (e: any) {
core.warning(
Expand All @@ -53,7 +51,7 @@ async function run(): Promise<void> {
try {
heavyBot = new Bot(
options,
new OpenAIOptions(options.openai_heavy_model, options.review_token_limits)
new OpenAIOptions(options.openai_heavy_model, options.heavy_token_limits)
)
} catch (e: any) {
core.warning(
Expand Down
16 changes: 10 additions & 6 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export class OpenAIOptions {

export class Options {
debug: boolean
summary_only: boolean
max_files_to_summarize: number
max_files_to_review: number
review_comment_lgtm: boolean
Expand All @@ -191,11 +192,12 @@ export class Options {
openai_retries: number
openai_timeout_ms: number
openai_concurrency_limit: number
summary_token_limits: TokenLimits
review_token_limits: TokenLimits
light_token_limits: TokenLimits
heavy_token_limits: TokenLimits

constructor(
debug: boolean,
summary_only: boolean,
max_files_to_summarize = '40',
max_files_to_review = '0',
review_comment_lgtm = false,
Expand All @@ -209,6 +211,7 @@ export class Options {
openai_concurrency_limit = '4'
) {
this.debug = debug
this.summary_only = summary_only
this.max_files_to_summarize = parseInt(max_files_to_summarize)
this.max_files_to_review = parseInt(max_files_to_review)
this.review_comment_lgtm = review_comment_lgtm
Expand All @@ -220,13 +223,14 @@ export class Options {
this.openai_retries = parseInt(openai_retries)
this.openai_timeout_ms = parseInt(openai_timeout_ms)
this.openai_concurrency_limit = parseInt(openai_concurrency_limit)
this.summary_token_limits = new TokenLimits(openai_light_model)
this.review_token_limits = new TokenLimits(openai_heavy_model)
this.light_token_limits = new TokenLimits(openai_light_model)
this.heavy_token_limits = new TokenLimits(openai_heavy_model)
}

// print all options using core.info
print(): void {
core.info(`debug: ${this.debug}`)
core.info(`summary_only: ${this.summary_only}`)
core.info(`max_files_to_summarize: ${this.max_files_to_summarize}`)
core.info(`max_files_to_review: ${this.max_files_to_review}`)
core.info(`review_comment_lgtm: ${this.review_comment_lgtm}`)
Expand All @@ -238,8 +242,8 @@ export class Options {
core.info(`openai_retries: ${this.openai_retries}`)
core.info(`openai_timeout_ms: ${this.openai_timeout_ms}`)
core.info(`openai_concurrency_limit: ${this.openai_concurrency_limit}`)
core.info(`summary_token_limits: ${this.summary_token_limits.string()}`)
core.info(`review_token_limits: ${this.review_token_limits.string()}`)
core.info(`summary_token_limits: ${this.light_token_limits.string()}`)
core.info(`review_token_limits: ${this.heavy_token_limits.string()}`)
}

check_path(path: string): boolean {
Expand Down
4 changes: 2 additions & 2 deletions src/review-comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export const handleReviewComment = async (
if (file_content.length > 0) {
const file_content_tokens = tokenizer.get_token_count(file_content)
if (
file_content_tokens < options.review_token_limits.extra_content_tokens
file_content_tokens < options.heavy_token_limits.extra_content_tokens
) {
inputs.file_content = file_content
}
Expand All @@ -150,7 +150,7 @@ export const handleReviewComment = async (
}
const file_diff_tokens = tokenizer.get_token_count(file_diff)
if (
file_diff_tokens < options.review_token_limits.extra_content_tokens
file_diff_tokens < options.heavy_token_limits.extra_content_tokens
) {
inputs.file_diff = file_diff
}
Expand Down
11 changes: 8 additions & 3 deletions src/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export const codeReview = async (
if (file_content.length > 0) {
if (
tokenizer.get_token_count(file_content) <
options.summary_token_limits.extra_content_tokens
options.light_token_limits.extra_content_tokens
) {
ins.file_content = file_content
}
Expand All @@ -163,7 +163,7 @@ export const codeReview = async (

if (
!ins.file_diff ||
file_diff_tokens < options.summary_token_limits.extra_content_tokens
file_diff_tokens < options.light_token_limits.extra_content_tokens
) {
// summarize content
try {
Expand Down Expand Up @@ -292,6 +292,11 @@ ${
}
}

if (options.summary_only === true) {
core.info('summary_only is true, exiting')
return
}

const review = async (
filename: string,
file_content: string,
Expand All @@ -305,7 +310,7 @@ ${
if (file_content.length > 0) {
const file_content_tokens = tokenizer.get_token_count(file_content)
if (
file_content_tokens < options.review_token_limits.extra_content_tokens
file_content_tokens < options.heavy_token_limits.extra_content_tokens
) {
ins.file_content = file_content
} else {
Expand Down