Skip to content
This repository was archived by the owner on Jun 14, 2023. It is now read-only.

Commit d4ce8cc

Browse files
author
Tarun Khandelwal
committed
fix: Small fixes and adding the lint check on GH actions
Signed-off-by: Tarun Khandelwal <tarkhand@redhat.com> Did some small changes to resolve some typos and added the go lint to GH actions and remove existing errors Signed-off-by: Tarun Khandelwal <tarkhand@redhat.com>
1 parent 0e5f2af commit d4ce8cc

16 files changed

Lines changed: 197 additions & 154 deletions

.github/pull_request_template.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
### Description
2+
3+
_Short summary of what is the issue and the solution._
4+
5+
### Dependencies
6+
7+
- _Ex. Other PRs._
8+
9+
### Breaking Change
10+
11+
- [ ] Yes
12+
- [ ] No
13+
14+
### Testing Notes
15+
16+
**What I did:**
17+
_What did you do to validate this PR?_
18+
19+
**How you can replicate my testing:**
20+
_How can the reviewer validate this PR?_
21+
22+
### **Links**
23+
24+
_Issues links or other related resources_

.github/semantic.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Always validate all commits, and ignore the PR title
2+
commitsOnly: true
3+
4+
# Allow use of Merge commits (eg on github: "Merge branch 'master' into feature/ride-unicorns")
5+
# this is only relevant when using commitsOnly: true (or titleAndCommits: true)
6+
allowMergeCommits: true
7+
8+
# Allow use of Revert commits (eg on github: "Revert "feat: ride unicorns"")
9+
# this is only relevant when using commitsOnly: true (or titleAndCommits: true)
10+
allowRevertCommits: true

.github/workflows/lint.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Lint
2+
on:
3+
push:
4+
tags:
5+
- v*
6+
branches:
7+
- master
8+
pull_request:
9+
jobs:
10+
golangci:
11+
name: lint
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- uses: actions/setup-go@v2
16+
- name: golangci-lint
17+
uses: golangci/golangci-lint-action@v2
18+
with:
19+
version: v1.36

.golangci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
run:
2+
# timeout for analysis, e.g. 30s, 5m, default is 1m
3+
timeout: 20m
4+
5+
linters:
6+
# please, do not use `enable-all`: it's deprecated and will be removed soon.
7+
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
8+
disable-all: true
9+
enable:
10+
- bodyclose
11+
- deadcode
12+
- depguard
13+
- dogsled
14+
- errcheck
15+
- goconst
16+
- gofmt
17+
- goimports
18+
- golint
19+
- goprintffuncname
20+
- gosimple
21+
- govet
22+
- ineffassign
23+
- interfacer
24+
- misspell
25+
- nakedret
26+
- rowserrcheck
27+
- staticcheck
28+
- structcheck
29+
- stylecheck
30+
- typecheck
31+
- unconvert
32+
- unparam
33+
- unused
34+
- varcheck
35+
- whitespace
36+
37+
linters-settings:
38+
gofmt:
39+
simplify: false

api/v1/gitbranch_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
// GitBranchSpec defines the desired state of GitBranch
2424
type GitBranchSpec struct {
2525
Repository string `json:"repository,omitempty"`
26-
BranchName string `json:"branchName,omitmepty"`
26+
BranchName string `json:"branchName,omitempty"`
2727
}
2828

2929
// GitBranchStatus defines the observed state of GitBranch

api/v1/groupversion_info.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,3 @@ var (
4747
// Serializer provides high-level encoding/decoding functions
4848
Serializer = serializer.NewSerializer(Scheme, &codecs)
4949
)
50-
51-
func init() {
52-
AddToScheme(Scheme)
53-
}

connectors/connector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func NewConnector(ctx context.Context, crdClient client.Client, k8sClient *kuber
5858
if !found {
5959
password = []byte{}
6060
}
61-
return NewGitSSH(crdClient, log, sshURL, string(user), privateKey, string(password))
61+
return NewGitSSH(crdClient, log, sshURL, user, privateKey, string(password))
6262
}
6363
return nil, errors.New("no connector settings found")
6464
}

