Skip to content

Commit

Permalink
updated readme with cobra commands
Browse files Browse the repository at this point in the history
  • Loading branch information
herlon214 committed Dec 4, 2021
1 parent 6e2e3a0 commit 1a05b0b
Showing 1 changed file with 61 additions and 46 deletions.
107 changes: 61 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,82 +1,97 @@
# :robot: Sonarqube PR Issues Review
[![GoDoc][doc-img]][doc] [![Build Status][ci-img]][ci] [![Coverage Status][cov-img]][cov] [![Go Report Card][report-card-img]][report-card]
[![Build Status][ci-img]][ci] [![Coverage Status][cov-img]][cov] [![Go Report Card][report-card-img]][report-card]

Simple Webhook for Sonarqube which publishes the issues found in the PR as review requesting changes.

The only SCM that is available for now is GitHub, feel free to open a PR if you want to add others.

```shell
$ sqpr
SQPR publishes Sonarqube the issues into your PRs

Usage:
sqpr [command]

Available Commands:
cli Executes CLI commands
completion generate the autocompletion script for the specified shell
help Help about any command
server Executes the server commands

Flags:
-h, --help help for sqpr

Use "sqpr [command] --help" for more information about a command.
```

## Getting started
First of all you need to setup the environment variables:
The following environment variables are required:

```
SONAR_API_KEY=SONAR_API_TOKEN
GH_TOKEN=GITHUB_API_TOKEN
SONAR_ROOT_URL=https://sonar-url-without-trailing-slash
WEBHOOK_SECRET=my-hook-secret # Not necessary if CLI
PORT=8080 # Not necessary if CLI
```

There are currently two ways to use this project:

### Webhook
To use the webhook you need to start the server by running:
To see the list of all available commands in the server mode run with the `--help` flag:
```shell
$ sqpr
```
$ sqpr server --help
Executes the server commands

### CLI
This option is mostly to test, ideally you should use the webhook.
Usage:
sqpr server [command]

To use in the command line you can see the available flags by running `sqpr --help` (or `go run cmd/cli/main.go`):
```
$ sqpr -server --help
Usage of sqpr:
-branch string
SCM Branch name (default "my-branch")
-markaspublished
Mark the issue as published to avoid sending it again (default false)
-project string
Sonarqube project name (default "my-project")
-publish
Publish review
```
Available Commands:
run Starts the webhook server

If you specify the `-branch` and `-project` it will print all the issues for the given branch:
```
$ sqpr -branch feat/newtest -project reynencourt_v3-vendor-onboarding
Flags:
-h, --help help for server

[OPEN] BUG: pkg/newwrong.go L5:
- :bug: MAJOR: Refactor this piece of code to not have any dead code after this "return". ([go:S1763](https://sonar-url-without-trailing-slash/coding_rules?open=go:S1763&rule_key=go:S1763))
[OPEN] BUG: pkg/newwrong.go L12:
- :bug: MAJOR: Refactor this piece of code to not have any dead code after this "return". ([go:S1763](https://sonar-url-without-trailing-slash/coding_rules?open=go:S1763&rule_key=go:S1763))
Use "sqpr server [command] --help" for more information about a command.
```

Start running the webservice by executing:
```shell
$ sqpr server run
INFO[0000] Listening on port 8080
```

If you also specify the `-publish` it will print the issues and also create add the comments in the respective
PR for the given branch.
### CLI
This option is mostly to test, ideally you should use the webhook.

```
$ sqpr -branch feat/newtest -project reynencourt_v3-vendor-onboarding -publish
```shell
$ sqpr cli
Executes CLI commands

[OPEN] BUG: pkg/newwrong.go L5:
- :bug: MAJOR: Refactor this piece of code to not have any dead code after this "return". ([go:S1763](https://sonar-url-without-trailing-slash/coding_rules?open=go:S1763&rule_key=go:S1763))
[OPEN] BUG: pkg/newwrong.go L12:
- :bug: MAJOR: Refactor this piece of code to not have any dead code after this "return". ([go:S1763](https://sonar-url-without-trailing-slash/coding_rules?open=go:S1763&rule_key=go:S1763))
Issues review published!
```
Usage:
sqpr cli [command]

The flag `-markaspublished` it will update the issue in the Sonarqube side, then the next time you run it
those marked issues will be filtered out. This is useful to avoid commenting about the same issues many
times in the PR.
Available Commands:
run Process the given project and branch

Flags:
--branch string SCM branch name (default "my-branch")
-h, --help help for cli
--mark Mark the issue as published to avoid sending it again
--project string Sonarqube project name (default "my-project")
--publish Publish review in the SCM

Use "sqpr cli [command] --help" for more information about a command.
```
$ sqpr -branch feat/newtest -project reynencourt_v3-vendor-onboarding -publish -markaspublished

Processing the issues for one specific project and branch:
```shell
$ sqpr cli run --project myorg_myproject --branch feat/newtest --publish --mark
INFO[0000] Processing myorg_myproject -> feat/newtest
[OPEN] BUG: pkg/newwrong.go L5:
- :bug: MAJOR: Refactor this piece of code to not have any dead code after this "return". ([go:S1763](https://sonar-url-without-trailing-slash/coding_rules?open=go:S1763&rule_key=go:S1763))
[OPEN] BUG: pkg/newwrong.go L12:
- :bug: MAJOR: Refactor this piece of code to not have any dead code after this "return". ([go:S1763](https://sonar-url-without-trailing-slash/coding_rules?open=go:S1763&rule_key=go:S1763))
Issues review published!
INFO[0000] Issues review published!
INFO[0000] --------------------------
INFO[0000] Mark as published result:
INFO[0000] 2 issues marked
Expand All @@ -94,5 +109,5 @@ INFO[0000] --------------------------
[cov-img]: https://codecov.io/gh/uber-go/fx/branch/master/graph/badge.svg
[cov]: https://codecov.io/gh/uber-go/fx/branch/master

[report-card-img]: https://goreportcard.com/badge/github.com/uber-go/fx
[report-card]: https://goreportcard.com/report/github.com/uber-go/fx
[report-card-img]: https://goreportcard.com/badge/github.com/herlon214/sonarqube-pr-issues
[report-card]: https://goreportcard.com/report/github.com/herlon214/sonarqube-pr-issues

0 comments on commit 1a05b0b

Please sign in to comment.