Skip to content

Instantly share code, notes, and snippets.

@vinchi777
Last active April 1, 2020 15:51
Show Gist options
  • Save vinchi777/0f64c087b0744014ba3096457259b3a6 to your computer and use it in GitHub Desktop.
Save vinchi777/0f64c087b0744014ba3096457259b3a6 to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"os/exec"
"time"
)
const project_dir = "/Users/fullscale/Rails/agencieshq"
const git_author = "jude_cali"
const url = "https://fullscale.rocks/api/employee-reports"
func main() {
api_key := os.Getenv("API_KEY")
commits := GetCommits()
form := fullscaleForm(commits)
submitReport(api_key, form)
}
func fullscaleForm(commits string) map[string]string {
dt := time.Now()
date := dt.Format("2006-01-02")
client_project_id := "10"
employee_id := "765"
reporter := "Calimbas, Jude Bacasmas"
send_to := "reports@fullscale.io"
projct_name := "OneHQ"
form := map[string]string{
"content": fmt.Sprintf("<p>%s</p>", commits),
"todo": "Pick new tickets",
"roadblocks": "None",
"remarks": "",
"subject": fmt.Sprintf("%s : Daily Report (%s) - %s", projct_name, date, reporter),
"employee_id": employee_id,
"send_to": send_to,
"report_template_id": "1",
"client_project_id": client_project_id,
"report_date": date,
"sent": "0",
}
return form
}
func submitReport(api_key string, form map[string]string) {
client := &http.Client{}
jsonValue, _ := json.Marshal(form)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonValue))
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", api_key))
req.Header.Set("Content-Type", "application/json")
resp, err := client.Do(req)
if err != nil {
log.Fatalln(err)
}
body, err := ioutil.ReadAll(resp.Body)
fmt.Println("post:\n", string(body))
}
func GetCommits() string {
cmd := exec.Command("git", "log", "--format=%B", "--since='6am'", "--branches", fmt.Sprintf("--author=%s", git_author))
cmd.Dir = project_dir
out, err := cmd.Output()
if err != nil {
log.Fatal(err)
}
return string(out)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment