moved stuff in exec.go

lint-refactor
KatolaZ 8 years ago
parent 37a6d33f46
commit 7a4cdc99d9
  1. 5
      Makefile
  2. 20
      commits.go
  3. 71
      exec.go

@ -5,7 +5,8 @@ types.go \
config.go \ config.go \
spooler.go \ spooler.go \
commits.go \ commits.go \
workers.go workers.go \
exec.go
all: scorshd all: scorshd
@ -16,7 +17,7 @@ deps:
go get 'golang.org/x/crypto/openpgp' go get 'golang.org/x/crypto/openpgp'
scorshd: $(SERVER_SOURCES) scorshd: $(SERVER_SOURCES)
$(BUILD) scorshd.go types.go config.go spooler.go commits.go workers.go $(BUILD) $(SERVER_SOURCES)
clean: clean:
rm scorshd rm scorshd

@ -94,18 +94,6 @@ func find_tag_config(tag_name string, w *SCORSHworker) (*SCORSHtag_cfg, bool) {
return nil, false return nil, false
} }
func exec_tag(tag *SCORSHtag_cfg) []error {
var ret []error
for _, c := range tag.Commands {
debug.log("[tag: %s] attempting command: %s\n", tag.Name, c.URL)
ret = append(ret, nil)
}
return ret
}
// traverse all the commits between two references, looking for scorsh // traverse all the commits between two references, looking for scorsh
// commands // commands
// fixme: we don't have just one keyring here.... // fixme: we don't have just one keyring here....
@ -182,6 +170,7 @@ func walk_commits(msg SCORSHmsg, w *SCORSHworker) error {
debug.log("[worker: %s] good_tag: %s\n", w.Name, good_tag) debug.log("[worker: %s] good_tag: %s\n", w.Name, good_tag)
if !good_tag { if !good_tag {
debug.log("[worker: %s] unsupported tag: %s\n", w.Name, t.Tag)
continue continue
} }
@ -190,20 +179,19 @@ func walk_commits(msg SCORSHmsg, w *SCORSHworker) error {
debug.log("[worker: %s] good_keys: %s\n", w.Name, good_keys) debug.log("[worker: %s] good_keys: %s\n", w.Name, good_keys)
if !good_keys { if !good_keys {
debug.log("[worker: %s] no matching keys for tag: %s\n", w.Name, t.Tag)
continue continue
} }
// c) If everything is OK, execute the tag // c) If everything is OK, execute the tag
if good_tag && good_keys { if good_tag && good_keys {
errs := exec_tag(tag_cfg) env := set_environment(&msg)
errs := exec_tag(tag_cfg, t.Args, env)
debug.log("[worker: %s] errors in tag %s: %s\n", w.Name, t.Tag, errs) debug.log("[worker: %s] errors in tag %s: %s\n", w.Name, t.Tag, errs)
} }
} }
} }
//signature, signed, err := check_signature(commit, &w.Keys)
//_, _, err := check_signature(commit, w.keys)
cur_commit = commit.Parent(0) cur_commit = commit.Parent(0)
} else { } else {
fmt.Printf("Commit %x not found!\n", cur_commit.Id()) fmt.Printf("Commit %x not found!\n", cur_commit.Id())

@ -0,0 +1,71 @@
package main
import (
"fmt"
"log"
"net/url"
"os"
"os/exec"
)
func exec_local_file(cmd_url *url.URL, args, env []string) error {
cmd := exec.Command(cmd_url.Path, args...)
cmd.Env = env
stdout, err := cmd.StdoutPipe()
if err != nil {
return nil
}
if err == nil {
err = cmd.Start()
if err == nil {
var output []byte
_, err := stdout.Read(output)
if err != nil {
log.Printf("[%s - stout follows: ]\n%s\n", output)
err = cmd.Wait()
}
}
}
return err
}
func exec_url(cmd_url *url.URL, args, env []string) error {
return nil
}
func exec_tag(tag *SCORSHtag_cfg, args []string, env []string) []error {
var ret []error
for _, c := range tag.Commands {
debug.log("[tag: %s] attempting command: %s\n", tag.Name, c.URL)
cmd_url, err := url.Parse(c.URL)
if err != nil {
log.Printf("[tag: %s] error parsing URL: %s", tag.Name, err)
} else {
if cmd_url.Scheme == "file" {
err = exec_local_file(cmd_url, args, env)
} else if cmd_url.Scheme == "http" || cmd_url.Scheme == "https" {
err = exec_url(cmd_url, args, env)
}
}
ret = append(ret, err)
}
return ret
}
func set_environment(msg *SCORSHmsg) []string {
env := os.Environ()
env = append(env, fmt.Sprintf("SCORSH_REPO=%s", msg.Repo))
env = append(env, fmt.Sprintf("SCORSH_BRANCH=%s", msg.Branch))
env = append(env, fmt.Sprintf("SCORSH_OLDREV=%s", msg.Old_rev))
env = append(env, fmt.Sprintf("SCORSH_NEWREV_=%s", msg.New_rev))
env = append(env, fmt.Sprintf("SCORSH_ID_=%s", msg.Id))
return env
}
Loading…
Cancel
Save