当前位置:网站首页>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
边栏推荐
- .mp4视频测试地址
- 药物发现综述-02-分子性质预测
- Golang monkeys eat peaches and ask for the number of peaches on the first day
- MapReduce elementary programming practice
- FB、WhatsApp群发消息在2022年到底有多热门?
- PostgreSQL设置自增字段
- How to understand query, key and value in transformer
- The contents of the latex table are left, middle and right
- What problems should be evaluated before implementing MES management system
- Solon 1.8.3 发布,云原生微服务开发框架
猜你喜欢

MySQL 18: execution of write statements

如何理解 Transformer 中的 Query、Key 与 Value

Meituan dynamic thread pool practice idea has been open source

The research group of Xuyong and duanwenhui of Tsinghua University has developed an efficient and accurate first principles electronic structure deep learning method and program

大尺寸导电滑环市场应用强度如何

Deepmind | pre training of molecular property prediction through noise removal

Esxi based black Qunhui DSM 7.0.1 installation of VMware Tools

Implementation of timed tasks in laravel framework

SQL Server 2016 detailed installation tutorial (with registration code and resources)

独立站卖家都在用的五大电子邮件营销技巧,你知道吗?
随机推荐
Some habits of making money in foreign lead
Set集合用法
Capacitor
完全二叉树的节点个数[非O(n)求法 -> 抽象二分]
同花顺股票开户是会有什么风险吗?同花顺开户安全吗
awk注意的几个问题
Deepmind | pre training of molecular property prediction through noise removal
【MySQL】-【函数】
美团动态线程池实践思路已开源
Evaluation - rank sum ratio comprehensive evaluation
Chapitre 4: redis
Review of drug discovery-02-prediction of molecular properties
【说明】Jmeter乱码的解决方法
What is the e-commerce conversion rate so abstract?
AI+临床试验患者招募|Massive Bio完成900万美元A轮融资
现在炒股网上开户安全吗?新手刚上路,求答案
基于可学习尺寸自适应分子亚结构的药物相互作用预测
MapReduce elementary programming practice
Overview of drug discovery-01 overview of drug discovery
【DNS 解析】将Name.com的域名接入DNSPod解析