From 991806249228e6ce21f254d91f2811e3e54baf6f Mon Sep 17 00:00:00 2001 From: Mandresy RABENJAHARISON Date: Thu, 21 Aug 2025 14:17:08 +0300 Subject: [PATCH] refactor : refact payload structure and environment variables in main.go and action.yml to remove unused fields and utilize branch reference for task ID extraction --- README.md | 6 ------ action.yml | 6 +----- main.go | 31 +++++++++++++------------------ 3 files changed, 14 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 74a66f9..b97a8c8 100644 --- a/README.md +++ b/README.md @@ -14,20 +14,14 @@ The action builds a JSON array with a single object from the issue event: [ { "task_id": 123, - "title": "Issue Title", - "body": "Issue body/description", "state": "open", - "author": "jdoe", "assignees": ["alice", "bob"], - "labels": ["bug", "backend"], "date_deadline": "2025-05-06" } ] ``` - `task_id`: from `${{ gitea.event.issue.number }}` -- `title`: from `${{ gitea.event.issue.title }}` -- `body`: from `${{ gitea.event.issue.body }}` - `state`: from `${{ gitea.event.issue.state }}` ("open" or "closed") - `author`: from `${{ gitea.event.issue.user.login }}` - `assignees`: from `${{ join(gitea.event.issue.assignees.*.login, ',') }}` (expanded and split) diff --git a/action.yml b/action.yml index c412106..10f6f7f 100644 --- a/action.yml +++ b/action.yml @@ -16,11 +16,7 @@ runs: image: 'Dockerfile' env: BASE_URL: ${{ inputs.base_url }} - ISSUE_NUMBER: ${{ gitea.event.issue.number }} - ISSUE_TITLE: ${{ gitea.event.issue.title }} - ISSUE_BODY: ${{ gitea.event.issue.body }} + BRANCH_REF: ${{ gitea.event.issue.ref }} ISSUE_STATE: ${{ gitea.event.issue.state }} - ISSUE_AUTHOR: ${{ gitea.event.issue.user.login }} ISSUE_ASSIGNEES: ${{ join(gitea.event.issue.assignees.*.login, ',') }} - ISSUE_LABELS: ${{ join(gitea.event.issue.labels.*.name, ',') }} ISSUE_DUE_DATE: ${{ gitea.event.issue.due_date }} diff --git a/main.go b/main.go index ea1333a..84abc9f 100644 --- a/main.go +++ b/main.go @@ -13,12 +13,8 @@ import ( type Payload struct { TaskID int64 `json:"task_id"` - Title string `json:"title"` - Body string `json:"body"` State string `json:"state"` - Author string `json:"author"` Assignees []string `json:"assignees"` - Labels []string `json:"labels"` DueDate string `json:"date_deadline,omitempty"` } @@ -54,29 +50,28 @@ func main() { logger := log.New(io.MultiWriter(os.Stdout, logFile), "", log.LstdFlags) // Build payload from env - issueNumber := os.Getenv("ISSUE_NUMBER") - issueTitle := os.Getenv("ISSUE_TITLE") - issueBody := os.Getenv("ISSUE_BODY") issueState := os.Getenv("ISSUE_STATE") - issueAuthor := os.Getenv("ISSUE_AUTHOR") issueAssignees := splitCSV(os.Getenv("ISSUE_ASSIGNEES")) - issueLabels := splitCSV(os.Getenv("ISSUE_LABELS")) issueDueDate := os.Getenv("ISSUE_DUE_DATE") + branchRef := os.Getenv("BRANCH_REF") - var taskID int64 - if issueNumber != "" { - // Best-effort parse; if it fails, taskID remains 0 - fmt.Sscanf(issueNumber, "%d", &taskID) + var odooTicketNumber int64 + if branchRef != "" { + // Expect format: /ticket-OdooTicketNumber + parts := strings.Split(branchRef, "/") + for _, part := range parts { + if strings.HasPrefix(part, "ticket-") { + ticketStr := strings.TrimPrefix(part, "ticket-") + fmt.Sscanf(ticketStr, "%d", &odooTicketNumber) + break + } + } } payload := Payload{ - TaskID: taskID, - Title: issueTitle, - Body: issueBody, + TaskID: odooTicketNumber, State: issueState, - Author: issueAuthor, Assignees: issueAssignees, - Labels: issueLabels, DueDate: issueDueDate, }