diff --git a/action.yml b/action.yml index 3ed8497..873ff5a 100644 --- a/action.yml +++ b/action.yml @@ -10,6 +10,7 @@ runs: image: "Dockerfile" env: ISSUE_LABELS: ${{ gitea.event.issue.labels }} + ISSUE_NUMBER: ${{ gitea.event.issue.number }} ODOO_TICKET_NUMBER: ${{ gitea.event.issue.ref }} ISSUE_TITLE: ${{ gitea.event.issue.title }} GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} diff --git a/main.go b/main.go index f50a85c..29b3f9c 100644 --- a/main.go +++ b/main.go @@ -27,24 +27,32 @@ func main() { issueOdooTicketString := os.Getenv("ODOO_TICKET_NUMBER") issueTitle := os.Getenv("ISSUE_TITLE") labelsStr := os.Getenv("ISSUE_LABELS") + issueNumberString := os.Getenv("ISSUE_NUMBER") giteaToken := os.Getenv("GITEA_TOKEN") giteaAPIURL := "https://gitea.ethumada.com" repoOwner := os.Getenv("REPO_OWNER") repoName := os.Getenv("REPO_NAME") - if issueOdooTicketString == "" || issueTitle == "" || giteaToken == "" || repoOwner == "" || repoName == "" { + if issueOdooTicketString == "" || issueNumberString == "" || issueTitle == "" || giteaToken == "" || repoOwner == "" || repoName == "" { logger.Println("Error: some environment variables are missing.") os.Exit(1) } // Convert the issue number to int64 - issueOdooTicketID, err := strconv.ParseInt(issueOdooTicketString, 10, 64) + issueNumber, err := strconv.ParseInt(issueNumberString, 10, 64) if err != nil { logger.Printf("Error while converting the issue number: %v\n", err) os.Exit(1) } + // Convert the odoo ticket number to int64 + issueOdooTicketID, err := strconv.ParseInt(issueOdooTicketString, 10, 64) + if err != nil { + logger.Printf("Error while converting the Odoo ticket number: %v\n", err) + os.Exit(1) + } + // Map labels to Git Flow prefixes prefix := "feature" if labelsStr != "" { @@ -129,13 +137,13 @@ func main() { } // Update the issue with the branch reference - _, _, err = client.EditIssue(repoOwner, repoName, issueOdooTicketID, editIssueOption) + _, _, err = client.EditIssue(repoOwner, repoName, issueNumber, editIssueOption) if err != nil { logger.Printf("Error while assigning the branch to the issue: %v\n", err) os.Exit(1) } - logger.Printf("Branch '%s' successfully assigned to issue #%d.\n", branchName, issueOdooTicketID) + logger.Printf("Branch '%s' successfully assigned to issue #%d.\n", branchName, issueNumber) } // Function to map labels to prefixes