Skip to content

Commit

Permalink
Merge pull request #12 from olegsu/tests
Browse files Browse the repository at this point in the history
tests
  • Loading branch information
olegsu committed Dec 6, 2021
2 parents 6d46c79 + be64d9b commit 469a7f1
Show file tree
Hide file tree
Showing 8 changed files with 600 additions and 430 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: release

on: [workflow_dispatch]

jobs:
release:
name: Build
runs-on: "ubuntu-18.04"
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '^1.17'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Test
run: go test ./...
- name: Build
run: docker build -t $(cat docker-repository.txt):$(cat next_version) .

26 changes: 13 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ module github.com/olegsu/pull-requests-bot
go 1.17

require (
github.com/bradleyfalzon/ghinstallation v1.1.1 // indirect
github.com/bradleyfalzon/ghinstallation v1.1.1
github.com/google/go-github/v41 v41.0.0
github.com/olegsu/go-tools v0.0.0-20210831145405-166a09aff939
github.com/stretchr/testify v1.7.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/go-logr/logr v1.1.0 // indirect
github.com/go-logr/zapr v1.1.0 // indirect
github.com/golang/protobuf v1.4.2 // indirect
github.com/google/go-github/v29 v29.0.2 // indirect
github.com/google/go-github/v40 v40.0.0 // indirect
github.com/google/go-github/v41 v41.0.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/olegsu/go-tools v0.0.0-20210831145405-166a09aff939 // indirect
github.com/tidwall/gjson v1.11.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.1.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.19.0 // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.25.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d // indirect
)
338 changes: 14 additions & 324 deletions go.sum

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions pkg/http/handlers/github_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package handlers

import (
"context"

"github.com/google/go-github/v41/github"
)

type (
GithubClient interface {
GetRepository(ctx context.Context, owner string, name string) (*github.Repository, *github.Response, error)
ListOrganizationMembers(ctx context.Context, org string, opt *github.ListMembersOptions) ([]*github.User, *github.Response, error)
GetFileContent(ctx context.Context, owner string, name string, path string, opt *github.RepositoryContentGetOptions) (*github.RepositoryContent, []*github.RepositoryContent, *github.Response, error)
EditIssueComment(ctx context.Context, owner string, name string, issue int64, comment *github.IssueComment) (*github.IssueComment, *github.Response, error)
CreateIssueComment(ctx context.Context, owner string, name string, issue int, comment *github.IssueComment) (*github.IssueComment, *github.Response, error)
AddLabelsToIssue(ctx context.Context, owner string, name string, issue int, labels []string) ([]*github.Label, *github.Response, error)
MergePullRequest(ctx context.Context, owner string, name string, issue int, commitMessage string, opt *github.PullRequestOptions) (*github.PullRequestMergeResult, *github.Response, error)
CreateWorkflowDispatchEventByFileName(ctx context.Context, owner, repo, workflowFileName string, event github.CreateWorkflowDispatchEventRequest) (*github.Response, error)
}

gh struct {
clinet *github.Client
}

Option func(g *gh)
)

func NewClient(opts ...Option) GithubClient {
g := &gh{}

for _, opt := range opts {
opt(g)
}

return g
}

func WithGithubClient(c *github.Client) Option {
return func(g *gh) {
g.clinet = c
}
}

func (g *gh) GetRepository(ctx context.Context, owner string, name string) (*github.Repository, *github.Response, error) {
return g.clinet.Repositories.Get(ctx, owner, name)
}
func (g *gh) ListOrganizationMembers(ctx context.Context, org string, opt *github.ListMembersOptions) ([]*github.User, *github.Response, error) {
return g.clinet.Organizations.ListMembers(ctx, org, opt)
}
func (g *gh) GetFileContent(ctx context.Context, owner string, name string, path string, opt *github.RepositoryContentGetOptions) (*github.RepositoryContent, []*github.RepositoryContent, *github.Response, error) {
return g.clinet.Repositories.GetContents(ctx, owner, name, path, opt)
}
func (g *gh) EditIssueComment(ctx context.Context, owner string, name string, issue int64, comment *github.IssueComment) (*github.IssueComment, *github.Response, error) {
return g.clinet.Issues.EditComment(ctx, owner, name, issue, comment)
}
func (g *gh) CreateIssueComment(ctx context.Context, owner string, name string, issue int, comment *github.IssueComment) (*github.IssueComment, *github.Response, error) {
return g.clinet.Issues.CreateComment(ctx, owner, name, issue, comment)
}
func (g *gh) AddLabelsToIssue(ctx context.Context, owner string, name string, issue int, labels []string) ([]*github.Label, *github.Response, error) {
return g.clinet.Issues.AddLabelsToIssue(ctx, owner, name, issue, labels)
}
func (g *gh) MergePullRequest(ctx context.Context, owner string, name string, issue int, commitMessage string, opt *github.PullRequestOptions) (*github.PullRequestMergeResult, *github.Response, error) {
return g.clinet.PullRequests.Merge(ctx, owner, name, issue, commitMessage, opt)
}
func (g *gh) CreateWorkflowDispatchEventByFileName(ctx context.Context, owner, repo, workflowFileName string, event github.CreateWorkflowDispatchEventRequest) (*github.Response, error) {
return g.clinet.Actions.CreateWorkflowDispatchEventByFileName(ctx, owner, repo, workflowFileName, event)
}
Loading

0 comments on commit 469a7f1

Please sign in to comment.