-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
113 changed files
with
9,193 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/bash | ||
echo "Compiling..." | ||
GOOS=linux CGO_ENABLED=0 go build main.go | ||
upx main | ||
echo "Zipping..." | ||
zip functions.zip main | ||
echo "Sending..." | ||
aws lambda update-function-code \ | ||
--function-name TestFunction \ | ||
--zip-file fileb://functions.zip | jq ".LastUpdateStatus" | ||
echo "Cleaning..." | ||
rm main functions.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,58 @@ | ||
package jira | ||
|
||
import "encoding/json" | ||
import ( | ||
"encoding/json" | ||
) | ||
|
||
|
||
//Types for JSON Deserialization | ||
type JiraWorklog struct { | ||
type Worklog struct { | ||
TimeSpentSeconds int `json:"timeSpentSeconds"` | ||
Date string `json:"created"` | ||
} | ||
|
||
func (w *Worklog) GetDate() string { | ||
return w.Date[0:10] | ||
} | ||
|
||
type JiraWorklogsField struct { | ||
Worklogs []JiraWorklog `json:"worklogs"` | ||
func (w *Worklog) GetHours() float64 { | ||
return float64(w.TimeSpentSeconds) / 3600 | ||
} | ||
|
||
type WorklogsField struct { | ||
Worklogs []Worklog `json:"worklogs"` | ||
|
||
} | ||
type JiraRequestFields struct { | ||
TimesheetCode string `json:"customfield_10101"` | ||
Worklog JiraWorklogsField `json:"worklog"` | ||
type RequestFields struct { | ||
TimesheetCode string `json:"customfield_10101"` //CUSTOM FIELD WITH ODOO TIMESHEET CODE | ||
Worklog WorklogsField `json:"worklog"` | ||
} | ||
|
||
type JiraUser struct { | ||
type User struct { | ||
Key string `json:"key"` | ||
Email string `json:"emailAddress"` | ||
} | ||
|
||
type JiraIssue struct { | ||
Key string `json:"key"` | ||
Fields JiraRequestFields `json:"fields"` | ||
type Issue struct { | ||
Key string `json:"key"` | ||
Fields RequestFields `json:"fields"` | ||
|
||
} | ||
|
||
type JiraRequest struct { | ||
User JiraUser `json:"user"` | ||
Issue JiraIssue `json:"issue"` | ||
type Request struct { | ||
User User `json:"user"` | ||
Issue Issue `json:"issue"` | ||
|
||
} | ||
|
||
func NewWorklogRequest(body string) (JiraRequest, error) { | ||
var jiraRequest JiraRequest | ||
func NewWorklogRequest(body string) (Request, error) { | ||
var jiraRequest Request | ||
err := json.Unmarshal([]byte(body),&jiraRequest) | ||
return jiraRequest, err | ||
} | ||
|
||
func (r *JiraRequest) GetLastWorklogTime() int { | ||
func (r *Request) GetLastWorklog() Worklog { | ||
var worklogs = r.Issue.Fields.Worklog.Worklogs | ||
var lastWorklog = worklogs[len(worklogs)-1] | ||
return lastWorklog.TimeSpentSeconds | ||
var lastWorklog = worklogs[len(worklogs) -1] | ||
return lastWorklog | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package odoo | ||
|
||
import ( | ||
"errors" | ||
odoo "jira-timesheet/odoo_api_wrapper" | ||
"os" | ||
) | ||
func CreateTimesheetLine(name string, email string, timesheetCode string, hours float64, date string) error{ | ||
c, err := odoo.NewClient(&odoo.ClientConfig{ | ||
Admin: os.Getenv("ODOO_ADMIN"), | ||
Password: os.Getenv("ODOO_PASSWORD"), | ||
Database: os.Getenv("ODOO_DB"), | ||
URL: os.Getenv("ODOO_URL"), | ||
}) | ||
if err != nil { | ||
return errors.New("Can't connect to Odoo, Error: "+err.Error()) | ||
} | ||
var taskSearch = odoo.Criteria{} | ||
taskSearch.Add("code","=",timesheetCode) | ||
task, err := c.FindProjectTask(&taskSearch) | ||
if err != nil || task == nil{ | ||
return errors.New("Can't find any Odoo task with "+timesheetCode+" code") | ||
} | ||
|
||
|
||
var employeeSearch = odoo.Criteria{} | ||
employeeSearch.Add("work_email","=",email) | ||
employee, err := c.FindHrEmployee(&employeeSearch) | ||
if err != nil || employee == nil{ | ||
return errors.New("Can't find any Odoo employee with "+email+" as mail adress") | ||
} | ||
|
||
|
||
|
||
var accountAnalyticLine = odoo.AccountAnalyticLine{ | ||
EmployeeId: odoo.NewMany2One(employee.Id.Get(), employee.Name.Get()), | ||
TaskId: odoo.NewMany2One(task.Id.Get(), task.Name.Get()), | ||
ProjectId: task.ProjectId, | ||
UnitAmount: odoo.NewFloat(hours), | ||
UserId: employee.UserId, | ||
Date: odoo.NewString(date), | ||
Name: odoo.NewString(name), | ||
} | ||
|
||
_, err = c.CreateAccountAnalyticLine(&accountAnalyticLine) | ||
|
||
if err != nil { | ||
return errors.New("Can't create Analytic Line. Error: "+err.Error()) | ||
} | ||
return nil | ||
|
||
|
||
|
||
} |
Oops, something went wrong.