Skip to content

Commit

Permalink
some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty287 committed Nov 23, 2023
1 parent 91afda4 commit 11ac924
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 33 deletions.
2 changes: 1 addition & 1 deletion shared/addon/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ func Load[T any](files []string, t types.Type) (*Addon[T], error) {
}, nil
//}

return nil, nil
//return nil, nil
}
2 changes: 2 additions & 0 deletions shared/addon/rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package rpc
import (
"net/rpc"

"github.com/hashicorp/go-plugin"
"github.com/rs/zerolog/log"

"go.woodpecker-ci.org/woodpecker/shared/addon/types"
)

type AddonRPCClient[T any] struct {
client *rpc.Client
broker *plugin.MuxBroker
}

func (a *AddonRPCClient[T]) Type() types.Type {
Expand Down
8 changes: 4 additions & 4 deletions shared/addon/rpc/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ type AddonPlugin[T any] struct {
Impl types.Addon[T]
}

func (a *AddonPlugin[T]) Server(_ *plugin.MuxBroker) (interface{}, error) {
return &AddonRPCServer[T]{Impl: a.Impl}, nil
func (a *AddonPlugin[T]) Server(broker *plugin.MuxBroker) (interface{}, error) {
return &AddonRPCServer[T]{Impl: a.Impl, broker: broker}, nil
}

func (*AddonPlugin[T]) Client(_ *plugin.MuxBroker, c *rpc.Client) (interface{}, error) {
return &AddonRPCClient[T]{client: c}, nil
func (*AddonPlugin[T]) Client(broker *plugin.MuxBroker, c *rpc.Client) (interface{}, error) {
return &AddonRPCClient[T]{broker: broker, client: c}, nil
}
9 changes: 7 additions & 2 deletions shared/addon/rpc/server.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package rpc

import (
//"net/rpc"

"github.com/hashicorp/go-plugin"

"go.woodpecker-ci.org/woodpecker/shared/addon/types"
)

type AddonRPCServer[T any] struct {
Impl types.Addon[T]
Impl types.Addon[T]
broker *plugin.MuxBroker
}

func (a *AddonRPCServer[T]) Type(_ interface{}, resp *types.Type) error {
Expand All @@ -14,7 +19,7 @@ func (a *AddonRPCServer[T]) Type(_ interface{}, resp *types.Type) error {
}

func (a *AddonRPCServer[T]) Addon(args map[string]interface{}, resp *T) error {
addon, err := a.Impl.Addon( /*args["logger"].(zerolog.Logger), */ args["env"].([]string))
addon, err := a.Impl.Addon(args["env"].([]string))
*resp = addon
return err
}
47 changes: 21 additions & 26 deletions shared/addon/test-addon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package main

import (
"context"
"log/slog"
"net/http"

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"

"go.woodpecker-ci.org/woodpecker/server/forge"
forge_types "go.woodpecker-ci.org/woodpecker/server/forge/types"
"go.woodpecker-ci.org/woodpecker/server/model"
Expand All @@ -26,133 +24,130 @@ func (a *TestAddon) Type() addon_types.Type {
}

func (a *TestAddon) Addon(env []string) (forge.Forge, error) {
logger := log.Logger // TODO send via rpc
logger.Error().Msg("hello world from addon")
return &config{l: logger}, nil
return &config{}, nil
}

type config struct {
l zerolog.Logger
}

// Name returns the string name of this driver
func (c *config) Name() string {
c.l.Error().Msg("call Name")
slog.Error("call Name")
return "addon-forge"
}

// URL returns the root url of a configured forge
func (c *config) URL() string {
c.l.Error().Msg("call URL")
slog.Error("call URL")
return ""
}

// Login authenticates an account with Bitbucket using the oauth2 protocol. The
// Bitbucket account details are returned when the user is successfully authenticated.
func (c *config) Login(ctx context.Context, w http.ResponseWriter, req *http.Request) (*model.User, error) {
c.l.Error().Msg("call Login")
slog.Error("call Login")
return nil, nil
}

// Auth uses the Bitbucket oauth2 access token and refresh token to authenticate
// a session and return the Bitbucket account login.
func (c *config) Auth(ctx context.Context, token, secret string) (string, error) {
c.l.Error().Msg("call Auth")
slog.Error("call Auth")
return "", nil
}

// Teams returns a list of all team membership for the Bitbucket account.
func (c *config) Teams(ctx context.Context, u *model.User) ([]*model.Team, error) {
c.l.Error().Msg("call Teams")
slog.Error("call Teams")
return nil, nil
}

// Repo returns the named Bitbucket repository.
func (c *config) Repo(ctx context.Context, u *model.User, remoteID model.ForgeRemoteID, owner, name string) (*model.Repo, error) {
c.l.Error().Msg("call Repo")
slog.Error("call Repo")
return nil, nil
}

// Repos returns a list of all repositories for Bitbucket account, including
// organization repositories.
func (c *config) Repos(ctx context.Context, u *model.User) ([]*model.Repo, error) {
c.l.Error().Msg("call Repos")
slog.Error("call Repos")
return nil, nil
}

// File fetches the file from the Bitbucket repository and returns its contents.
func (c *config) File(ctx context.Context, u *model.User, r *model.Repo, p *model.Pipeline, f string) ([]byte, error) {
c.l.Error().Msg("call File")
slog.Error("call File")
return nil, nil
}

// Dir fetches a folder from the bitbucket repository
func (c *config) Dir(ctx context.Context, u *model.User, r *model.Repo, p *model.Pipeline, f string) ([]*forge_types.FileMeta, error) {
c.l.Error().Msg("call Dir")
slog.Error("call Dir")
return nil, nil
}

// Status creates a pipeline status for the Bitbucket commit.
func (c *config) Status(ctx context.Context, user *model.User, repo *model.Repo, pipeline *model.Pipeline, _ *model.Workflow) error {
c.l.Error().Msg("call Status")
slog.Error("call Status")
return nil
}

// Activate activates the repository by registering repository push hooks with
// the Bitbucket repository. Prior to registering hook, previously created hooks
// are deleted.
func (c *config) Activate(ctx context.Context, u *model.User, r *model.Repo, link string) error {
c.l.Error().Msg("call Activate")
slog.Error("call Activate")
return nil
}

// Deactivate deactivates the repository be removing repository push hooks from
// the Bitbucket repository.
func (c *config) Deactivate(ctx context.Context, u *model.User, r *model.Repo, link string) error {
c.l.Error().Msg("call Deactivate")
slog.Error("call Deactivate")
return nil
}

// Netrc returns a netrc file capable of authenticating Bitbucket requests and
// cloning Bitbucket repositories.
func (c *config) Netrc(u *model.User, _ *model.Repo) (*model.Netrc, error) {
c.l.Error().Msg("call Netrc")
slog.Error("call Netrc")
return nil, nil
}

// Branches returns the names of all branches for the named repository.
func (c *config) Branches(ctx context.Context, u *model.User, r *model.Repo, p *model.ListOptions) ([]string, error) {
c.l.Error().Msg("call Branches")
slog.Error("call Branches")
return nil, nil
}

// BranchHead returns the sha of the head (latest commit) of the specified branch
func (c *config) BranchHead(ctx context.Context, u *model.User, r *model.Repo, branch string) (string, error) {
c.l.Error().Msg("call BranchHead")
slog.Error("call BranchHead")
return "", nil
}

// PullRequests returns the pull requests of the named repository.
func (c *config) PullRequests(ctx context.Context, u *model.User, r *model.Repo, p *model.ListOptions) ([]*model.PullRequest, error) {
c.l.Error().Msg("call PullRequests")
slog.Error("call PullRequests")
return nil, nil
}

// Hook parses the incoming Bitbucket hook and returns the Repository and
// Pipeline details. If the hook is unsupported nil values are returned.
func (c *config) Hook(_ context.Context, req *http.Request) (*model.Repo, *model.Pipeline, error) {
c.l.Error().Msg("call Hook")
slog.Error("call Hook")
return nil, nil, nil
}

// OrgMembership returns if user is member of organization and if user
// is admin/owner in this organization.
func (c *config) OrgMembership(ctx context.Context, u *model.User, owner string) (*model.OrgPerm, error) {
c.l.Error().Msg("call OrgMembership")
slog.Error("call OrgMembership")
return nil, nil
}

func (c *config) Org(ctx context.Context, u *model.User, owner string) (*model.Org, error) {
c.l.Error().Msg("call Org")
slog.Error("call Org")
return nil, nil
}

0 comments on commit 11ac924

Please sign in to comment.