Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlJi committed Oct 7, 2024
1 parent 084390c commit ff9ef37
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 4 deletions.
75 changes: 72 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ This approach helps PR authors avoid searching for issues in lengthy console log
- [Disabling a Linter](#disabling-a-linter)
- [Executing Linters via Docker](#executing-linters-via-docker)
- [Reviewbot Operational Flow](#reviewbot-operational-flow)
- [How to add a new Linter](#how-to-add-a-new-linter)
- [Monitoring Detection Results](#monitoring-detection-results)
- [Contributing](#contributing)
- [License](#license)
Expand All @@ -49,9 +50,10 @@ This approach helps PR authors avoid searching for issues in lengthy console log
Reviewbot is a self-hosted code analysis and review service supporting multiple languages and coding standards. It is particularly beneficial for organizations with numerous private repositories:

- **Security** - Recommended self-hosting for data security and control
- **Improvement-Oriented** - Detected issues are primarily reported in the form of Review Comments or Github Annotations, facilitating efficient problem resolution and code improvement
- **Flexibility** - Supports multiple languages and coding standards, with easy integration of new code inspection tools
- **Observability** - Supports alert notifications for timely awareness of detected issues
- **Usability** - Designed for zero-configuration, enabling inspection of all repositories with minimal setup
- **Configurable** - Supports configuration of linter execution commands, parameters, and environments, providing flexibility for complex scenarios

Reviewbot is developed using Golang, featuring simple logic and clear code, making it easy to understand and maintain.

Expand Down Expand Up @@ -100,10 +102,35 @@ The following are some common configuration scenarios:

Linters are generally executed using default commands, but we can adjust these commands. For example:

```yaml
qbox/kodo:
linters:
staticcheck:
workDir: "src/qiniu.com/kodo"
```
This configuration means that for the `staticcheck` inspection of the `qbox/kodo` repository code, execution should occur in the `src/qiniu.com/kodo` directory.

We can even configure more complex commands, such as:

```yaml
qbox/kodo:
linters:
golangci-lint:
command:
- "/bin/sh"
- "-c"
- "--"
args:
- |
source env.sh
cp .golangci.yml src/qiniu.com/kodo/.golangci.yml
cd src/qiniu.com/kodo
export GO111MODULE=auto
go mod tidy
golangci-lint run --timeout=10m0s --allow-parallel-runners=true --print-issued-lines=false --out-format=line-number >> $ARTIFACT/lint.log 2>&1
```

This configuration indicates that for the `golangci-lint` inspection of the `qbox/kodo` repository code, execution occurs through custom commands and arguments.

The usage of command and args here is similar to that of Kubernetes Pod command and args. You can refer to [Kubernetes Pod](https://kubernetes.io/docs/concepts/workloads/pods/) for more information.
Expand All @@ -114,7 +141,14 @@ The **$ARTIFACT** environment variable is noteworthy. This is a built-in variabl

We can also disable a specific linter check for a particular repository through configuration. For example:

This configuration means that the `golangci-lint` check is disabled for the `qbox/kodo` repository.
```yaml
qbox/net-gslb:
linters:
golangci-lint:
enable: false
```

This configuration means that the `golangci-lint` check is disabled for the `qbox/net-gslb` repository.

### Executing Linters via Docker

Expand All @@ -126,6 +160,14 @@ By default, Reviewbot uses locally installed linters for checks. However, in som

In these scenarios, we can configure Docker images to execute the linters. For example:

```yaml
qbox/net-gslb:
linters:
golangci-lint:
dockerAsRunner:
image: "golangci/golangci-lint:v1.54.2"
```

This configuration means that for the `golangci-lint` check of the `qbox/net-gslb` repository code, the `golangci/golangci-lint:v1.54.2` Docker image is used for execution.

## Reviewbot Operational Flow
Expand Down Expand Up @@ -161,9 +203,36 @@ Github Event -> Reviewbot -> Execute Linter -> Provide Feedback
- Some linters provide Code Comments, precise to the code line
- Some linters provide issue comments
## How to Add a New Linter?
- Please select an Issue you want to address from the [issues](https://github.com/qiniu/reviewbot/issues) list.
- Of course, if there isn't one, you can first create an Issue describing the Linter you want to add
- Coding
- Based on the language or domain the linter focuses on, [choose the appropriate code location](https://github.com/qiniu/reviewbot/tree/master/internal/linters)
- The implementation logic for most linters is divided into three main parts:
- Execute the linter, generally by calling the relevant executable program
- Process the linter's output, focusing only on the output related to the current PR
- Provide feedback on the output related to the current PR, precise to the code line
- Deployment: If your linter is an external executable program, you'll need to add instructions on how to install this linter in the [Dockerfile](https://github.com/qiniu/reviewbot/blob/master/Dockerfile)
- Documentation: To facilitate subsequent use and maintenance, we should [add appropriate documentation here](https://github.com/qiniu/reviewbot/tree/master/docs/website/docs/components)
## Monitoring Detection Results
Reviewbot provides a monitoring dashboard for detection results, allowing you to view the detection results of all repositories and linters.
Reviewbot supports notification of detection results through WeWork (企业微信) alerts. For specific implementation details, refer to [here](https://github.com/qiniu/reviewbot/blob/8bfb122a2e4292f1cc74aedab8f51d1a0c149d55/internal/metric/metrics.go#L17).
To enable this feature, simply set the environment variable `WEWORK_WEBHOOK` when starting Reviewbot. This environment variable should point to the WeWork chat group's bot URL. When valid issues are detected, notifications will be sent automatically. For example:
<div style="display: flex; justify-content: flex-start;">
<img src="./docs/static/found-valid-issue.png" alt="Found valid issue" width="467"/>
</div>
If unexpected output is encountered, notifications will also be sent, like this:
<div style="display: flex; justify-content: flex-start;">
<img src="./docs/static/found-unexpected-issue.png" alt="Found unexpected issue" width="467"/>
</div>
For unexpected outputs, **it usually means that the default execution configuration of the relevant linter does not support the current repository**. In such cases, you need to explicitly specify the configuration through a configuration file based on the actual situation.
## Contributing
Expand Down
21 changes: 20 additions & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ Reviewbot 帮助你快速搭建一个自托管的代码分析和代码审查服
Reviewbot 是一个自托管的代码分析和代码审查服务,支持多种语言和多种代码规范,尤其适合有大量私有仓库的组织:

- **安全性** - 推荐自托管,数据安全可控
- **面向改进** - 检测出的问题,都会优先以类 Review Comments 或 Github Annotations 形式优先反馈,方便问题改进
- **灵活性** - 支持多种语言和多种代码规范,也非常容易添加新的代码检查工具
- **可观测** - 支持 alert 通知,方便及时感知检测出的问题
- **易用性** - 面向零配置设计,不需要太多的配置,就能对所有仓库进行检测
- **可配置** - 支持通过配置来调整 linter 的执行命令、执行参数、执行环境等,非常灵活

Reviewbot 基于 golang 开发,逻辑简单,代码清晰,容易理解和维护。

Expand Down Expand Up @@ -210,6 +211,24 @@ Github 事件 -> Reviewbot -> 执行 linter -> 反馈结果
- 部署,如果你的 linter 是外部可执行程序,那么就需要在 [Dockerfile](https://github.com/qiniu/reviewbot/blob/master/Dockerfile) 中添加如何安装这个 linter
- 文档,为方便后续的使用和运维,我们应当 [在这里](https://github.com/qiniu/reviewbot/tree/master/docs/website/docs/components) 添加合适的文档
## 观察检测结果
Reviewbot 支持通过企业微信 alert 来通知检测结果,具体实现参考[这里](https://github.com/qiniu/reviewbot/blob/8bfb122a2e4292f1cc74aedab8f51d1a0c149d55/internal/metric/metrics.go#L17)
只需要在 Reviewbot 启动时,设置环境变量 `WEWORK_WEBHOOK` 就行,这个环境变量指向企业微信聊天组的机器人 URL,当检测出有效问题时,会自动发送通知。类似:
<div style="display: flex; justify-content: flex-start;">
<img src="./docs/static/found-valid-issue.png" alt="Found valid issue" width="467"/>
</div>
如果遇到非预期的输出,也会发送通知,类似:
<div style="display: flex; justify-content: flex-start;">
<img src="./docs/static/found-unexpected-issue.png" alt="Found unexpected issue" width="467"/>
</div>
对于非预期输出,**通常意味着相关 linter 默认的执行配置不支持当前仓库**,你需要通过配置文件基于实际情况显式指定。
## 贡献
Your contributions to Reviewbot are essential for its long-term maintenance and improvement. Thanks for supporting Reviewbot!
Expand Down
Binary file added docs/static/found-unexpected-issue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/static/found-valid-issue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ff9ef37

Please sign in to comment.