feat: use odoo ticket number in branch name
This commit is contained in:
parent
85a8e421a9
commit
9fc4cd977d
@ -10,7 +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 }}
|
||||
REPO_OWNER: ${{ gitea.event.repository.owner.login }}
|
||||
|
||||
14
main.go
14
main.go
@ -24,7 +24,7 @@ func main() {
|
||||
logger := log.New(multiWriter, "", log.LstdFlags)
|
||||
|
||||
// Retrieve environment variables
|
||||
issueNumberStr := os.Getenv("ISSUE_NUMBER")
|
||||
issueOdooTicketString := os.Getenv("ODOO_TICKET_NUMBER")
|
||||
issueTitle := os.Getenv("ISSUE_TITLE")
|
||||
labelsStr := os.Getenv("ISSUE_LABELS")
|
||||
|
||||
@ -33,13 +33,13 @@ func main() {
|
||||
repoOwner := os.Getenv("REPO_OWNER")
|
||||
repoName := os.Getenv("REPO_NAME")
|
||||
|
||||
if issueNumberStr == "" || issueTitle == "" || giteaToken == "" || repoOwner == "" || repoName == "" {
|
||||
if issueOdooTicketString == "" || issueTitle == "" || giteaToken == "" || repoOwner == "" || repoName == "" {
|
||||
logger.Println("Error: some environment variables are missing.")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Convert the issue number to int64
|
||||
issueNumber, err := strconv.ParseInt(issueNumberStr, 10, 64)
|
||||
issueOdooTicketID, err := strconv.ParseInt(issueOdooTicketString, 10, 64)
|
||||
if err != nil {
|
||||
logger.Printf("Error while converting the issue number: %v\n", err)
|
||||
os.Exit(1)
|
||||
@ -56,7 +56,7 @@ func main() {
|
||||
}
|
||||
|
||||
// Form the branch name in the format "prefix/ticket-number"
|
||||
branchName := fmt.Sprintf("%s/ticket-%d", prefix, issueNumber)
|
||||
branchName := fmt.Sprintf("%s/ticket-%d", prefix, issueOdooTicketID)
|
||||
|
||||
logger.Printf("Branch name set to: %s\n", branchName)
|
||||
|
||||
@ -114,7 +114,7 @@ func main() {
|
||||
}
|
||||
|
||||
// Assign the branch to the issue via the Gitea API
|
||||
logger.Printf("Assigning branch '%s' to issue #%d.\n", branchName, issueNumber)
|
||||
logger.Printf("Assigning branch '%s' to issue #%d.\n", branchName, issueOdooTicketID)
|
||||
|
||||
// Create the Gitea client
|
||||
client, err := gitea.NewClient(giteaAPIURL, gitea.SetToken(giteaToken))
|
||||
@ -129,13 +129,13 @@ func main() {
|
||||
}
|
||||
|
||||
// Update the issue with the branch reference
|
||||
_, _, err = client.EditIssue(repoOwner, repoName, issueNumber, editIssueOption)
|
||||
_, _, err = client.EditIssue(repoOwner, repoName, issueOdooTicketID, 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, issueNumber)
|
||||
logger.Printf("Branch '%s' successfully assigned to issue #%d.\n", branchName, issueOdooTicketID)
|
||||
}
|
||||
|
||||
// Function to map labels to prefixes
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user