Commit 5e966047 authored by Kamil Trzciński's avatar Kamil Trzciński

Make lint happy (serious name refactoring)

parent 2f73fb39
......@@ -140,7 +140,7 @@ vet:
lint:
# Checking project code style...
@golint ./... | grep -v "be unexported"
@golint ./... | ( ! grep -v -e "be unexported" -e "don't use an underscore in package name" -e "ALL_CAPS" )
complexity:
# Checking code complexity
......
......@@ -16,9 +16,8 @@ func getDefaultConfigDirectory() string {
return filepath.Join(homeDir, ".gitlab-runner")
} else if currentDir := helpers.GetCurrentWorkingDirectory(); currentDir != "" {
return currentDir
} else {
panic("Cannot get default config file location")
}
panic("Cannot get default config file location")
}
func userModeWarning(withRun bool) {
......
......@@ -7,16 +7,18 @@ import (
"github.com/codegangsta/cli"
"gitlab.com/ayufan/golang-cli-helpers"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/common"
_ "gitlab.com/gitlab-org/gitlab-ci-multi-runner/executors/docker"
_ "gitlab.com/gitlab-org/gitlab-ci-multi-runner/executors/parallels"
_ "gitlab.com/gitlab-org/gitlab-ci-multi-runner/executors/shell"
_ "gitlab.com/gitlab-org/gitlab-ci-multi-runner/executors/ssh"
_ "gitlab.com/gitlab-org/gitlab-ci-multi-runner/executors/virtualbox"
"gopkg.in/yaml.v1"
"io/ioutil"
"os"
"os/exec"
"strings"
// Force to load all executors, executes init() on them
_ "gitlab.com/gitlab-org/gitlab-ci-multi-runner/executors/docker"
_ "gitlab.com/gitlab-org/gitlab-ci-multi-runner/executors/parallels"
_ "gitlab.com/gitlab-org/gitlab-ci-multi-runner/executors/shell"
_ "gitlab.com/gitlab-org/gitlab-ci-multi-runner/executors/ssh"
_ "gitlab.com/gitlab-org/gitlab-ci-multi-runner/executors/virtualbox"
)
type ExecCommand struct {
......@@ -47,9 +49,8 @@ func (c *ExecCommand) getCommands(commands interface{}) (string, error) {
return text + "\n", nil
} else if commands != nil {
return "", errors.New("unsupported script")
} else {
return "", nil
}
return "", nil
}
func (c *ExecCommand) supportedOption(key string, _ interface{}) bool {
......
package commands_helpers
package helpers
import (
"io/ioutil"
......
package commands_helpers
package helpers
import (
"testing"
......
package commands_helpers
package helpers
import (
"archive/zip"
......
package commands_helpers
package helpers
import (
"io"
......
package commands_helpers
package helpers
import (
"os"
......
package commands_helpers
package helpers
import (
"github.com/Sirupsen/logrus"
......
package commands_helpers
package helpers
import (
"testing"
......
package commands_helpers
package helpers
import (
"os"
......
package commands_helpers
package helpers
import (
"testing"
......
package commands_helpers
package helpers
import (
"bufio"
......
package commands_helpers
package helpers
import (
"io/ioutil"
......
package commands_helpers
package helpers
import (
"github.com/Sirupsen/logrus"
......
package commands_helpers
package helpers
import (
"errors"
......
......@@ -384,20 +384,20 @@ func (mr *RunCommand) Stop(s service.Service) error {
}
}
func (c *RunCommand) Execute(context *cli.Context) {
func (mr *RunCommand) Execute(context *cli.Context) {
svcConfig := &service.Config{
Name: c.ServiceName,
DisplayName: c.ServiceName,
Name: mr.ServiceName,
DisplayName: mr.ServiceName,
Description: defaultDescription,
Arguments: []string{"run"},
}
service, err := service_helpers.New(c, svcConfig)
service, err := service_helpers.New(mr, svcConfig)
if err != nil {
log.Fatalln(err)
}
if c.Syslog {
if mr.Syslog {
log.SetFormatter(new(log.TextFormatter))
logger, err := service.SystemLogger(nil)
if err == nil {
......
......@@ -86,13 +86,13 @@ func (s *RegisterCommand) askExecutor() {
s.Executor = s.ask("executor", "Please enter the executor: "+executors+":", true)
if common.NewExecutor(s.Executor) != nil {
return
}
message := "Invalid executor specified"
if s.NonInteractive {
log.Panicln(message)
} else {
message := "Invalid executor specified"
if s.NonInteractive {
log.Panicln(message)
} else {
log.Errorln(message)
}
log.Errorln(message)
}
}
}
......@@ -153,53 +153,53 @@ func (s *RegisterCommand) askRunner() {
}
}
func (c *RegisterCommand) askExecutorOptions() {
switch c.Executor {
func (s *RegisterCommand) askExecutorOptions() {
switch s.Executor {
case "docker":
c.askDocker()
c.SSH = nil
c.Parallels = nil
c.VirtualBox = nil
s.askDocker()
s.SSH = nil
s.Parallels = nil
s.VirtualBox = nil
case "docker-ssh":
c.askDocker()
c.askSSHLogin()
c.Parallels = nil
c.VirtualBox = nil
s.askDocker()
s.askSSHLogin()
s.Parallels = nil
s.VirtualBox = nil
case "ssh":
c.askSSHServer()
c.askSSHLogin()
c.Docker = nil
c.Parallels = nil
c.VirtualBox = nil
s.askSSHServer()
s.askSSHLogin()
s.Docker = nil
s.Parallels = nil
s.VirtualBox = nil
case "parallels":
c.askParallels()
c.askSSHServer()
c.Docker = nil
c.VirtualBox = nil
s.askParallels()
s.askSSHServer()
s.Docker = nil
s.VirtualBox = nil
case "VirtualBox":
c.askVirtualBox()
c.askSSHLogin()
c.Docker = nil
c.Parallels = nil
s.askVirtualBox()
s.askSSHLogin()
s.Docker = nil
s.Parallels = nil
}
}
func (c *RegisterCommand) Execute(context *cli.Context) {
func (s *RegisterCommand) Execute(context *cli.Context) {
userModeWarning(true)
c.context = context
err := c.loadConfig()
s.context = context
err := s.loadConfig()
if err != nil {
log.Panicln(err)
}
c.askRunner()
s.askRunner()
if !c.LeaveRunner {
if !s.LeaveRunner {
defer func() {
// De-register runner on panic
if r := recover(); r != nil {
if c.registered {
c.network.DeleteRunner(c.RunnerCredentials)
if s.registered {
s.network.DeleteRunner(s.RunnerCredentials)
}
// pass panic to next defer
......@@ -211,21 +211,21 @@ func (c *RegisterCommand) Execute(context *cli.Context) {
signal.Notify(signals, os.Interrupt)
go func() {
s := <-signals
c.network.DeleteRunner(c.RunnerCredentials)
log.Fatalf("RECEIVED SIGNAL: %v", s)
signal := <-signals
s.network.DeleteRunner(s.RunnerCredentials)
log.Fatalf("RECEIVED SIGNAL: %v", signal)
}()
}
c.askExecutor()
s.askExecutor()
if c.config.Concurrent < c.Limit {
log.Warningf("Specified limit (%d) larger then current concurrent limit (%d). Concurrent limit will not be enlarged.", c.Limit, c.config.Concurrent)
if s.config.Concurrent < s.Limit {
log.Warningf("Specified limit (%d) larger then current concurrent limit (%d). Concurrent limit will not be enlarged.", s.Limit, s.config.Concurrent)
}
c.askExecutorOptions()
c.addRunner(&c.RunnerConfig)
c.saveConfig()
s.askExecutorOptions()
s.addRunner(&s.RunnerConfig)
s.saveConfig()
log.Printf("Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!")
}
......
......@@ -93,9 +93,8 @@ func (c *RunnerCredentials) UniqueID() string {
func (c *RunnerCredentials) Log() *log.Entry {
if c.ShortDescription() != "" {
return log.WithField("runner", c.ShortDescription())
} else {
return log.WithFields(log.Fields{})
}
return log.WithFields(log.Fields{})
}
func (c *RunnerConfig) String() string {
......
This diff is collapsed.
......@@ -7,11 +7,11 @@ import (
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/executors"
)
type DockerCommandExecutor struct {
DockerExecutor
type commandExecutor struct {
executor
}
func (s *DockerCommandExecutor) watchContainers(preContainer, buildContainer, postContainer *docker.Container) {
func (s *commandExecutor) watchContainers(preContainer, buildContainer, postContainer *docker.Container) {
s.Println()
err := s.watchContainer(preContainer, bytes.NewBufferString(s.BuildScript.PreScript))
......@@ -39,7 +39,7 @@ func (s *DockerCommandExecutor) watchContainers(preContainer, buildContainer, po
s.BuildFinish <- nil
}
func (s *DockerCommandExecutor) Start() error {
func (s *commandExecutor) Start() error {
s.Debugln("Starting Docker command...")
imageName, err := s.getImageName()
......@@ -95,8 +95,8 @@ func init() {
}
creator := func() common.Executor {
return &DockerCommandExecutor{
DockerExecutor: DockerExecutor{
return &commandExecutor{
executor: executor{
AbstractExecutor: executors.AbstractExecutor{
ExecutorOptions: options,
},
......
......@@ -8,12 +8,12 @@ import (
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/helpers/ssh"
)
type DockerSSHExecutor struct {
DockerExecutor
type sshExecutor struct {
executor
sshCommand ssh.Command
}
func (s *DockerSSHExecutor) Start() error {
func (s *sshExecutor) Start() error {
if s.Config.SSH == nil {
return errors.New("Missing SSH configuration")
}
......@@ -74,9 +74,9 @@ func (s *DockerSSHExecutor) Start() error {
return nil
}
func (s *DockerSSHExecutor) Cleanup() {
func (s *sshExecutor) Cleanup() {
s.sshCommand.Cleanup()
s.DockerExecutor.Cleanup()
s.executor.Cleanup()
}
func init() {
......@@ -92,8 +92,8 @@ func init() {
}
creator := func() common.Executor {
return &DockerSSHExecutor{
DockerExecutor: DockerExecutor{
return &sshExecutor{
executor: executor{
AbstractExecutor: executors.AbstractExecutor{
ExecutorOptions: options,
},
......
......@@ -6,7 +6,7 @@ import (
)
type PulledImage struct {
Id string
ID string
LastPulled time.Time
TTL time.Duration
}
......@@ -47,7 +47,7 @@ func (c *PulledImageCache) mark(imageName string, id string, ttl time.Duration)
}
c.images[imageName] = PulledImage{
LastPulled: time.Now(),
Id: id,
ID: id,
TTL: ttl,
}
}
......@@ -30,7 +30,7 @@ func TestImagePulledInTheFuture(t *testing.T) {
cache := PulledImageCache{}
cache.images = make(map[string]PulledImage)
cache.images["test"] = PulledImage{
Id: "id",
ID: "id",
LastPulled: time.Now().Add(time.Hour),
TTL: time.Second,
}
......
package executors
// make sure that shells get loaded before executors
// this happens, because of difference in ordering init()
// from external packages between 1.4.x and 1.5.x
// this import forces to load shells before
// and fixes: panic: no shells defined
import (
// make sure that shells get loaded before executors
// this happens, because of difference in ordering init()
// from external packages between 1.4.x and 1.5.x
// this import forces to load shells before
// and fixes: panic: no shells defined
_ "gitlab.com/gitlab-org/gitlab-ci-multi-runner/shells"
)
......@@ -13,7 +13,7 @@ import (
prl "gitlab.com/gitlab-org/gitlab-ci-multi-runner/helpers/parallels"
)
type ParallelsExecutor struct {
type executor struct {
executors.AbstractExecutor
cmd *exec.Cmd
vmName string
......@@ -23,7 +23,7 @@ type ParallelsExecutor struct {
machineVerified bool
}
func (s *ParallelsExecutor) waitForIPAddress(vmName string, seconds int) (string, error) {
func (s *executor) waitForIPAddress(vmName string, seconds int) (string, error) {
var lastError error
if s.ipAddress != "" {
......@@ -50,7 +50,7 @@ func (s *ParallelsExecutor) waitForIPAddress(vmName string, seconds int) (string
return "", lastError
}
func (s *ParallelsExecutor) verifyMachine(vmName string) error {
func (s *executor) verifyMachine(vmName string) error {
if s.machineVerified {
return nil
}
......@@ -84,7 +84,7 @@ func (s *ParallelsExecutor) verifyMachine(vmName string) error {
return nil
}
func (s *ParallelsExecutor) restoreFromSnapshot() error {
func (s *executor) restoreFromSnapshot() error {
s.Debugln("Requesting default snapshot for VM...")
snapshot, err := prl.GetDefaultSnapshot(s.vmName)
if err != nil {
......@@ -100,7 +100,7 @@ func (s *ParallelsExecutor) restoreFromSnapshot() error {
return nil
}
func (s *ParallelsExecutor) createVM() error {
func (s *executor) createVM() error {
baseImage := s.Config.Parallels.BaseName
if baseImage == "" {
return errors.New("Missing Image setting from Parallels config")
......@@ -151,7 +151,7 @@ func (s *ParallelsExecutor) createVM() error {
return nil
}
func (s *ParallelsExecutor) Prepare(globalConfig *common.Config, config *common.RunnerConfig, build *common.Build) error {
func (s *executor) Prepare(globalConfig *common.Config, config *common.RunnerConfig, build *common.Build) error {
err := s.AbstractExecutor.Prepare(globalConfig, config, build)
if err != nil {
return err
......@@ -267,7 +267,7 @@ func (s *ParallelsExecutor) Prepare(globalConfig *common.Config, config *common.
return nil
}
func (s *ParallelsExecutor) Start() error {
func (s *executor) Start() error {
ipAddr, err := s.waitForIPAddress(s.vmName, 60)
if err != nil {
return err
......@@ -300,7 +300,7 @@ func (s *ParallelsExecutor) Start() error {
return nil
}
func (s *ParallelsExecutor) Cleanup() {
func (s *executor) Cleanup() {
s.sshCommand.Cleanup()
if s.vmName != "" {
......@@ -326,7 +326,7 @@ func init() {
}
creator := func() common.Executor {
return &ParallelsExecutor{
return &executor{
AbstractExecutor: executors.AbstractExecutor{
ExecutorOptions: options,
},
......
......@@ -16,13 +16,13 @@ import (
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/helpers"
)
type ShellExecutor struct {
type executor struct {
executors.AbstractExecutor
cmd *exec.Cmd
scriptDir string
}
func (s *ShellExecutor) Prepare(globalConfig *common.Config, config *common.RunnerConfig, build *common.Build) error {
func (s *executor) Prepare(globalConfig *common.Config, config *common.RunnerConfig, build *common.Build) error {
if globalConfig != nil {
s.Shell.User = globalConfig.User
}
......@@ -55,7 +55,7 @@ func (s *ShellExecutor) Prepare(globalConfig *common.Config, config *common.Runn
return nil
}
func (s *ShellExecutor) Start() error {
func (s *executor) Start() error {
s.Debugln("Starting shell command...")
// Create execution command
......@@ -102,7 +102,7 @@ func (s *ShellExecutor) Start() error {
return nil
}
func (s *ShellExecutor) Cleanup() {
func (s *executor) Cleanup() {
helpers.KillProcessGroup(s.cmd)
if s.scriptDir != "" {
......@@ -132,7 +132,7 @@ func init() {
}
creator := func() common.Executor {
return &ShellExecutor{
return &executor{
AbstractExecutor: executors.AbstractExecutor{
ExecutorOptions: options,
},
......
......@@ -8,12 +8,12 @@ import (
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/helpers/ssh"
)
type SSHExecutor struct {
type executor struct {
executors.AbstractExecutor
sshCommand ssh.Command
}
func (s *SSHExecutor) Prepare(globalConfig *common.Config, config *common.RunnerConfig, build *common.Build) error {
func (s *executor) Prepare(globalConfig *common.Config, config *common.RunnerConfig, build *common.Build) error {
err := s.AbstractExecutor.Prepare(globalConfig, config, build)
if err != nil {
return err
......@@ -26,7 +26,7 @@ func (s *SSHExecutor) Prepare(globalConfig *common.Config, config *common.Runner
return nil
}
func (s *SSHExecutor) Start() error {
func (s *executor) Start() error {
if s.Config.SSH == nil {
return errors.New("Missing SSH configuration")
}
......@@ -59,7 +59,7 @@ func (s *SSHExecutor) Start() error {
return nil
}
func (s *SSHExecutor) Cleanup() {
func (s *executor) Cleanup() {
s.sshCommand.Cleanup()
s.AbstractExecutor.Cleanup()
}
......@@ -76,7 +76,7 @@ func init() {
}
creator := func() common.Executor {
return &SSHExecutor{
return &executor{
AbstractExecutor: executors.AbstractExecutor{
ExecutorOptions: options,
},
......
......@@ -10,7 +10,7 @@ import (
"time"
)
type VirtualBoxExecutor struct {
type executor struct {
executors.AbstractExecutor
vmName string
sshCommand ssh.Command
......@@ -19,7 +19,7 @@ type VirtualBoxExecutor struct {
machineVerified bool
}
func (s *VirtualBoxExecutor) verifyMachine(vmName string, sshPort string) error {
func (s *executor) verifyMachine(vmName string, sshPort string) error {
if s.machineVerified {
return nil
}
......@@ -49,7 +49,7 @@ func (s *VirtualBoxExecutor) verifyMachine(vmName string, sshPort string) error
return nil
}
func (s *VirtualBoxExecutor) restoreFromSnapshot() error {
func (s *executor) restoreFromSnapshot() error {
s.Debugln("Reverting VM to current snapshot...")
err := vbox.RevertToSnapshot(s.vmName)
if err != nil {
......@@ -60,7 +60,7 @@ func (s *VirtualBoxExecutor) restoreFromSnapshot() error {
}
// virtualbox doesn't support templates
func (s *VirtualBoxExecutor) createVM(vmName string) error {
func (s *executor) createVM(vmName string) error {
baseImage := s.Config.VirtualBox.BaseName
if baseImage == "" {
return errors.New("Missing Image setting from VirtualBox configuration")
......@@ -112,7 +112,7 @@ func (s *VirtualBoxExecutor) createVM(vmName string) error {
return nil
}
func (s *VirtualBoxExecutor) Prepare(globalConfig *common.Config, config *common.RunnerConfig, build *common.Build) error {
func (s *executor) Prepare(globalConfig *common.Config, config *common.RunnerConfig, build *common.Build) error {
err := s.AbstractExecutor.Prepare(globalConfig, config, build)
if err != nil {
return err
......@@ -228,7 +228,7 @@ func (s *VirtualBoxExecutor) Prepare(globalConfig *common.Config, config *common
return nil
}
func (s *VirtualBoxExecutor) Start() error {
func (s *executor) Start() error {
s.Println("Starting SSH command...")
s.sshCommand = ssh.Command{
Config: *s.Config.SSH,
......@@ -257,7 +257,7 @@ func (s *VirtualBoxExecutor) Start() error {
return nil
}
func (s *VirtualBoxExecutor) Cleanup() {
func (s *executor) Cleanup() {
s.sshCommand.Cleanup()
if s.vmName != "" {
......@@ -281,7 +281,7 @@ func init() {
}
creator := func() common.Executor {
return &VirtualBoxExecutor{
return &executor{
AbstractExecutor: executors.AbstractExecutor{
ExecutorOptions: options,
},
......
......@@ -9,19 +9,19 @@ import (
"time"
)
const ZipUidGidFieldType = 0x7875
const ZipUIDGidFieldType = 0x7875
const ZipTimestampFieldType = 0x5455
// from https://github.com/LuaDist/zip/blob/master/proginfo/extrafld.txt
// ZipExtraField is taken from https://github.com/LuaDist/zip/blob/master/proginfo/extrafld.txt
type ZipExtraField struct {
Type uint16
Size uint16
}
type ZipUidGidField struct {
type ZipUIDGidField struct {
Version uint8
UIDSize uint8
Uid uint32
UID uint32
GIDSize uint8
Gid uint32
}
......@@ -69,7 +69,7 @@ func processZipTimestampField(data []byte, file *zip.FileHeader) error {
func createZipExtra(fi os.FileInfo) []byte {
var buffer bytes.Buffer
err := createZipUidGidField(&buffer, fi)
err := createZipUIDGidField(&buffer, fi)
if err == nil {
err = createZipTimestampField(&buffer, fi)
}
......@@ -108,8 +108,8 @@ func processZipExtra(file *zip.FileHeader) error {
}
switch field.Type {
case ZipUidGidFieldType:
err = processZipUidGidField(data, file)
case ZipUIDGidFieldType:
err = processZipUIDGidField(data, file)
case ZipTimestampFieldType:
err = processZipTimestampField(data, file)
}
......
......@@ -22,7 +22,7 @@ func TestCreateZipExtra(t *testing.T) {
data := createZipExtra(fi)
assert.NotEmpty(t, data)
assert.Len(t, data, binary.Size(&ZipExtraField{})*2+
binary.Size(&ZipUidGidField{})+