From 8af94084c55f27a7e54f8f0ffdf159acdb40d5fc Mon Sep 17 00:00:00 2001 From: Jeremy Colin Date: Fri, 26 Dec 2025 20:52:51 +0100 Subject: [PATCH 1/4] feat: add deployments freeze and unfreeze --- internal/watchlyapi/deployment.go | 46 +++++++++++++++++++++++++++ main.go | 52 +++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) diff --git a/internal/watchlyapi/deployment.go b/internal/watchlyapi/deployment.go index 689e3d1..51ea0a4 100644 --- a/internal/watchlyapi/deployment.go +++ b/internal/watchlyapi/deployment.go @@ -101,3 +101,49 @@ func FinishDeployment(apiKey, githubSha, status, completedAt string) error { return nil } + +type ProjectSettingsUpdateBody struct { + DeploymentFreeze *bool `json:"deployment_freeze,omitempty"` +} + +type ProjectSettingsUpdateResponse struct { + Message string `json:"message"` +} + +func UpdateProjectSettings(apiKey string, deploymentFreeze bool) error { + deploymentFreezePtr := &deploymentFreeze + body := ProjectSettingsUpdateBody{ + DeploymentFreeze: deploymentFreezePtr, + } + + marshalledBody, err := json.Marshal(body) + if err != nil { + return err + } + + req, err := http.NewRequest("PUT", WATCHLY_ENDPOINT+"/webhooks/projects", bytes.NewBuffer(marshalledBody)) + if err != nil { + return err + } + + req.Header.Set("Content-Type", "application/json") + req.Header.Set("Authorization", "Bearer "+apiKey) + + client := NewHttpClient() + resp, err := client.Do(req) + if err != nil { + return err + } + defer resp.Body.Close() + + if resp.StatusCode >= 400 { + return fmt.Errorf("failed to update project settings: %s", resp.Status) + } + + var response ProjectSettingsUpdateResponse + if err := json.NewDecoder(resp.Body).Decode(&response); err != nil { + return err + } + + return nil +} diff --git a/main.go b/main.go index fe03880..1435314 100644 --- a/main.go +++ b/main.go @@ -125,6 +125,58 @@ func main() { fmt.Println("watchly-cli - ✅ Finished deployment") + return nil + }, + }, + { + Name: "freeze", + Usage: "Freeze deployments for this project", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "api-key", + Aliases: []string{"k"}, + Usage: "Watchly API key for your project", + Sources: cli.EnvVars("WATCHLY_API_KEY"), + Required: true, + }, + }, + Action: func(ctx context.Context, cmd *cli.Command) error { + apiKey := cmd.String("api-key") + + fmt.Println("watchly-cli - ❄️ Freezing deployments...") + + if err := watchlyapi.UpdateProjectSettings(apiKey, true); err != nil { + return fmt.Errorf("failed to freeze deployments: %w", err) + } + + fmt.Println("watchly-cli - ✅ Deployments frozen") + + return nil + }, + }, + { + Name: "unfreeze", + Usage: "Unfreeze deployments for this project", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "api-key", + Aliases: []string{"k"}, + Usage: "Watchly API key for your project", + Sources: cli.EnvVars("WATCHLY_API_KEY"), + Required: true, + }, + }, + Action: func(ctx context.Context, cmd *cli.Command) error { + apiKey := cmd.String("api-key") + + fmt.Println("watchly-cli - 🔥Unfreezing deployments...") + + if err := watchlyapi.UpdateProjectSettings(apiKey, false); err != nil { + return fmt.Errorf("failed to unfreeze deployments: %w", err) + } + + fmt.Println("watchly-cli - ✅ Deployments unfrozen") + return nil }, }, From 3bbe6d42a2c940e838ad2091c6a580d64a5a35ab Mon Sep 17 00:00:00 2001 From: Jeremy Colin Date: Fri, 26 Dec 2025 20:54:47 +0100 Subject: [PATCH 2/4] feat: move freeze and unfreeze to deployments --- main.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/main.go b/main.go index 1435314..14f6084 100644 --- a/main.go +++ b/main.go @@ -128,6 +128,12 @@ func main() { return nil }, }, + }, + }, + { + Name: "deployments", + Usage: "Manage deployment settings", + Commands: []*cli.Command{ { Name: "freeze", Usage: "Freeze deployments for this project", From ef783f87d4e5963d4fde5ac44d9160da2f784263 Mon Sep 17 00:00:00 2001 From: Jeremy Colin Date: Fri, 26 Dec 2025 21:03:47 +0100 Subject: [PATCH 3/4] feat: check deployments enabled --- internal/watchlyapi/deployment.go | 31 +++++++++++++++++++++++++++++++ main.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/internal/watchlyapi/deployment.go b/internal/watchlyapi/deployment.go index 51ea0a4..691c835 100644 --- a/internal/watchlyapi/deployment.go +++ b/internal/watchlyapi/deployment.go @@ -147,3 +147,34 @@ func UpdateProjectSettings(apiKey string, deploymentFreeze bool) error { return nil } + +type ProjectEnabledResponse struct { + Enabled bool `json:"enabled"` +} + +func GetProjectEnabled(apiKey string) (bool, error) { + req, err := http.NewRequest("GET", WATCHLY_ENDPOINT+"/webhooks/projects/enabled", nil) + if err != nil { + return false, err + } + + req.Header.Set("Authorization", "Bearer "+apiKey) + + client := NewHttpClient() + resp, err := client.Do(req) + if err != nil { + return false, err + } + defer resp.Body.Close() + + if resp.StatusCode >= 400 { + return false, fmt.Errorf("failed to get project enabled status: %s", resp.Status) + } + + var response ProjectEnabledResponse + if err := json.NewDecoder(resp.Body).Decode(&response); err != nil { + return false, err + } + + return response.Enabled, nil +} diff --git a/main.go b/main.go index 14f6084..ed892b9 100644 --- a/main.go +++ b/main.go @@ -183,6 +183,35 @@ func main() { fmt.Println("watchly-cli - ✅ Deployments unfrozen") + return nil + }, + }, + { + Name: "enabled", + Usage: "Check if deployments are enabled for this project", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "api-key", + Aliases: []string{"k"}, + Usage: "Watchly API key for your project", + Sources: cli.EnvVars("WATCHLY_API_KEY"), + Required: true, + }, + }, + Action: func(ctx context.Context, cmd *cli.Command) error { + apiKey := cmd.String("api-key") + + enabled, err := watchlyapi.GetProjectEnabled(apiKey) + if err != nil { + return fmt.Errorf("failed to get project enabled status: %w", err) + } + + if enabled { + fmt.Println("watchly-cli - ✅ Deployments are enabled") + } else { + fmt.Println("watchly-cli - ❌ Deployments are disabled") + } + return nil }, }, From 0edb9c005983704701ff3b90fbb2871aaf684296 Mon Sep 17 00:00:00 2001 From: Jeremy Colin Date: Sat, 27 Dec 2025 18:09:08 +0100 Subject: [PATCH 4/4] feat: change deployments to repository --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index ed892b9..82775c0 100644 --- a/main.go +++ b/main.go @@ -131,8 +131,8 @@ func main() { }, }, { - Name: "deployments", - Usage: "Manage deployment settings", + Name: "repository", + Usage: "Manage repository settings", Commands: []*cli.Command{ { Name: "freeze",