def summary_for_tag()

in devai-cli/src/devai/commands/release.py [0:0]


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

    if len(tags) == 0:
        click.echo("No tags found")
        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 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))

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

    return response