client := rest.NewClient(os.Getenv("SQUARECLOUD_API_KEY"))
defer client.Close()
api := rest.New(client)
Lister l’historique des deploys
api.GetApplicationDeployments(appID) renvoie [][]squarecloud.Deployment — une slice interne par deploy. Chaque événement d’un groupe partage le même ID (le SHA-1 du commit, 40 caractères hexadécimaux) et parcourt les états du cycle de vie : pending → clone → commit → restarting → success | error.
history, err := api.GetApplicationDeployments("abc123def456abc123def456")
if err != nil {
panic(err)
}
for _, timeline := range history {
last := timeline[len(timeline)-1]
fmt.Printf("Deploy %s ended as %s\n", last.ID, last.State)
for _, event := range timeline {
if event.State == "clone" {
fmt.Println(" cloned branch", event.Branch)
}
if event.State == "commit" {
fmt.Println(" files", event.Files.Added, event.Files.Removed, event.Files.Modified)
}
}
}
Branch n’est renseigné que sur l’événement "clone", et Files (Added, Removed, Modified) uniquement sur l’événement "commit".
Inspecter la configuration actuelle
api.GetApplicationCurrentDeployment(appID) renvoie un squarecloud.DeploymentCurrent avec la liaison GitHub App actuellement configurée.
current, err := api.GetApplicationCurrentDeployment("abc123def456abc123def456")
if err != nil {
panic(err)
}
if current.App == nil {
fmt.Println("no GitHub App linked")
} else {
fmt.Println("linked to", current.App.FullName)
}
Lier via la GitHub App Square Cloud (recommandé)
api.LinkApplicationGithubApp(appID, repoName, branch) lie un dépôt GitHub à l’application via la GitHub App officielle.
err := api.LinkApplicationGithubApp("abc123def456abc123def456", "octocat/hello-world", "main")
if err != nil {
panic(err)
}
Pour retirer la liaison :
err := api.UnlinkApplicationGithubApp("abc123def456abc123def456")
LinkApplicationGithubApp et UnlinkApplicationGithubApp nécessitent un token de session (JWT) comme identifiant — les simples clés d’API ne sont pas acceptées par ces endpoints. Passez-le avec rest.WithToken(sessionToken) ou construisez le client avec.
Lier via le flux webhook hérité
api.PostApplicationDeployWebhook(appID, accessToken) enregistre un GitHub Personal Access Token (ghp_* ou github_pat_*) et renvoie l’URL de webhook à configurer sur GitHub.
webhookURL, err := api.PostApplicationDeployWebhook("abc123def456abc123def456", "ghp_xxx...")
if err != nil {
panic(err)
}
fmt.Println("Configure GitHub to POST to:", webhookURL)
Passez le token "@" pour retirer le webhook configuré.
_, err := api.PostApplicationDeployWebhook("abc123def456abc123def456", "@")