fixed bug in parsing non-scorsh commits

lint-refactor
KatolaZ 8 years ago
parent b0aa804366
commit b3e10f839c
  1. 98
      commits.go
  2. 18
      types.go
  3. 2
      workers.go

@ -35,7 +35,7 @@ func check_signature(commit *git.Commit, keyring *openpgp.KeyRing) (signature, s
strings.NewReader(signature)) strings.NewReader(signature))
if err_sig == nil { if err_sig == nil {
fmt.Printf("Good signature \n") debug.log("[commit: %s] Good signature \n", commit.Id())
return signature, signed, nil return signature, signed, nil
} }
err = err_sig err = err_sig
@ -49,11 +49,14 @@ func find_scorsh_message(commit *git.Commit) (string, error) {
sep := "---\n" sep := "---\n"
msg := commit.RawMessage() msg := commit.RawMessage()
debug.log("[find_scorsg_msg] found message:\n %s\n", msg) debug.log("[find_scorsg_msg] found message:\n%s\n", msg)
// FIXME!!! replace the following with a proper regexp.Match // FIXME!!! replace the following with a proper regexp.Match
idx := strings.Index(msg, sep) idx := strings.Index(msg, sep)
if idx < 0 {
return "", fmt.Errorf("no SCORSH message found\n")
}
return msg[idx:], nil return msg[idx:], nil
} }
@ -114,7 +117,7 @@ func walk_commits(msg SCORSHmsg, w *SCORSHworker) error {
var tags SCORSHclient_msg var tags SCORSHclient_msg
var commit_msg string var commit_msg string
fmt.Printf("Inside parse_commits\n") debug.log("[worker: %s] Inside parse_commits\n", w.Name)
reponame := msg.Repo reponame := msg.Repo
old_rev := msg.Old_rev old_rev := msg.Old_rev
@ -145,6 +148,7 @@ func walk_commits(msg SCORSHmsg, w *SCORSHworker) error {
cur_commit := newrev_commit cur_commit := newrev_commit
// FIXME: replace with a queue of commits
for cur_commit.Id().String() != oldrev_commit.Id().String() { for cur_commit.Id().String() != oldrev_commit.Id().String() {
commit, err := repo.LookupCommit(cur_commit.Id()) commit, err := repo.LookupCommit(cur_commit.Id())
@ -156,53 +160,53 @@ func walk_commits(msg SCORSHmsg, w *SCORSHworker) error {
// Check if the commit contains a scorsh command // Check if the commit contains a scorsh command
commit_msg, err = find_scorsh_message(commit) commit_msg, err = find_scorsh_message(commit)
if err != nil { if err == nil {
log.Printf("[worker: %s] %s\n", w.Name, SCORSHerr(SCORSH_ERR_SIGNATURE)) // Check if is the comment contains a valid scorsh message
} err = yaml.Unmarshal([]byte(commit_msg), &tags)
// Check if is the comment contains a valid scorsh message if err != nil {
err = yaml.Unmarshal([]byte(commit_msg), &tags) // no scorsh message found
err = fmt.Errorf("unmarshal error: %s", err)
if err != nil { } else {
// no scorsh message found // there is a scorsh message there so....
log.Printf("[worker: %s] no scorsh message found: %s", err)
} else { // 1) get the list of all the keyrings which verify the message
// there is a scorsh message there so.... valid_keys := get_valid_keys(commit, &(w.Keys))
debug.log("[worker: %s] validated keyrings on commit: %s\n", w.Name, valid_keys)
// 1) get the list of all the keyrings which verify the message
valid_keys := get_valid_keys(commit, &(w.Keys)) // 2) then for each tag in the message
debug.log("[worker: %s] validated keyrings on commit: %s\n", w.Name, valid_keys) for _, t := range tags.Tags {
// a) check that the tag is among those accepted by the worker
// 2) then for each tag in the message tag_cfg, good_tag := find_tag_config(t.Tag, w)
for _, t := range tags.Tags { debug.log("[worker: %s] good_tag: %s\n", w.Name, good_tag)
// a) check that the tag is among those accepted by the worker
tag_cfg, good_tag := find_tag_config(t.Tag, w) if !good_tag {
debug.log("[worker: %s] good_tag: %s\n", w.Name, good_tag) debug.log("[worker: %s] unsupported tag: %s\n", w.Name, t.Tag)
continue
if !good_tag { }
debug.log("[worker: %s] unsupported tag: %s\n", w.Name, t.Tag)
continue // b) check that at least one of the accepted tag keyrings
} // is in valid_keys
good_keys := intersect_keys(w.TagKeys[t.Tag], valid_keys) != nil
// b) check that at least one of the accepted tag keyrings debug.log("[worker: %s] good_keys: %s\n", w.Name, good_keys)
// is in valid_keys
good_keys := intersect_keys(w.TagKeys[t.Tag], valid_keys) != nil if !good_keys {
debug.log("[worker: %s] good_keys: %s\n", w.Name, good_keys) debug.log("[worker: %s] no matching keys for tag: %s\n", w.Name, t.Tag)
continue
if !good_keys { }
debug.log("[worker: %s] no matching keys for tag: %s\n", w.Name, t.Tag)
continue // c) If everything is OK, execute the tag
} if good_tag && good_keys {
env := set_environment(&msg, t.Tag, get_author_email(commit), get_committer_email(commit))
// c) If everything is OK, execute the tag errs := exec_tag(tag_cfg, t.Args, env)
if good_tag && good_keys { debug.log("[worker: %s] errors in tag %s: %s\n", w.Name, t.Tag, errs)
env := set_environment(&msg, t.Tag, get_author_email(commit), get_committer_email(commit)) }
errs := exec_tag(tag_cfg, t.Args, env)
debug.log("[worker: %s] errors in tag %s: %s\n", w.Name, t.Tag, errs)
} }
} }
} else {
log.Printf("[worker: %s] error parsing commit %s: %s", w.Name, cur_commit.Id().String(), err)
} }
// FIXME: ADD ALL THE PARENTS TO THE QUEUE OF COMMITS
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())

@ -38,14 +38,14 @@ type SCORSHtag_cfg struct {
// Configuration of a worker // Configuration of a worker
type SCORSHworker_cfg struct { type SCORSHworker_cfg struct {
Name string `yaml:"w_name"` Name string `yaml:"w_name"`
Repos []string `yaml:"w_repos"` Repos []string `yaml:"w_repos"`
Folder string `yaml:"w_folder"` Folder string `yaml:"w_folder"`
Logfile string `yaml:"w_logfile"` Logfile string `yaml:"w_logfile"`
Tagfile string `yaml:"w_tagfile"` Tagfile string `yaml:"w_tagfile"`
Keyrings []string `yaml:"w_keyrings"` // Keyrings []string `yaml:"w_keyrings"`
Tags []SCORSHtag_cfg `yaml:"w_tags"` Tags []SCORSHtag_cfg `yaml:"w_tags"`
TagKeys map[string]map[string]bool TagKeys map[string]map[string]bool
} }
// State of a worker // State of a worker
@ -136,7 +136,7 @@ func (w *SCORSHworker) String() string {
fmt.Fprintf(&buff, "Folder: %s\n", w.Folder) fmt.Fprintf(&buff, "Folder: %s\n", w.Folder)
fmt.Fprintf(&buff, "Logfile: %s\n", w.Logfile) fmt.Fprintf(&buff, "Logfile: %s\n", w.Logfile)
fmt.Fprintf(&buff, "Tagfile: %s\n", w.Tagfile) fmt.Fprintf(&buff, "Tagfile: %s\n", w.Tagfile)
fmt.Fprintf(&buff, "Keyrings: %s\n", w.Keyrings) // fmt.Fprintf(&buff, "Keyrings: %s\n", w.Keyrings)
return buff.String() return buff.String()
} }

@ -30,7 +30,7 @@ func (worker *SCORSHworker) Matches(repo, branch string) bool {
func (w *SCORSHworker) LoadKeyrings() error { func (w *SCORSHworker) LoadKeyrings() error {
w.Keys = make(map[string]openpgp.KeyRing, len(w.Keyrings)) w.Keys = make(map[string]openpgp.KeyRing)
w.TagKeys = make(map[string]map[string]bool) w.TagKeys = make(map[string]map[string]bool)
for _, t := range w.Tags { for _, t := range w.Tags {

Loading…
Cancel
Save