connectors/github.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,9 @@ func (g *Github) CreatePullRequest(ctx context.Context, pr PullRequest) error {
211211
ghPR, response, err := g.scm.PullRequests.Create(ctx, repoName, prRequest)
212212
if err != nil {
213213
buf := new(bytes.Buffer)
214-
buf.ReadFrom(response.Body)
214+
if _, err := buf.ReadFrom(response.Body); err != nil {
215+
log.Errorf("Error reading the response body: %v", err)
216+
}
215217
log.Errorf("Github status code: %d", response.Status)
216218
log.Errorf("Github response:\n [%s]", buf.String())
217219
return errors.Wrap(err, "failed to create PullRequest in Github")

connectors/github_util.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ type GithubFetcher struct {
2020
}
2121

2222
func (g *GithubFetcher) BuildPRCRDsFromGithub(ctx context.Context, lastUpdated time.Time) ([]gitv1.GitPullRequest, error) {
23-
crdPRs := []gitv1.GitPullRequest{}
24-
repoName := g.repositoryName(g.repository)
23+
var crdPRs []gitv1.GitPullRequest
24+
repoName := g.repositoryName()
2525

2626
prs, _, err := g.client.PullRequests.List(ctx, repoName, scm.PullRequestListOptions{UpdatedAfter: &lastUpdated})
2727
if err != nil {
@@ -40,7 +40,7 @@ func (g *GithubFetcher) BuildPRCRDsFromGithub(ctx context.Context, lastUpdated t
4040
}
4141

4242
func (g *GithubFetcher) BuildPRCRDFromGithub(ctx context.Context, pr *scm.PullRequest, lastUpdated time.Time) (*gitv1.GitPullRequest, error) {
43-
repositoryName := g.repositoryName(g.repository)
43+
repositoryName := g.repositoryName()
4444
reviewers := []string{}
4545
approvers := map[string]bool{}
4646

@@ -91,7 +91,7 @@ func (g *GithubFetcher) BuildPRCRDFromGithub(ctx context.Context, pr *scm.PullRe
9191

9292
func (g *GithubFetcher) BuildBranchCRDsFromGithub(ctx context.Context, lastUpdated time.Time) ([]gitv1.GitBranch, error) {
9393
crdBranches := []gitv1.GitBranch{}
94-
repoName := g.repositoryName(g.repository)
94+
repoName := g.repositoryName()
9595

9696
branches, _, err := g.client.Git.ListBranches(ctx, repoName, scm.ListOptions{})
9797
if err != nil {
@@ -110,7 +110,7 @@ func (g *GithubFetcher) BuildBranchCRDsFromGithub(ctx context.Context, lastUpdat
110110
}
111111

112112
func (g *GithubFetcher) BuildBranchCRDFromGithub(ctx context.Context, branch *scm.Reference, lastUpdated time.Time) (*gitv1.GitBranch, error) {
113-
repositoryName := g.repositoryName(g.repository)
113+
repositoryName := g.repositoryName()
114114

115115
crd := gitv1.GitBranch{
116116
ObjectMeta: metav1.ObjectMeta{
@@ -134,7 +134,7 @@ func (g *GithubFetcher) BuildBranchCRDFromGithub(ctx context.Context, branch *sc
134134
return &crd, nil
135135
}
136136

137-
func (g *GithubFetcher) repositoryName(r gitv1.GitRepository) string {
137+
func (g *GithubFetcher) repositoryName() string {
138138
return fmt.Sprintf("%s/%s", g.owner, g.repoName)
139139
}
140140

connectors/gitssh.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"os"
77

88
gitv1 "github.com/flanksource/git-operator/api/v1"
9-
v1 "github.com/flanksource/git-operator/api/v1"
109
"github.com/go-git/go-billy/v5"
1110
"github.com/go-git/go-billy/v5/memfs"
1211
git "github.com/go-git/go-git/v5"
@@ -44,6 +43,9 @@ func (g *GitSSH) Clone(ctx context.Context, branch string) (billy.Filesystem, *g
4443
Progress: os.Stdout,
4544
Auth: g.auth,
4645
})
46+
if err != nil {
47+
return nil, nil, err
48+
}
4749

4850
work, err := repo.Worktree()
4951
if err != nil {
@@ -145,17 +147,19 @@ func (g *GitSSH) GetBranchCRDsFromRemote(ctx context.Context, repository *gitv1.
145147
return nil, errors.Wrap(err, "failed to list branches")
146148
}
147149

148-
branches := []v1.GitBranch{}
150+
branches := []gitv1.GitBranch{}
149151

150-
branchesIter.ForEach(func(ref *plumbing.Reference) error {
152+
if err := branchesIter.ForEach(func(ref *plumbing.Reference) error {
151153
// Ignore HEAD
152154
if ref.Name().Short() == "HEAD" {
153155
return nil
154156
}
155157
branch := g.GetBranchCRDFromRemote(repository, ref)
156158
branches = append(branches, branch)
157159
return nil
158-
})
160+
}); err != nil {
161+
return nil, err
162+
}
159163

160164
return branches, nil
161165
}

0 commit comments

Comments
 (0)