From b3238e90f2d205c5920ea60ece5901e216f4d4eb Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 26 Nov 2023 08:10:01 +0200 Subject: [PATCH] s --- pr_agent/git_providers/git_provider.py | 52 ++++++++++++------- pr_agent/settings/pr_add_docs.toml | 2 +- pr_agent/settings/pr_description_prompts.toml | 9 ++-- 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/pr_agent/git_providers/git_provider.py b/pr_agent/git_providers/git_provider.py index 05122f9c..d929ed37 100644 --- a/pr_agent/git_providers/git_provider.py +++ b/pr_agent/git_providers/git_provider.py @@ -1,5 +1,6 @@ from abc import ABC, abstractmethod from dataclasses import dataclass +from pr_agent.algo.language_handler import language_extension_map # enum EDIT_TYPE (ADDED, DELETED, MODIFIED, RENAMED) from enum import Enum @@ -173,26 +174,39 @@ def get_main_pr_language(languages, files) -> str: extension_list.append(file.filename.rsplit('.')[-1]) # get the most common extension - most_common_extension = max(set(extension_list), key=extension_list.count) + most_common_extension = '.' + max(set(extension_list), key=extension_list.count) + try: + if top_language in language_extension_map and most_common_extension in language_extension_map[top_language]: + main_language_str = top_language + else: + for language, extensions in language_extension_map.items(): + if most_common_extension in extensions: + main_language_str = language + break + except Exception as e: + get_logger().exception(f"Failed to get main language: {e}") + pass - # look for a match. TBD: add more languages, do this systematically - if most_common_extension == 'py' and top_language == 'python' or \ - most_common_extension == 'js' and top_language == 'javascript' or \ - most_common_extension == 'ts' and top_language == 'typescript' or \ - most_common_extension == 'go' and top_language == 'go' or \ - most_common_extension == 'java' and top_language == 'java' or \ - most_common_extension == 'c' and top_language == 'c' or \ - most_common_extension == 'cpp' and top_language == 'c++' or \ - most_common_extension == 'cs' and top_language == 'c#' or \ - most_common_extension == 'swift' and top_language == 'swift' or \ - most_common_extension == 'php' and top_language == 'php' or \ - most_common_extension == 'rb' and top_language == 'ruby' or \ - most_common_extension == 'rs' and top_language == 'rust' or \ - most_common_extension == 'scala' and top_language == 'scala' or \ - most_common_extension == 'kt' and top_language == 'kotlin' or \ - most_common_extension == 'pl' and top_language == 'perl' or \ - most_common_extension == top_language: - main_language_str = top_language + ## old approach: + # most_common_extension = max(set(extension_list), key=extension_list.count) + # if most_common_extension == 'py' and top_language == 'python' or \ + # most_common_extension == 'js' and top_language == 'javascript' or \ + # most_common_extension == 'ts' and top_language == 'typescript' or \ + # most_common_extension == 'tsx' and top_language == 'typescript' or \ + # most_common_extension == 'go' and top_language == 'go' or \ + # most_common_extension == 'java' and top_language == 'java' or \ + # most_common_extension == 'c' and top_language == 'c' or \ + # most_common_extension == 'cpp' and top_language == 'c++' or \ + # most_common_extension == 'cs' and top_language == 'c#' or \ + # most_common_extension == 'swift' and top_language == 'swift' or \ + # most_common_extension == 'php' and top_language == 'php' or \ + # most_common_extension == 'rb' and top_language == 'ruby' or \ + # most_common_extension == 'rs' and top_language == 'rust' or \ + # most_common_extension == 'scala' and top_language == 'scala' or \ + # most_common_extension == 'kt' and top_language == 'kotlin' or \ + # most_common_extension == 'pl' and top_language == 'perl' or \ + # most_common_extension == top_language: + # main_language_str = top_language except Exception as e: get_logger().exception(e) diff --git a/pr_agent/settings/pr_add_docs.toml b/pr_agent/settings/pr_add_docs.toml index 31b7195c..ffb7d01d 100644 --- a/pr_agent/settings/pr_add_docs.toml +++ b/pr_agent/settings/pr_add_docs.toml @@ -103,7 +103,7 @@ Description: '{{description}}' {%- if language %} -Main language: {{language}} +Main PR language: '{{language}}' {%- endif %} diff --git a/pr_agent/settings/pr_description_prompts.toml b/pr_agent/settings/pr_description_prompts.toml index 2a51b324..f1633e46 100644 --- a/pr_agent/settings/pr_description_prompts.toml +++ b/pr_agent/settings/pr_description_prompts.toml @@ -2,8 +2,8 @@ system="""You are CodiumAI-PR-Reviewer, a language model designed to review git pull requests. Your task is to provide full description of a Pull Request (PR) content. - Make sure to focus on the new PR code (the '+' lines). -- Notice that the 'Previous title', 'Previous description' and 'Commit messages' sections may be partial, simplistic, non-informative or not up-to-date. Hence, compare them to the PR diff code, and use them only as a reference. -- Emphasize first the most important changes, and then the less important ones. +- Keep in mind that the 'Previous title', 'Previous description' and 'Commit messages' sections may be partial, simplistic, non-informative or out of date. Hence, compare them to the PR diff code, and use them only as a reference. +- Prioritize the most significant changes first, followed by the minor ones. - If needed, each YAML output should be in block scalar format ('|-') {%- if extra_instructions %} @@ -68,12 +68,15 @@ Answer should be a valid YAML, and nothing else. Each YAML output MUST be after """ user="""PR Info: + Previous title: '{{title}}' + Previous description: '{{description}}' + Branch: '{{branch}}' {%- if language %} -Main language: {{language}} +Main PR language: '{{ language }}' {%- endif %} {%- if commit_messages_str %}