当前位置:网站首页>Hi, you have a code review strategy to check!
Hi, you have a code review strategy to check!
2022-06-28 01:43:00 【InfoQ】
Introduce
- The method is too long , Write the whole logic in a method , No necessary abstraction and encapsulation .
- Methods do not need to be commented , The method name is not literal yet .
- After the file is opened , Forget to close the workflow .
Component is introduced
- checkstyle Official documents
- SonarQube Official documents
The overall use process

- Coder Submit your own code to the code repository , launch Merge Request.
- The code warehouse calls the build hook , Trigger the wood building process .
- Jianmu pulls the code from the warehouse , Conduct checkstyle and SonarQube Static code scan .
- Jianmu will scan the results , In the form of comments , Write back to Merge Request In the comments .
- Reviewer start-up , Refer to the scan results , Conduct Code Review.
How to build
- Transform the project itself , Introduce in the project checkstyle and SonarQube plug-in unit , And complete the configuration . About checkstyle and sonarqube The configuration and use of can be referred to :checkstyle Official documentsSonarQube Official documents
- Start to prepare the Jianmu nodes we need to use 🤪
- git-clone node ( official :https://jianmuhub.com/_/git_clone)

- maven node ( official :https://jianmuhub.com/_/maven_build)

- check_style node ( Customize :https://jianmuhub.com/weizhongyuan/check_style)

- sonarqube-analysis node ( Customize :https://jianmuhub.com/fat_squirrel/sonarqube_analysis)

- git_merge_comment node ( Customize :https://jianmuhub.com/weizhongyuan/git_merge_comment)

- Enterprise wechat notification node ( official :https://jianmuhub.com/_/qywx_notice)

- Then write DSL file
name: java-style-check
# Can be executed concurrently
global:
concurrent: true
trigger:
type: webhook
param:
- name: action
type: STRING
exp: $.body.json.object_attributes.action
- name: object_kind
type: STRING
exp: $.body.json.object_kind
- name: user_name
type: STRING
exp: $.body.json.object_attributes.last_commit.author.name
- name: project_name
type: STRING
exp: $.body.json.project.name
- name: source_branch
type: STRING
exp: $.body.json.object_attributes.source_branch
- name: target_branch
type: STRING
exp: $.body.json.object_attributes.target_branch
- name: remote_url
type: STRING
exp: $.body.json.project.git_http_url
- name: git_host
type: STRING
exp: $.header.x-real-ip
- name: project_id
type: STRING
exp: $.body.json.project.id
- name: iid
type: STRING
exp: $.body.json.object_attributes.iid
# webhook event One merge event open、update、reopen Can trigger the process
only: (${trigger.object_kind} == "merge_request" && ${trigger.action} == "open" || ${trigger.action} == "update" || ${trigger.action} == "reopen")
workflow:
start:
type: start
targets:
- git_source_branch
- git_target_branch
# Source branch
git_source_branch:
type: "git_clone:1.1.1"
sources:
- start
targets:
- maven1
param:
remote_url: "${trigger.remote_url}"
ref: "refs/heads/${trigger.source_branch}"
netrc_password: "((gitlab.password))"
netrc_machine: "x.x.x.x"
netrc_username: "((gitlab.username))"
# adopt mvn command , Use code specification checking tools check-style Check source branch , Generate specification result file
# adopt mvn command , Use the code defect checking tool sonarqube To check the code , And upload the results to the server
maven1:
type: "jianmu/maven:jdk"
sources:
- git_source_branch
targets:
- sonarqube_analysis
param:
mvn_action: "compile sonar:sonar clean checkstyle:checkstyle-aggregate"
workspace: "${git_source_branch.git_path}"
maven_public_id: "maven-releases"
maven_public_url: "http://x.x.x.x:8081/repository/maven-public/"
# Get the new code BUG And the number of new vulnerabilities , And get sonarqube Deployment address of
sonarqube_analysis:
sources:
- maven1
targets:
- check_style
type: "fat_squirrel/sonarqube_analysis:v2"
param:
ip: "x.x.x.x:9000"
project_name: "name"
# Target branch
git_target_branch:
type: "git_clone:1.2.2"
sources:
- start
targets:
- maven2
param:
remote_url: "${trigger.remote_url}"
ref: "refs/heads/${trigger.target_branch}"
password: "((gitlab.password))"
username: "((gitlab.username))"
# Use code specification checking tools check-style Check the target branch , Generate specification result file
maven2:
type: "maven_build:1.3.1-jdk"
sources:
- git_target_branch
targets:
- check_style
param:
mvn_action: "checkstyle:checkstyle-aggregate"
workspace: "${git_target_branch.git_path}"
maven_public_id: "maven-releases"
maven_public_url: "http://172.16.35.15:8081/repository/maven-public/"
# Get the specification result files of the source branch and the target branch from the shared directory for comparison
check_style:
sources:
- sonarqube_analysis
- maven2
targets:
- condition
type: "jianmu/check_style:v3"
param:
file2: "${git_target_branch.git_path}/target/checkstyle-result.xml"
file1: "${git_source_branch.git_path}/target/checkstyle-result.xml"
# Judge nodes , Take different branches
condition:
sources:
- check_style
type: condition
expression: ${check_style.result}=="1"
cases:
true: qywx_notice
false: condition2
qywx_notice:
type: "qywx_notice:1.2.1"
sources:
- condition
targets:
- git_merge_comment1
param:
mentioned_mobile_list: "[]"
bot_webhook_url: "((chatbot.merge))"
text_content: " project :${trigger.project_name}, submitter :${trigger.user_name}, news : In this submission, the number of non conformities has been increased :${check_style.diff}"
msgtype: "text"
mentioned_list: "[]"
git_merge_comment1:
type: "jianmu/git_merge_comment:v1"
sources:
- qywx_notice
targets:
- end
param:
project_id: "${trigger.project_id}"
host: "${trigger.git_host}"
comment: "action:${trigger.action}, project :${trigger.project_name}, submitter :${trigger.user_name}, news : This consolidation adds ${check_style.diff} A format problem , newly added ${sonarqube_analysis.new_bugs} individual bug Wind addition , newly added ${sonarqube_analysis.new_vulnerabilities} Vulnerability issues , Details visible :'${sonarqube_analysis.url}'"
merge_request_iid: "${trigger.iid}"
token: "((AUTOOPS.private_token))"
condition2:
sources:
- condition
type: condition
expression: ${check_style.result}=="0"
cases:
true: qywx_notice2
false: qywx_notice3
qywx_notice2:
type: "qywx_notice:1.2.1"
sources:
- condition2
targets:
- git_merge_comment2
param:
mentioned_mobile_list: "[]"
bot_webhook_url: "((chatbot.merge))"
text_content: " project :${trigger.project_name}, submitter :${trigger.user_name}, news : This submission is not much , Just right !"
msgtype: "text"
mentioned_list: "[]"
git_merge_comment2:
type: "jianmu/git_merge_comment:v1"
sources:
- qywx_notice2
targets:
- end
param:
project_id: "${trigger.project_id}"
host: "${trigger.git_host}"
comment: "action:${trigger.action}, project :${trigger.project_name}, submitter :${trigger.user_name}, news : There is no new format problem in this consolidation , newly added ${sonarqube_analysis.new_bugs} individual bug Wind addition , newly added ${sonarqube_analysis.new_vulnerabilities} Vulnerability issues , Details visible :'${sonarqube_analysis.url}'"
merge_request_iid: "${trigger.iid}"
token: "((AUTOOPS.private_token))"
qywx_notice3:
type: "qywx_notice:1.2.1"
sources:
- condition2
targets:
- git_merge_comment3
param:
mentioned_mobile_list: "[]"
bot_webhook_url: "((chatbot.merge))"
text_content: " project :${trigger.project_name}, submitter :${trigger.user_name}, news : This submission reduces the number of non conformities :${check_style.diff}"
msgtype: "text"
mentioned_list: "[]"
git_merge_comment3:
type: "jianmu/git_merge_comment:v1"
sources:
- qywx_notice3
targets:
- end
param:
project_id: "${trigger.project_id}"
host: "${trigger.git_host}"
comment: "action:${trigger.action}, project :${trigger.project_name}, submitter :${trigger.user_name}, news : This merger has decreased ${check_style.diff} A format problem , newly added ${sonarqube_analysis.new_bugs} individual bug Wind addition , newly added ${sonarqube_analysis.new_vulnerabilities} Vulnerability issues , Details visible :'${sonarqube_analysis.url}'"
merge_request_iid: "${trigger.iid}"
token: "((AUTOOPS.private_token))"
end:
type: end
sources:
- git_merge_comment1
- git_merge_comment2
- git_merge_comment3

- Trigger process
- Result display

ending
边栏推荐
- 向excel中导入mysql中的数据表
- [embedded foundation] serial port communication
- What is the e-commerce conversion rate so abstract?
- Deepmind | pre training of molecular property prediction through noise removal
- 自监督学习与药物发现
- golang 猴子吃桃子,求第一天桃子的数量
- Set collection usage
- The number of nodes of a complete binary tree [non-O (n) solution > Abstract dichotomy]
- 评价——灰色关联分析
- 【牛客讨论区】第四章:Redis
猜你喜欢
SPuG - lightweight automatic operation and maintenance platform
Review of drug discovery-03-molecular design and optimization
【MySQL】-【函数】
美团动态线程池实践思路已开源
Chapitre 4: redis
声网 VQA:将实时互动中未知的视频画质用户主观体验变可知
Adobe Premiere Basics - general operations for editing material files (offline files, replacing materials, material labels and grouping, material enabling, convenient adjustment of opacity, project pa
LMSOC:一种对社会敏感的预训练方法
MapReduce elementary programming practice
How about the market application strength of large-size conductive slip rings
随机推荐
Lodash realizes anti shake and throttling functions and native implementation
无人机专用滑环定制要求是什么
Review of drug discovery-03-molecular design and optimization
How to read a paper
Interviewer asked: Inheritance of JS
Intensive reading of transformer thesis paragraph by paragraph
Adobe Premiere Basics - common video effects (cropping, black and white, clip speed, mirroring, lens halo) (XV)
Review of drug discovery-02-prediction of molecular properties
Adobe Premiere基础-常用的视频特效(边角定位,马赛克,模糊,锐化,手写工具,效果控件层级顺序)(十六)
What are the requirements for customizing the slip ring for UAV
Ai+ clinical trial patient recruitment | massive bio completed round a financing of $9million
Arrays.asList()坑
Is it safe to open an online futures account?
Adobe Premiere基础-常用的视频特效(裁剪,黑白,剪辑速度,镜像,镜头光晕)(十五)
药物发现综述-03-分子设计与优化
LATEX 表格内容居左,中,右
.mp4视频测试地址
界面组件Telerik UI for WPF入门指南 - 如何使用主题切换自定义样式
Deepmind | pre training of molecular property prediction through noise removal
The flutter slivereappbar is fully parsed. All the effects you want are here!