chore: convert line ending
This commit is contained in:
parent
c6634be696
commit
572ecfa889
76
main.go
76
main.go
@ -13,17 +13,17 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Créer un logger pour écrire les messages d'erreur
|
||||
// Create a logger to write error messages
|
||||
logFile, err := os.OpenFile("action.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
|
||||
if err != nil {
|
||||
fmt.Printf("Erreur lors de la création du fichier de log : %v\n", err)
|
||||
fmt.Printf("Error while creating the log file: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer logFile.Close()
|
||||
multiWriter := io.MultiWriter(os.Stdout, logFile)
|
||||
logger := log.New(multiWriter, "", log.LstdFlags)
|
||||
|
||||
// Récupérer les variables d'environnement
|
||||
// Retrieve environment variables
|
||||
issueNumberStr := os.Getenv("ISSUE_NUMBER")
|
||||
issueTitle := os.Getenv("ISSUE_TITLE")
|
||||
labelsStr := os.Getenv("ISSUE_LABELS")
|
||||
@ -34,57 +34,57 @@ func main() {
|
||||
repoName := os.Getenv("REPO_NAME")
|
||||
|
||||
if issueNumberStr == "" || issueTitle == "" || giteaToken == "" || giteaAPIURL == "" || repoOwner == "" || repoName == "" {
|
||||
logger.Println("Erreur : certaines variables d'environnement sont manquantes.")
|
||||
logger.Println("Error: some environment variables are missing.")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Convertir le numéro de l'issue en int64
|
||||
// Convert the issue number to int64
|
||||
issueNumber, err := strconv.ParseInt(issueNumberStr, 10, 64)
|
||||
if err != nil {
|
||||
logger.Printf("Erreur lors de la conversion du numéro de l'issue : %v\n", err)
|
||||
logger.Printf("Error while converting the issue number: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Mapper les labels aux préfixes Git Flow
|
||||
// Map labels to Git Flow prefixes
|
||||
prefix := "feature"
|
||||
if labelsStr != "" {
|
||||
prefix, err = getPrefixFromLabels(labelsStr)
|
||||
}
|
||||
if err != nil {
|
||||
logger.Printf("Erreur lors de la détermination du préfixe : %v\n", err)
|
||||
logger.Printf("Error while determining the prefix: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Former le nom de la branche au format "prefixe/us-numero"
|
||||
// Form the branch name in the format "prefix/us-number"
|
||||
branchName := fmt.Sprintf("%s/us-%d", prefix, issueNumber)
|
||||
|
||||
logger.Printf("Nom de la branche défini : %s\n", branchName)
|
||||
logger.Printf("Branch name set to: %s\n", branchName)
|
||||
|
||||
// Configurer Git
|
||||
logger.Println("Configuration de Git...")
|
||||
// Configure Git
|
||||
logger.Println("Configuring Git...")
|
||||
err = runCommand(logger, "git", "config", "--global", "user.name", "gitea-actions")
|
||||
if err != nil {
|
||||
logger.Printf("Erreur lors de la configuration de Git : %v\n", err)
|
||||
logger.Printf("Error while configuring Git: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err = runCommand(logger, "git", "fetch", "origin")
|
||||
if err != nil {
|
||||
logger.Printf("Erreur lors de la mise a jour des references distantes")
|
||||
logger.Printf("Error while updating remote references")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err = runCommand(logger, "git", "config", "--global", "user.email", "actions@gitea.com")
|
||||
if err != nil {
|
||||
logger.Printf("Erreur lors de la configuration de Git : %v\n", err)
|
||||
logger.Printf("Error while configuring Git: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Vérifier si la branche existe déjà
|
||||
logger.Printf("Vérification de l'existence de la branche '%s'...\n", branchName)
|
||||
// Check if the branch already exists
|
||||
logger.Printf("Checking if branch '%s' exists...\n", branchName)
|
||||
output, err := exec.Command("git", "ls-remote", "--heads", "origin", branchName).CombinedOutput()
|
||||
if err != nil {
|
||||
logger.Printf("Erreur lors de la vérification de la branche : %v\nSortie : %s\n", err, string(output))
|
||||
logger.Printf("Error while checking the branch: %v\nOutput: %s\n", err, string(output))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
@ -94,63 +94,63 @@ func main() {
|
||||
}
|
||||
|
||||
if branchExists {
|
||||
logger.Printf("La branche '%s' existe déjà. Aucune action n'a été effectuée.\n", branchName)
|
||||
logger.Printf("Branch '%s' already exists. No action taken.\n", branchName)
|
||||
} else {
|
||||
// Créer et pousser la branche
|
||||
logger.Printf("Création de la branche '%s' à partir de 'dev'.\n", branchName)
|
||||
// Create and push the branch
|
||||
logger.Printf("Creating branch '%s' from 'develop'.\n", branchName)
|
||||
err = runCommand(logger, "git", "checkout", "-b", branchName, "origin/develop")
|
||||
if err != nil {
|
||||
logger.Printf("Erreur lors de la création de la branche : %v\n", err)
|
||||
logger.Printf("Error while creating the branch: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err = runCommand(logger, "git", "push", "origin", branchName)
|
||||
if err != nil {
|
||||
logger.Printf("Erreur lors du push de la branche : %v\n", err)
|
||||
logger.Printf("Error while pushing the branch: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logger.Printf("Branche '%s' créée et poussée avec succès.\n", branchName)
|
||||
logger.Printf("Branch '%s' successfully created and pushed.\n", branchName)
|
||||
}
|
||||
|
||||
// Attribuer la branche à l'issue via l'API Gitea
|
||||
logger.Printf("Attribution de la branche '%s' à l'issue #%d.\n", branchName, issueNumber)
|
||||
// Assign the branch to the issue via the Gitea API
|
||||
logger.Printf("Assigning branch '%s' to issue #%d.\n", branchName, issueNumber)
|
||||
|
||||
// Création du client Gitea
|
||||
// Create the Gitea client
|
||||
client, err := gitea.NewClient(giteaAPIURL, gitea.SetToken(giteaToken))
|
||||
if err != nil {
|
||||
logger.Printf("Erreur lors de la création du client Gitea : %v\n", err)
|
||||
logger.Printf("Error while creating the Gitea client: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Préparer les options pour éditer l'issue
|
||||
// Prepare options to edit the issue
|
||||
editIssueOption := gitea.EditIssueOption{
|
||||
Ref: &branchName,
|
||||
}
|
||||
|
||||
// Mettre à jour l'issue avec la référence de la branche
|
||||
// Update the issue with the branch reference
|
||||
_, _, err = client.EditIssue(repoOwner, repoName, issueNumber, editIssueOption)
|
||||
if err != nil {
|
||||
logger.Printf("Erreur lors de l'attribution de la branche à l'issue : %v\n", err)
|
||||
logger.Printf("Error while assigning the branch to the issue: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logger.Printf("Branche '%s' attribuée à l'issue #%d avec succès.\n", branchName, issueNumber)
|
||||
logger.Printf("Branch '%s' successfully assigned to issue #%d.\n", branchName, issueNumber)
|
||||
}
|
||||
|
||||
// Fonction pour mapper les labels aux préfixes
|
||||
// Function to map labels to prefixes
|
||||
func getPrefixFromLabels(labelsStr string) (string, error) {
|
||||
// Définir la correspondance label ➔ préfixe
|
||||
// Define the label ➔ prefix correspondence
|
||||
labelPrefixMap := map[string]string{
|
||||
"enhancement": "feature",
|
||||
"invalid": "bugfix",
|
||||
"bug": "hotfix",
|
||||
}
|
||||
|
||||
// Séparer les labels (supposant qu'ils sont séparés par des virgules)
|
||||
// Split labels (assuming they are comma-separated)
|
||||
labels := strings.Split(labelsStr, ",")
|
||||
|
||||
// Créer un mapping avec des clés en minuscules
|
||||
// Create a mapping with lower-case keys
|
||||
labelPrefixMapLower := make(map[string]string)
|
||||
for key, value := range labelPrefixMap {
|
||||
keyLower := strings.ToLower(key)
|
||||
@ -160,7 +160,7 @@ func getPrefixFromLabels(labelsStr string) (string, error) {
|
||||
for _, label := range labels {
|
||||
label = strings.TrimSpace(label)
|
||||
labelLower := strings.ToLower(label)
|
||||
fmt.Printf("Label actuel : %s", labelLower)
|
||||
fmt.Printf("Current label: %s", labelLower)
|
||||
if prefix, exists := labelPrefixMapLower[labelLower]; exists {
|
||||
return prefix, nil
|
||||
}
|
||||
@ -173,6 +173,6 @@ func runCommand(logger *log.Logger, name string, arg ...string) error {
|
||||
cmd := exec.Command(name, arg...)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
logger.Printf("Exécution de la commande : %s %s\n", name, strings.Join(arg, " "))
|
||||
logger.Printf("Executing command: %s %s\n", name, strings.Join(arg, " "))
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user