Skip to content

Commit

Permalink
Merge pull request #9 from LinuxSuRen/skip-status
Browse files Browse the repository at this point in the history
feat: skip sending status if pr is -1
  • Loading branch information
LinuxSuRen authored Dec 30, 2022
2 parents 1d93748 + bf0f614 commit 02834db
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import (

// Reconcile is the main entry of this reconciler
func Reconcile(ctx context.Context, repoInfo RepoInformation) (err error) {
if repoInfo.PrNumber == -1 {
fmt.Println("skip due to pr number is -1")
return
}

repo := repoInfo.getRepoPath()
maker := NewStatusMaker(repo, repoInfo.Token)
maker.WithTarget(repoInfo.Target).WithPR(repoInfo.PrNumber).
Expand Down
46 changes: 46 additions & 0 deletions pkg/git_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package pkg

import (
"context"
"github.com/jenkins-x/go-scm/scm"
"github.com/stretchr/testify/assert"
"testing"
)

func TestReconcile(t *testing.T) {
type args struct {
ctx context.Context
repoInfo RepoInformation
}
tests := []struct {
name string
args args
wantErr bool
}{{
name: "pr number is -1",
args: args{
repoInfo: RepoInformation{
PrNumber: -1,
},
},
wantErr: false,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := Reconcile(tt.args.ctx, tt.args.repoInfo); (err != nil) != tt.wantErr {
t.Errorf("Reconcile() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}

func TestNewStatusMaker(t *testing.T) {
maker := NewStatusMaker("", "")
assert.NotNil(t, maker)
assert.NotNil(t, maker.expirationCheck)
assert.False(t, maker.expirationCheck(nil, nil))
assert.False(t, maker.expirationCheck(&scm.Status{State: scm.StateSuccess},
&scm.StatusInput{State: scm.StateError}))
assert.True(t, maker.expirationCheck(&scm.Status{State: scm.StateSuccess},
&scm.StatusInput{State: scm.StateSuccess}))
}
33 changes: 33 additions & 0 deletions pkg/type_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package pkg

import "testing"

func TestRepoInformation_getRepoPath(t *testing.T) {
type fields struct {
Owner string
Repo string
}
tests := []struct {
name string
fields fields
want string
}{{
name: "normal case",
fields: fields{
Owner: "owner",
Repo: "repo",
},
want: "owner/repo",
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
r := RepoInformation{
Owner: tt.fields.Owner,
Repo: tt.fields.Repo,
}
if got := r.getRepoPath(); got != tt.want {
t.Errorf("getRepoPath() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 02834db

Please sign in to comment.