当前位置:网站首页>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
边栏推荐
- SPuG - lightweight automatic operation and maintenance platform
- 解决ionic4 使用hammerjs手势 press 事件,页面无法滚动问题
- 联想拯救者R720如何组建双通道内存
- How to build dual channel memory for Lenovo Savior r720
- Huawei partners and Developers Conference 2022 | Kirin software cooperates with Huawei to jointly build the computing industry and create a digital intelligence future
- ionic4实现半星评分
- Li Kou today's question -522 Longest special sequence
- Google Earth engine (GEE) -- an error caused by the imagecollection (error) traversing the image collection
- awk注意的几个问题
- Collection de cas d'effets spéciaux en cliquant sur la souris de la page Web
猜你喜欢

什么是过孔式导电滑环?

Adobe Premiere Basics - common video effects (corner positioning, mosaic, blur, sharpen, handwriting tools, effect control hierarchy) (16)

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

MySQL 18: execution of write statements

Web3 技术初体验以及相关学习资料

机器学习笔记 - 时间序列作为特征

基于可学习尺寸自适应分子亚结构的药物相互作用预测

评价——秩和比综合评价

声网 VQA:将实时互动中未知的视频画质用户主观体验变可知

What is a through-hole conductive slip ring?
随机推荐
面试官问:JS的this指向
基于可学习尺寸自适应分子亚结构的药物相互作用预测
评价——灰色关联分析
MySQL 18: execution of write statements
【说明】Jmeter乱码的解决方法
Web3 technology initial experience and related learning materials
Set collection usage
Zhang Fan: the attribution of flying pig after advertising based on causal inference technology
Why stainless steel swivel
SPuG - lightweight automatic operation and maintenance platform
Implementation of timed tasks in laravel framework
Can you open an account for stock trading in flush? Is it safe?
Lefse analyzes the local implementation method with all installation files and details to ensure success.
The practice of dual process guard and keeping alive in IM instant messaging development
Is it safe to open an account online now? Novice is just on the road, ask for the answer
国外LEAD赚钱的一些习惯
How to build dual channel memory for Lenovo Savior r720
The flutter slivereappbar is fully parsed. All the effects you want are here!
独立站卖家都在用的五大电子邮件营销技巧,你知道吗?
Some problems in awk