iT邦幫忙

2024 iThome 鐵人賽

DAY 16
0
DevOps

將 AI Code Review 整進 CICD系列 第 16

將 AI Code Review 整進 CICD Day15

  • 分享至 

  • xImage
  •  

延續看 _prepare_pr_review,不太確定為啥要將 key_issues_to_review 移到最後方,但反正就是換位置。這段可以參照

https://ithelp.ithome.com.tw/upload/images/20240830/20118525SWlPlxfywS.png


# move data['review'] 'key_issues_to_review' key to the end of the dictionary
if 'key_issues_to_review' in data['review']:
    key_issues_to_review = data['review'].pop('key_issues_to_review')
    data['review']['key_issues_to_review'] = key_issues_to_review

再往下走,可以看到 code_feedback 的處理。從 prompt 可以得知 code_feedback 是從 num_code_suggestions決定是否處理的。他是 CodeSuggestion 的列表。而CodeSuggestion relevant_file, language, suggestion, relevant_line。

而決定要不要用 code_feedback,取決於pr_reviewer.inline_code_comments 設定是否為 True。如果不是則格式化文件路徑讓他好毒,並指出相關代碼行以及連結

if 'code_feedback' in data:
    code_feedback = data['code_feedback']

    # Filter out code suggestions that can be submitted as inline comments
    if get_settings().pr_reviewer.inline_code_comments:
        del data['code_feedback']
    else:
        for suggestion in code_feedback:
            if ('relevant_file' in suggestion) and (not suggestion['relevant_file'].startswith('``')):
                suggestion['relevant_file'] = f"``{suggestion['relevant_file']}``"

            if 'relevant_line' not in suggestion:
                suggestion['relevant_line'] = ''

            relevant_line_str = suggestion['relevant_line'].split('\n')[0]

            # removing '+'
            suggestion['relevant_line'] = relevant_line_str.lstrip('+').strip()

            # try to add line numbers link to code suggestions
            if hasattr(self.git_provider, 'generate_link_to_relevant_line_number'):
                link = self.git_provider.generate_link_to_relevant_line_number(suggestion)
                if link:
                    suggestion['relevant_line'] = f"[{suggestion['relevant_line']}]({link})"
            else:
                pass

{%- if num_code_suggestions > 0 %}

class PRReview(BaseModel):
    review: Review
    code_feedback: List[CodeSuggestion]
{%- else %}


上一篇
將 AI Code Review 整進 CICD Day14
下一篇
將 AI Code Review 整進 CICD Day17
系列文
將 AI Code Review 整進 CICD28
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言