fix: use issue in gitea sdk

This commit is contained in:
Mandresy RABENJAHARISON 2025-08-21 11:28:27 +03:00
parent 9fc4cd977d
commit c9d46dbf21
2 changed files with 13 additions and 4 deletions

View File

@ -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 }}

16
main.go
View File

@ -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