first version of post-receive (with debug info)

lint-refactor
KatolaZ 8 years ago
parent 001bcbdbff
commit 625d1beff9
  1. 37
      commits.go
  2. 10
      exec.go
  3. 39
      hooks/post-receive

@ -94,9 +94,21 @@ func find_tag_config(tag_name string, w *SCORSHworker) (*SCORSHtag_cfg, bool) {
return nil, false
}
// traverse all the commits between two references, looking for scorsh
// commands
// fixme: we don't have just one keyring here....
func get_author_email(c *git.Commit) string {
sig := c.Author()
return sig.Email
}
func get_committer_email(c *git.Commit) string {
sig := c.Committer()
return sig.Email
}
// walk_commits traverses all the commits between two references,
// looking for scorsh commands, and tries to execute those if found
func walk_commits(msg SCORSHmsg, w *SCORSHworker) error {
var tags SCORSHclient_msg
@ -138,13 +150,11 @@ func walk_commits(msg SCORSHmsg, w *SCORSHworker) error {
commit, err := repo.LookupCommit(cur_commit.Id())
if err == nil {
//debug.log("commit: %s", CommitToString(commit))
// We should look for scorsh-tags, and if the commit has any,
// check if it can be verified by any of the keyrings associated
// with that specific scorsh-tag
// check if the commit contains a scorsh command
// We look for scorsh-tags, and if the commit has any, check if
// it can be verified by any of the keyrings associated with
// that specific scorsh-tag
// Check if the commit contains a scorsh command
commit_msg, err = find_scorsh_message(commit)
if err != nil {
log.Printf("[worker: %s] %s\n", w.Name, SCORSHerr(SCORSH_ERR_SIGNATURE))
@ -157,9 +167,9 @@ func walk_commits(msg SCORSHmsg, w *SCORSHworker) error {
// no scorsh message found
log.Printf("[worker: %s] no scorsh message found: %s", err)
} else {
// there is a scorsh message there so
// there is a scorsh message there so....
// 1) get the list of all the keys which verify the message
// 1) get the list of all the keyrings which verify the message
valid_keys := get_valid_keys(commit, &(w.Keys))
debug.log("[worker: %s] validated keyrings on commit: %s\n", w.Name, valid_keys)
@ -174,7 +184,8 @@ func walk_commits(msg SCORSHmsg, w *SCORSHworker) error {
continue
}
// b) check that at least one of the accepted tag keys is in valid_keys
// 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
debug.log("[worker: %s] good_keys: %s\n", w.Name, good_keys)
@ -185,7 +196,7 @@ func walk_commits(msg SCORSHmsg, w *SCORSHworker) error {
// c) If everything is OK, execute the tag
if good_tag && good_keys {
env := set_environment(&msg)
env := set_environment(&msg, t.Tag, get_author_email(), get_committer_email())
errs := exec_tag(tag_cfg, t.Args, env)
debug.log("[worker: %s] errors in tag %s: %s\n", w.Name, t.Tag, errs)
}

@ -48,7 +48,11 @@ func exec_tag(tag *SCORSHtag_cfg, args []string, env []string) []error {
log.Printf("[tag: %s] error parsing URL: %s", tag.Name, err)
} else {
if cmd_url.Scheme == "file" {
//if err = check_hash(cmd_url, c.Hash); err == nil {
err = exec_local_file(cmd_url, args, env)
//} else {
//log.Printf("[tag: %s] WARNING!!! HASH MISMATCH FOR %s\n", cmd_url)
//}
} else if cmd_url.Scheme == "http" || cmd_url.Scheme == "https" {
err = exec_url(cmd_url, args, env)
}
@ -58,7 +62,7 @@ func exec_tag(tag *SCORSHtag_cfg, args []string, env []string) []error {
return ret
}
func set_environment(msg *SCORSHmsg) []string {
func set_environment(msg *SCORSHmsg, tag, author, committer string) []string {
env := os.Environ()
env = append(env, fmt.Sprintf("SCORSH_REPO=%s", msg.Repo))
@ -66,5 +70,9 @@ func set_environment(msg *SCORSHmsg) []string {
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))
env = append(env, fmt.Sprintf("SCORSH_TAG=%s", tag))
env = append(env, fmt.Sprintf("SCORSH_AUTHOR=%s", author))
env = append(env, fmt.Sprintf("SCORSH_COMMITTER=%s", committer))
return env
}

@ -0,0 +1,39 @@
#!/bin/sh
SCORSH_CFG="scorsh"
SCORSH_VAR="scorsh.spooldir"
while read old_value new_value ref; do
echo "arguments: ${old_value} ${new_value} ${ref} "
msg=$(git cat-file -p ${ref})
echo "Got reference:"
printf "$msg"
echo
echo "------"
repo=$(pwd)
branch=$(echo ${ref} | sed -r -e 's:refs/heads/::g')
now=$(date +%s)
id="${new_value}_${now}"
spool_dir=$(git config -f ${SCORSH_CFG} ${SCORSH_VAR})
echo "id: ${id}"
echo "repo: ${repo}"
echo "branch: ${branch}"
echo "old_rev: ${old_value}"
echo "new_rev: ${new_value}"
echo "spool_dir: ${spool_dir}"
done
cat <<EOF
---
m_id: $id
m_repo: $repo
m_branch: $branch
m_oldrev: ${old_value}
m_newrev: ${new_value}
...
EOF>${spool_dir}/${id}
Loading…
Cancel
Save