Post MR cleanup (better error handling, comments, etc)

This commit is contained in:
Harrison Cramer
2023-05-20 09:42:00 -07:00
parent 27ec4668c1
commit f5038656a9
3 changed files with 53 additions and 72 deletions

View File

@@ -11,16 +11,22 @@ import (
)
func main() {
branchName, err := getCurrentBranch()
errCheck(err)
if err != nil {
log.Fatalf("Failure: Failed to get current branch: %v", err)
}
if branchName == "main" || branchName == "master" {
log.Fatalf("Cannot run on %s branch", branchName)
}
/* Initialize Gitlab client */
var c Client
errCheck(c.Init(branchName))
if err := c.Init(branchName); err != nil {
log.Fatalf("Failure: Failed to iniialize client: %v", err)
}
m := http.NewServeMux()
m.Handle("/approve", withGitlabContext(http.HandlerFunc(ApproveHandler), c))
@@ -45,10 +51,6 @@ func main() {
<-done
}
type ResponseError struct {
message string
}
func withGitlabContext(next http.HandlerFunc, c Client) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := context.WithValue(context.Background(), "client", c)
@@ -56,13 +58,6 @@ func withGitlabContext(next http.HandlerFunc, c Client) http.Handler {
})
}
func errCheck(err error) {
if err != nil {
log.Fatalf("Failure: %s", err)
os.Exit(1)
}
}
/* Gets the current branch */
func getCurrentBranch() (res string, e error) {
gitCmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD")
@@ -73,5 +68,4 @@ func getCurrentBranch() (res string, e error) {
}
return strings.TrimSpace(string(output)), nil
}