当前位置:网站首页>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
边栏推荐
- Proe/creo product structure design - continuous research
- Centos8 operation record command version Yum redis MySQL Nacos JDK
- What is the application scope and function of the conductive slip ring of single crystal furnace
- 如何阅读一篇论文
- OS模块与OS.path 模块的学习
- ionic4实现半星评分
- 美团动态线程池实践思路已开源
- Lefse analyzes the local implementation method with all installation files and details to ensure success.
- 现在炒股网上开户安全吗?新手刚上路,求答案
- Adobe Premiere基础-编辑素材文件常规操作(脱机文件,替换素材,素材标签和编组,素材启用,便捷调节不透明度,项目打包)(十七)
猜你喜欢

Solon 1.8.3 release, cloud native microservice development framework

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

How to optimize the "message" list of IM

Maimai hot post: Why are big factories keen on making wheels?

. Mp4 video test address

药物发现综述-02-分子性质预测

万字长文看懂商业智能(BI)|推荐收藏

单晶炉导电滑环的应用范围和作用是什么

什么是数字化?什么是数字化转型?为什么企业选择数字化转型?

药物发现综述-01-药物发现概述
随机推荐
Solon 1.8.3 发布,云原生微服务开发框架
lodash实现防抖和节流功能及原生实现
[DNS resolution] set the name DNSPod resolution for domain name access of COM
什么是数字化?什么是数字化转型?为什么企业选择数字化转型?
Ai+ clinical trial patient recruitment | massive bio completed round a financing of $9million
什么是过孔式导电滑环?
. Mp4 video test address
如何高效读书学习
How to build an e-commerce platform at low cost
N methods of data De duplication using SQL
网络爬虫是什么
Ten thousand words long article understanding business intelligence (BI) | recommended collection
DeepMind | 通过去噪来进行分子性质预测的预训练
Comprehensive evaluation of free, easy-to-use and powerful open source note taking software
LATEX 表格内容居左,中,右
How to study efficiently
Supervised, unsupervised and semi supervised learning
Xctf attack and defense world misc wage earner advanced zone
数据库查询优化:主从读写分离及常见问题
Adobe Premiere基础-编辑素材文件常规操作(脱机文件,替换素材,素材标签和编组,素材启用,便捷调节不透明度,项目打包)(十七)