Skip to content

Commit f72ce88

Browse files
authored
Merge pull request #4 from merico-dev/code-style-improvement
Code style improvement
2 parents b537da3 + 7fef1bd commit f72ce88

File tree

7 files changed

+84
-20
lines changed

7 files changed

+84
-20
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: golangci-lint
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
branches:
8+
- main
9+
pull_request:
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
golangci:
16+
name: lint
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v2
20+
- name: golangci-lint
21+
uses: golangci/golangci-lint-action@v2
22+
with:
23+
version: latest

CONTRIBUTING.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,43 @@ We aim to reply to issues within 24 hours.
2020

2121
## Style Guides
2222

23+
### Linters
24+
25+
We use `golangci-lint` ([official website](https://golangci-lint.run/), [GitHub](https://github.com/golangci/golangci-lint)) for linting, which is a Go linters aggregator. It's also integrated with the GitHub Actions workflows.
26+
27+
- The list of linters enabled by default is documented [here](https://golangci-lint.run/usage/linters/).
28+
- It can be [integrated with IDE](https://golangci-lint.run/usage/integrations/)
29+
- You can [run it locally](https://golangci-lint.run/usage/quick-start/).
30+
31+
Besides, we also use the [Go Report Card](https://goreportcard.com/report/github.com/merico-dev/stream). There is a badge like [![Go Report Card](https://goreportcard.com/badge/github.com/merico-dev/stream)](https://goreportcard.com/report/github.com/merico-dev/stream) in the main README.md.
32+
2333
### Git Commit Message
2434

2535
We try our best to follow the [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/#summary) guidelines.
36+
37+
TL;DR: The commit message should be structured as follows:
38+
39+
```
40+
<type>[optional scope]: <description>
41+
[optional body]
42+
[optional footer(s)]
43+
```
44+
45+
where "type" can be:
46+
- `feat`: implements a feature
47+
- `fix`: patches a bug
48+
- `BREAKING CHANGE`: a breaking change. Or append `!` at the end of "feat" or "fix", like `feat!` and `fix!`
49+
- other types are allowed, for example: `build`, `chore`, `ci`, `docs`, `style`, `refactor`, `perf`, `test`
50+
51+
Both "body" and "footer" are optional; BREAKING CHANGE can be addressed both in the title as well as in the footer. Some examples:
52+
53+
- `feat: send an email to the customer when a product is shipped`
54+
- `feat!: send an email to the customer when a product is shipped`
55+
- `feat(api): send an email to the customer when a product is shipped`
56+
- `feat(api)!: send an email to the customer when a product is shipped`
57+
- `BREAKING CHANGE: send an email to the customer when a product is shipped`
58+
- ```
59+
feat!: send an email to the customer when a product is shipped
60+
A detailed description in the body.
61+
BREAKING CHANGE: readdressing the breaking change in the footer.
62+
```

cmd/argocd/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ type Plugin string
1616
// Install implements the installation of ArgoCD.
1717
func (p Plugin) Install(options *map[string]interface{}) {
1818
argocd.Install(options)
19-
log.Println("argocd install finished")
19+
log.Printf("%s install finished", NAME)
2020
}
2121

2222
// Reinstall implements the reinstallation of ArgoCD.
2323
func (p Plugin) Reinstall(options *map[string]interface{}) {
24-
log.Println("mock: argocd reinstall finished")
24+
log.Printf("mock: %s reinstall finished", NAME)
2525
}
2626

2727
// Uninstall implements the uninstallation of ArgoCD.
2828
func (p Plugin) Uninstall(options *map[string]interface{}) {
29-
log.Println("mock: argocd uninstall finished")
29+
log.Printf("mock: %s uninstall finished", NAME)
3030
}
3131

3232
// DevStreamPlugin is the exported variable used by the DevStream core.
3333
var DevStreamPlugin Plugin
3434

3535
func main() {
36-
fmt.Println("This is a plugin for DevStream. Use it with DevStream.")
36+
fmt.Printf("%T: %s is a plugin for DevStream. Use it with DevStream.\n", NAME, DevStreamPlugin)
3737
}

cmd/argocdapp/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ type Plugin string
1616
// Install implements the installation of an ArgoCD app.
1717
func (p Plugin) Install(options *map[string]interface{}) {
1818
argocdapp.Install(options)
19-
log.Println("argocdapps install finished")
19+
log.Printf("%s install finished", NAME)
2020
}
2121

2222
// Reinstall implements the installation of an ArgoCD app.
2323
func (p Plugin) Reinstall(options *map[string]interface{}) {
24-
log.Println("mock: argocdapps reinstall finished")
24+
log.Printf("mock: %s reinstall finished", NAME)
2525
}
2626

2727
// Uninstall Uninstall the installation of an ArgoCD app.
2828
func (p Plugin) Uninstall(options *map[string]interface{}) {
29-
log.Println("mock: argocdapps uninstall finished")
29+
log.Printf("mock: %s uninstall finished", NAME)
3030
}
3131

3232
// DevStreamPlugin is the exported variable used by the DevStream core.
3333
var DevStreamPlugin Plugin
3434

3535
func main() {
36-
fmt.Println("This is a plugin for DevStream. Use it with DevStream.")
36+
fmt.Printf("%T: %s is a plugin for DevStream. Use it with DevStream.\n", NAME, DevStreamPlugin)
3737
}

cmd/devstream/main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package main
22

33
import (
4+
"log"
5+
46
"github.com/spf13/cobra"
57
)
68

@@ -14,11 +16,6 @@ var (
1416
}
1517
)
1618

17-
// Execute runs the rootCMD's Execute func.
18-
func Execute() error {
19-
return rootCMD.Execute()
20-
}
21-
2219
func init() {
2320
rootCMD.PersistentFlags().StringVarP(&configFile, "config-file", "f", "config.yaml", "config file")
2421

@@ -27,5 +24,8 @@ func init() {
2724
}
2825

2926
func main() {
30-
rootCMD.Execute()
27+
err := rootCMD.Execute()
28+
if err != nil {
29+
log.Fatal(err)
30+
}
3131
}

cmd/githubactions/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ type Plugin string
1616
// Install implements the installation of some GitHub Actions workflows.
1717
func (p Plugin) Install(options *map[string]interface{}) {
1818
githubactions.Install(options)
19-
log.Println("github actions install finished")
19+
log.Printf("%s install finished", NAME)
2020
}
2121

2222
// Reinstall implements the installation of some GitHub Actions workflows.
2323
func (p Plugin) Reinstall(options *map[string]interface{}) {
24-
log.Println("mock: github actions reinstall finished")
24+
log.Printf("mock: %s reinstall finished", NAME)
2525
}
2626

2727
// Uninstall implements the installation of some GitHub Actions workflows.
2828
func (p Plugin) Uninstall(options *map[string]interface{}) {
29-
log.Println("mock: github actions uninstall finished")
29+
log.Printf("mock: %s uninstall finished", NAME)
3030
}
3131

3232
// DevStreamPlugin is the exported variable used by the DevStream core.
3333
var DevStreamPlugin Plugin
3434

3535
func main() {
36-
fmt.Println("This is a plugin for DevStream. Use it with DevStream.")
36+
fmt.Printf("%T: %s is a plugin for DevStream. Use it with DevStream.\n", NAME, DevStreamPlugin)
3737
}

internal/pkg/githubactions/githubactions.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ func generateGitHubWorkflowFileByName(f string) string {
1515
}
1616

1717
func getGitHubToken() string {
18-
viper.BindEnv("github_token")
19-
token, ok := viper.Get("github_token").(string)
18+
err := viper.BindEnv("github_token")
19+
if err != nil {
20+
log.Fatalf("ENV var GITHUB_TOKEN is needed")
21+
}
2022

23+
token, ok := viper.Get("github_token").(string)
2124
if !ok {
2225
log.Fatalf("ENV var GITHUB_TOKEN is needed")
2326
}
27+
2428
return token
2529
}
2630

0 commit comments

Comments
 (0)