Skip to content

Commit

Permalink
Release command updates (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgrant authored Mar 4, 2024
1 parent 8a0390d commit ccc409b
Showing 1 changed file with 69 additions and 49 deletions.
118 changes: 69 additions & 49 deletions outer-loop-cli/src/devai/commands/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import click
import sys
from devai.util.file_processor import format_files_as_string, list_files, list_changes, list_commit_messages, list_commits_for_branches, list_tags, list_commits_for_tags
from vertexai.language_models import CodeChatModel

Expand All @@ -22,7 +23,7 @@
"temperature": 0.2
}

source='''
source = '''
GIT DIFFS:
{}
Expand All @@ -33,7 +34,7 @@
{}
'''
qry='''
report_qry = '''
INSTRUCTIONS:
You are senior software engineer doing a code review. You are given following information:
GIT DIFFS - new code changes
Expand All @@ -49,98 +50,117 @@
GIT COMMITS show the commit messages provided by developer that you can use for extra context.
Using this pattern, analyze provided GIT DIFFS, GIT COMMITS and FINAL CODE section and write user friendly explanation about what has changed in several sentences with bullet points.
Only write explanation for new code changes and not for othe code in the FINAL CODE section.
Using this pattern, analyze provided GIT DIFFS, GIT COMMITS and FINAL CODE section
and write explanation for internal company change management about what has changed in several sentences with bullet points.
Use professional tone for explanation.
Only write explanation for new code changes and not for existing code in the FINAL CODE section.
'''

@click.command(name="notes_user")
@click.option('-s', '--branch_a', required=True, type=str)
@click.option('-e', '--branch_b', required=True, type=str)
def notes_user(branch_a, branch_b):
click.echo('notes_user')
click.echo(f'branch_a={branch_a}')
click.echo(f'branch_b={branch_b}')
user_notes_qry = '''
INSTRUCTIONS:
You are senior software engineer doing a code review. You are given following information:
GIT DIFFS - new code changes
GIT COMMITS - developer written comments for new code changes
FINAL CODE - final version of the source code
GIT DIFFS show lines added and removed with + and - indicators.
Here's an example:
This line shows that code was changed/removed from the FINAL CODE section:
- return f"file: source: [Binary File - Not ASCII Text]"
This line shows that code was changed/added in the FINAL CODE section:
+ # return f"file: source: [Binary File - Not ASCII Text]
list = list_commits_for_branches(branch_a, branch_b)
start_sha = list[len(list)-1]

if len(list) == 1:
start_sha = branch_a
print("set start_sha to branch")
GIT COMMITS show the commit messages provided by developer that you can use for extra context.

end_sha = list[0]
Using this pattern, analyze provided GIT DIFFS, GIT COMMITS and FINAL CODE section
and write end user summary about what has changed in several sentences with bullet points.
Use user humorous tone for explanation. MUST INCLUDE ONE JOKE
Only write explanation for new code changes and not for existing code in the FINAL CODE section.
'''

# This flag will enable usage of ^ operator
# this allows refer to the parent of a commit / include start commit in git operations(diff, log)
refer_commit_parent = True
files = list_files(start_sha, end_sha, refer_commit_parent)

changes = list_changes(start_sha, end_sha, refer_commit_parent)
commit_messages = list_commit_messages(start_sha, end_sha, refer_commit_parent)

prompt_context = source.format(changes, commit_messages, format_files_as_string(files))
@click.command(name="report")
@click.option('-t', '--tag', required=True, type=str)
def report(tag):
click.echo('report')
click.echo(f'tag={tag}')

response = summary_for_tag(tag, report_qry)

code_chat_model = CodeChatModel.from_pretrained("codechat-bison")
chat = code_chat_model.start_chat(context=prompt_context, **parameters)
response = chat.send_message(qry)
click.echo(f"Response from Model:\n{response.text}")

click.echo(f"Response from Model: {response.text}")

@click.command(name="notes_user_tag")
@click.command(name="notes")
@click.option('-t', '--tag', required=True, type=str)
def notes_user_tag(tag):
click.echo('notes_user_tag')
def notes(tag):
click.echo('notes')
click.echo(f'tag={tag}')

response = summary_for_tag(tag, user_notes_qry)

click.echo(f"Response from Model:\n{response.text}")


def check_if_string_is_in_list(string, list):
for item in list:
if string == item:
return True

return False


def summary_for_tag(tag, qry):
tags = list_tags()

if len(tags) == 0:
click.echo("No tags found")
return

sys.exit()

if not check_if_string_is_in_list(tag, tags):
click.echo(f"Tag {tag} does not exist. Existing tags: {tags}")
sys.exit()

previous_tag = ""
list = []

refer_commit_parent = False
if len(tags) == 1:
if len(tags) == 1 or tag == tags[0]:
list = list_commits_for_tags(tag, "HEAD")
else:
refer_commit_parent = True
for i in range(len(tags)):
if tags[i] == tag:
previous_tag = tags[i-1]

list = list_commits_for_branches(previous_tag, tag)

start_sha = list[len(list)-1]

if len(list) == 1:
start_sha = previous_tag

end_sha = list[0]

files = list_files(start_sha, end_sha, refer_commit_parent)

changes = list_changes(start_sha, end_sha, refer_commit_parent)

commit_messages = list_commit_messages(start_sha, end_sha, refer_commit_parent)

prompt_context = source.format(changes, commit_messages, format_files_as_string(files))
commit_messages = list_commit_messages(
start_sha, end_sha, refer_commit_parent)

prompt_context = source.format(
changes, commit_messages, format_files_as_string(files))

code_chat_model = CodeChatModel.from_pretrained("codechat-bison")
chat = code_chat_model.start_chat(context=prompt_context, **parameters)
response = chat.send_message(qry)

click.echo(f"Response from Model: {response.text}")
return response


@click.group()
def release():
pass

release.add_command(notes_user)
release.add_command(notes_user_tag)

release.add_command(report)
release.add_command(notes)

0 comments on commit ccc409b

Please sign in to comment.