Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Release

on:
push:
branches:
- main

jobs:
build:
name: Build for release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.22"
- name: Test
run: go test -v ./...
- name: Build
run: go build -v ./...
29 changes: 29 additions & 0 deletions .github/workflows/publish-github.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Publish

on:
release:
types: [created]

jobs:
goreleaser:
name: Publish with GoReleaser
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.22"
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
version: "~> v2"
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GORELEASER_TOKEN: ${{ secrets.GORELEASER_TOKEN }}
22 changes: 22 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Pull Request

on:
pull_request:
branches:
- main

jobs:
build:
name: Build and Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.22"
- name: Test
run: go test -v ./...
- name: Build
run: go build -v ./...
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/
*.exe
44 changes: 44 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
version: 2

builds:
- binary: apialerts
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
- windows
goarch:
- amd64
- arm64

archives:
- name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
formats:
- tar.gz
formats_overrides:
- goos: windows
formats:
- zip

checksum:
name_template: "checksums.txt"

homebrew_casks:
- repository:
owner: apialerts
name: homebrew-tap
token: "{{ .Env.GORELEASER_TOKEN }}"
homepage: "https://apialerts.com"
description: "API Alerts CLI — send events from your terminal"

scoops:
- repository:
owner: apialerts
name: scoop-bucket
token: "{{ .Env.GORELEASER_TOKEN }}"
homepage: "https://apialerts.com"
description: "API Alerts CLI — send events from your terminal"

changelog:
sort: asc
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 apialerts

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
111 changes: 110 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,110 @@
# apialerts-cli
# API Alerts • CLI

[GitHub Repo](https://github.com/apialerts/apialerts-cli)

A command-line interface for [apialerts.com](https://apialerts.com). Send events from your terminal, scripts, and CI/CD pipelines.

## Installation

### Homebrew (macOS / Linux)

```bash
brew tap apialerts/tap
brew install apialerts
```

### Scoop (Windows)

```bash
scoop bucket add apialerts https://github.com/apialerts/scoop-bucket
scoop install apialerts
```

### Go Install

```bash
go install github.com/apialerts/apialerts-cli@latest
```

### Download Binary

Download the latest binary from the [Releases](https://github.com/apialerts/apialerts-cli/releases) page.

## Setup

Configure your API key once. The key is stored in `~/.apialerts/config.json`.

```bash
apialerts config --key your_api_key
```

Verify your configuration

```bash
apialerts config
```

## Send Events

Send an event with a message

```bash
apialerts send -m "Deploy completed"
```

Send an event with a name and title

```bash
apialerts send -e user.purchase -t "New Sale" -m "$49.99 from john@example.com" -c payments
```

### Optional Properties

You can optionally specify an event name, title, channel, tags, and a link.

```bash
apialerts send -m "Payment failed" -c payments -g billing,error -l https://dashboard.example.com
```

| Flag | Short | Description |
|------|-------|-------------|
| `--message` | `-m` | Event message (required) |
| `--event` | `-e` | Event name for routing (optional, e.g. `user.purchase`) |
| `--title` | `-t` | Event title (optional) |
| `--channel` | `-c` | Target channel (optional, uses default channel if not set) |
| `--tags` | `-g` | Comma-separated tags (optional) |
| `--link` | `-l` | Associated URL (optional) |
| `--key` | | API key override (optional, uses stored config if not set) |

### Override API Key

You can override the stored API key for a single request.

```bash
apialerts send -m "Hello World" --key other_api_key
```

## Test Connectivity

Send a test event to verify your API key and connection.

```bash
apialerts test
```

## CI/CD Examples

### GitHub Actions

```yaml
- name: Send deploy alert
run: |
apialerts send -m "Deployed ${{ github.sha }}" -c deployments -g ci,deploy --key ${{ secrets.APIALERTS_API_KEY }}
```

### Shell Script

```bash
#!/bin/bash
apialerts send -m "Backup completed" -c ops -g backup,cron
```
7 changes: 7 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Release Process

1. Update the version in `cmd/constants.go`
2. PR to `main` branch and merge if tests pass
3. Ensure GitHub Actions tests pass on `main` before creating a release
4. Create a new release on GitHub on the `main` branch with a `v` prefixed tag (e.g. `v0.1.0`)
5. GoReleaser will automatically build cross-platform binaries and attach them to the release
45 changes: 45 additions & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package cmd

import (
"fmt"

"github.com/apialerts/apialerts-cli/internal/config"
"github.com/spf13/cobra"
)

var configKey string

var configCmd = &cobra.Command{
Use: "config",
Short: "Configure the CLI",
Long: "Set your API key for authentication. The key is stored in ~/.apialerts/config.json.",
RunE: func(cmd *cobra.Command, args []string) error {
if configKey == "" {
// Show current config
cfg, err := config.Load()
if err != nil {
return fmt.Errorf("failed to load config: %w", err)
}
if cfg.APIKey == "" {
fmt.Println("No API key configured.")
fmt.Println("Run: apialerts config --key <your-api-key>")
} else {
masked := cfg.APIKey[:6] + "..." + cfg.APIKey[len(cfg.APIKey)-4:]
fmt.Printf("API Key: %s\n", masked)
}
return nil
}

cfg := &config.CLIConfig{APIKey: configKey}
if err := config.Save(cfg); err != nil {
return fmt.Errorf("failed to save config: %w", err)
}
fmt.Println("API key saved.")
return nil
},
}

func init() {
configCmd.Flags().StringVar(&configKey, "key", "", "Your API Alerts API key")
rootCmd.AddCommand(configCmd)
}
6 changes: 6 additions & 0 deletions cmd/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package cmd

const (
IntegrationName = "cli"
Version = "0.0.1"
)
22 changes: 22 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
)

var rootCmd = &cobra.Command{
Use: "apialerts",
Short: "API Alerts CLI — send events from your terminal",
Long: "A command-line interface for apialerts.com. Configure your API key, send events, and test connectivity.",
Version: Version,
}

func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
Loading
Loading