Compare commits

..

No commits in common. "main" and "v1.1" have entirely different histories.
main ... v1.1

2 changed files with 8 additions and 21 deletions

View File

@ -10,16 +10,12 @@ inputs:
base_url: base_url:
description: 'Base URL of the FastAPI server.' description: 'Base URL of the FastAPI server.'
required: true required: true
auth_token:
description: 'Bearer token for authenticating to the FastAPI server.'
required: true
runs: runs:
using: 'docker' using: 'docker'
image: 'Dockerfile' image: 'Dockerfile'
env: env:
BASE_URL: ${{ inputs.base_url }} BASE_URL: ${{ inputs.base_url }}
AUTH_TOKEN: ${{ inputs.auth_token }}
BRANCH_REF: ${{ gitea.event.issue.ref }} BRANCH_REF: ${{ gitea.event.issue.ref }}
ISSUE_STATE: ${{ gitea.event.issue.state }} ISSUE_STATE: ${{ gitea.event.issue.state }}
ISSUE_ASSIGNEES: ${{ join(gitea.event.issue.assignees.*.login, ',') }} ISSUE_ASSIGNEES: ${{ join(gitea.event.issue.assignees.*.login, ',') }}

25
main.go
View File

@ -12,10 +12,10 @@ import (
) )
type Payload struct { type Payload struct {
TaskID int64 `json:"task_id"` TaskID int64 `json:"task_id"`
State string `json:"state"` State string `json:"state"`
UserIDs []string `json:"user_ids"` Assignees []string `json:"assignees"`
DueDate string `json:"date_deadline,omitempty"` DueDate string `json:"date_deadline,omitempty"`
} }
func splitCSV(value string) []string { func splitCSV(value string) []string {
@ -54,11 +54,6 @@ func main() {
issueAssignees := splitCSV(os.Getenv("ISSUE_ASSIGNEES")) issueAssignees := splitCSV(os.Getenv("ISSUE_ASSIGNEES"))
issueDueDate := os.Getenv("ISSUE_DUE_DATE") issueDueDate := os.Getenv("ISSUE_DUE_DATE")
branchRef := os.Getenv("BRANCH_REF") branchRef := os.Getenv("BRANCH_REF")
authToken := os.Getenv("AUTH_TOKEN")
if strings.TrimSpace(authToken) == "" {
logger.Println("AUTH_TOKEN not provided. Please pass 'auth_token' input mapped to a secret.")
os.Exit(1)
}
var odooTicketNumber int64 var odooTicketNumber int64
if branchRef != "" { if branchRef != "" {
@ -74,10 +69,10 @@ func main() {
} }
payload := Payload{ payload := Payload{
TaskID: odooTicketNumber, TaskID: odooTicketNumber,
State: issueState, State: issueState,
UserIDs: issueAssignees, Assignees: issueAssignees,
DueDate: issueDueDate, DueDate: issueDueDate,
} }
payloadBytes, err := json.Marshal([]Payload{payload}) payloadBytes, err := json.Marshal([]Payload{payload})
@ -93,7 +88,6 @@ func main() {
os.Exit(1) os.Exit(1)
} }
req.Header.Set("Content-Type", "application/json") req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+authToken)
resp, err := http.DefaultClient.Do(req) resp, err := http.DefaultClient.Do(req)
if err != nil { if err != nil {
@ -103,9 +97,6 @@ func main() {
defer resp.Body.Close() defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body) body, _ := io.ReadAll(resp.Body)
logger.Printf("Status: %s\nResponse: %s\n", resp.Status, string(body)) logger.Printf("Status: %s\nResponse: %s\n", resp.Status, string(body))
if resp.StatusCode == http.StatusUnauthorized || resp.StatusCode == http.StatusForbidden {
logger.Println("Authentication to FastAPI failed. Check FASTAPI token.")
}
if resp.StatusCode < 200 || resp.StatusCode >= 300 { if resp.StatusCode < 200 || resp.StatusCode >= 300 {
os.Exit(1) os.Exit(1)
} }