Browse Source

wrap log

master
AJ ONeal 3 years ago
parent
commit
c3cd41a24f
  1. 14
      internal/api/api.go
  2. 10
      internal/log/log.go
  3. 4
      internal/webhooks/bitbucket/bitbucket.go
  4. 2
      internal/webhooks/gitea/gitea.go
  5. 2
      internal/webhooks/github/github.go
  6. 2
      main.go

14
internal/api/api.go

@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"os/exec"
@ -13,6 +12,7 @@ import (
"strings"
"time"
"git.rootprojects.org/root/gitdeploy/internal/log"
"git.rootprojects.org/root/gitdeploy/internal/options"
"git.rootprojects.org/root/gitdeploy/internal/webhooks"
@ -79,7 +79,7 @@ func Route(r chi.Router, runOpts *options.ServerConfig) {
// r.Body is always .Close()ed by Go's http server
r.Body = http.MaxBytesReader(w, r.Body, options.DefaultMaxBodySize)
// TODO admin auth middleware
log.Println("TODO: handle authentication")
log.Printf("TODO: handle authentication")
next.ServeHTTP(w, r)
})
})
@ -153,7 +153,7 @@ func Route(r chi.Router, runOpts *options.ServerConfig) {
decoder := json.NewDecoder(r.Body)
msg := &KillMsg{}
if err := decoder.Decode(msg); nil != err {
log.Println("kill job invalid json:", err)
log.Printf("kill job invalid json:\n%v", err)
http.Error(w, "invalid json body", http.StatusBadRequest)
return
}
@ -178,12 +178,12 @@ func Route(r chi.Router, runOpts *options.ServerConfig) {
decoder := json.NewDecoder(r.Body)
msg := &webhooks.Ref{}
if err := decoder.Decode(msg); nil != err {
log.Println("promotion job invalid json:", err)
log.Printf("promotion job invalid json:\n%v", err)
http.Error(w, "invalid json body", http.StatusBadRequest)
return
}
if "" == msg.HTTPSURL || "" == msg.RefName {
log.Println("promotion job incomplete json", msg)
log.Printf("promotion job incomplete json %s", msg)
http.Error(w, "incomplete json body", http.StatusBadRequest)
return
}
@ -196,7 +196,7 @@ func Route(r chi.Router, runOpts *options.ServerConfig) {
}
}
if n < 0 {
log.Println("promotion job invalid: cannot promote:", n)
log.Printf("promotion job invalid: cannot promote: %d", n)
http.Error(w, "invalid promotion", http.StatusBadRequest)
return
}
@ -319,7 +319,7 @@ func remove(jobID string, nokill bool) {
if nil != job.Cmd.Process {
// but definitely was started
err := job.Cmd.Process.Kill()
log.Println("error killing job:", err)
log.Printf("error killing job:\n%v", err)
}
}
}

10
internal/log/log.go

@ -0,0 +1,10 @@
package log
import (
"log"
)
// Printf wraps log.Printf
func Printf(msg string, els ...interface{}) {
log.Printf(msg, els...)
}

4
internal/webhooks/bitbucket/bitbucket.go

@ -5,11 +5,11 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"strings"
"git.rootprojects.org/root/gitdeploy/internal/log"
"git.rootprojects.org/root/gitdeploy/internal/options"
"git.rootprojects.org/root/gitdeploy/internal/webhooks"
@ -114,7 +114,7 @@ func InitWebhook(providername string, secretList *string, envname string) func()
branch = refName
ref = fmt.Sprintf("refs/heads/%s", refName)
default:
log.Println("unexpected bitbucket RefType", refType)
log.Printf("unexpected bitbucket RefType %s\n", refType)
ref = fmt.Sprintf("refs/UNKNOWN/%s", refName)
}

2
internal/webhooks/gitea/gitea.go

@ -7,11 +7,11 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"strings"
"git.rootprojects.org/root/gitdeploy/internal/log"
"git.rootprojects.org/root/gitdeploy/internal/options"
"git.rootprojects.org/root/gitdeploy/internal/webhooks"

2
internal/webhooks/github/github.go

@ -3,11 +3,11 @@ package github
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"strings"
"git.rootprojects.org/root/gitdeploy/internal/log"
"git.rootprojects.org/root/gitdeploy/internal/options"
"git.rootprojects.org/root/gitdeploy/internal/webhooks"

2
main.go

@ -5,7 +5,6 @@ import (
"encoding/json"
"flag"
"fmt"
"log"
"net/http"
"os"
"path/filepath"
@ -15,6 +14,7 @@ import (
"git.rootprojects.org/root/gitdeploy/assets/examples"
"git.rootprojects.org/root/gitdeploy/assets/public"
"git.rootprojects.org/root/gitdeploy/internal/api"
"git.rootprojects.org/root/gitdeploy/internal/log"
"git.rootprojects.org/root/gitdeploy/internal/options"
"git.rootprojects.org/root/gitdeploy/internal/webhooks"
"git.rootprojects.org/root/vfscopy"

Loading…
Cancel
Save