Skip to content
Merged

1.8.5 #228

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
7 changes: 6 additions & 1 deletion .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: Codspeed Benchmarks
on:
push:
branches:
- main
paths:
- 'card_data/**'
pull_request:
types: [ opened, reopened, synchronize ]
paths:
Expand All @@ -26,7 +31,7 @@ jobs:
python-version: '3.12'

- name: Install uv
uses: astral-sh/setup-uv@v4
uses: astral-sh/setup-uv@v7

- name: Install dependencies
run: uv sync --dev
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/go_test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test
name: Golang Tests

on:
pull_request:
Expand All @@ -13,7 +13,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v6

- name: Set up Go
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.24
Expand Down
2 changes: 2 additions & 0 deletions card_data/pipelines/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from .defs.extract.tcgcsv.extract_pricing import build_dataframe
from .defs.load.tcgcsv.load_pricing import load_pricing_data, data_quality_checks_on_pricing
from .sensors import discord_success_sensor, discord_failure_sensor


@definitions
Expand All @@ -31,4 +32,5 @@ def defs() -> dg.Definitions:
assets=[build_dataframe, load_pricing_data, data_quality_checks_on_pricing],
jobs=[pricing_pipeline_job],
schedules=[price_schedule],
sensors=[discord_success_sensor, discord_failure_sensor]
)
40 changes: 40 additions & 0 deletions card_data/pipelines/sensors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import requests
from dagster import DagsterRunStatus, RunStatusSensorContext, run_status_sensor

from .utils.secret_retriever import fetch_n8n_webhook_secret


@run_status_sensor(run_status=DagsterRunStatus.SUCCESS, name="discord_success_sensor")
def discord_success_sensor(context: RunStatusSensorContext):
context.log.info(f"Detected successful run: {context.dagster_run.run_id}")
try:
response = requests.post(
fetch_n8n_webhook_secret(),
json={
"job_name": context.dagster_run.job_name,
"status": "SUCCESS",
"run_id": context.dagster_run.run_id,
},
timeout=10,
)
context.log.info(f"n8n response: {response.status_code}")
except Exception as e:
context.log.error(f"Failed to send notification: {e}")


@run_status_sensor(run_status=DagsterRunStatus.FAILURE, name="discord_failure_sensor")
def discord_failure_sensor(context: RunStatusSensorContext):
context.log.info(f"Detected failed run: {context.dagster_run.run_id}")
try:
response = requests.post(
fetch_n8n_webhook_secret(),
json={
"job_name": context.dagster_run.job_name,
"status": "FAILURE",
"run_id": context.dagster_run.run_id,
},
timeout=10,
)
context.log.info(f"n8n response: {response.status_code}")
except Exception as e:
context.log.error(f"Failed to send notification: {e}")
11 changes: 11 additions & 0 deletions card_data/pipelines/utils/secret_retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,14 @@ def fetch_secret() -> str:
secret_dict: SupabaseSecret = json.loads(secret)

return secret_dict["database_uri"]


def fetch_n8n_webhook_secret() -> str:
client = botocore.session.get_session().create_client("secretsmanager")
cache_config = SecretCacheConfig()
cache = SecretCache(config=cache_config, client=client)

secret = cast(str, cache.get_secret_string("n8n_webhook"))
secret_dict: dict[str, str] = json.loads(secret)

return secret_dict["n8n_webhook"]
2 changes: 1 addition & 1 deletion cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func runCLI(args []string) int {
fmt.Sprintf("\n\t%-15s %s", "search", "Search for a resource"),
fmt.Sprintf("\n\t%-15s %s", "speed", "Calculate the speed of a Pokémon in battle"),
fmt.Sprintf("\n\t%-15s %s", "types", "Get details about a typing"),
"\n\n", styling.StyleItalic.Render("hint: when calling a resource with a space, use a hyphen"),
"\n\n", styling.StyleItalic.Render(styling.HyphenHint),
"\n", styling.StyleItalic.Render("example: poke-cli ability strong-jaw"),
"\n", styling.StyleItalic.Render("example: poke-cli pokemon flutter-mane"),
"\n\n", fmt.Sprintf("%s %s", "↓ ctrl/cmd + click for docs/guides\n", styling.DocsLink),
Expand Down
13 changes: 5 additions & 8 deletions cmd/ability/ability.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"github.com/digitalghost-dev/poke-cli/connections"
"github.com/digitalghost-dev/poke-cli/flags"
"github.com/digitalghost-dev/poke-cli/styling"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

func AbilityCommand() (string, error) {
Expand All @@ -22,7 +20,7 @@ func AbilityCommand() (string, error) {
"Get details about a specific ability.\n\n",
styling.StyleBold.Render("USAGE:"),
fmt.Sprintf("\n\t%s %s %s %s", "poke-cli", styling.StyleBold.Render("ability"), "<ability-name>", "[flag]"),
fmt.Sprintf("\n\t%-30s", styling.StyleItalic.Render("Use a hyphen when typing a name with a space.")),
fmt.Sprintf("\n\t%-30s", styling.StyleItalic.Render(styling.HyphenHint)),
"\n\n",
styling.StyleBold.Render("FLAGS:"),
fmt.Sprintf("\n\t%-30s %s", "-p, --pokemon", "Prints Pokémon that learn this ability."),
Expand All @@ -35,13 +33,12 @@ func AbilityCommand() (string, error) {

args := os.Args

flag.Parse()

if len(os.Args) == 3 && (os.Args[2] == "-h" || os.Args[2] == "--help") {
flag.Usage()
if utils.CheckHelpFlag(&output, flag.Usage) {
return output.String(), nil
}

flag.Parse()

if err := utils.ValidateAbilityArgs(args); err != nil {
output.WriteString(err.Error())
return output.String(), err
Expand Down Expand Up @@ -81,7 +78,7 @@ func AbilityCommand() (string, error) {
}
}

capitalizedAbility := cases.Title(language.English).String(strings.ReplaceAll(abilityName, "-", " "))
capitalizedAbility := styling.CapitalizeResourceName(abilityName)
output.WriteString(styling.StyleBold.Render(capitalizedAbility) + "\n")

generationParts := strings.Split(abilitiesStruct.Generation.Name, "-")
Expand Down
5 changes: 5 additions & 0 deletions cmd/ability/ability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ func TestAbilityCommand(t *testing.T) {
args: []string{"ability", "clear-body"},
expectedOutput: utils.LoadGolden(t, "ability.golden"),
},
{
name: "Ability command: beads-of-ruin",
args: []string{"ability", "beads-of-ruin"},
expectedOutput: utils.LoadGolden(t, "ability-ii.golden"),
},
{
name: "Misspelled ability name",
args: []string{"ability", "bulletproff"},
Expand Down
8 changes: 3 additions & 5 deletions cmd/berry/berry.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ func BerryCommand() (string, error) {
output.WriteString(helpMessage)
}

flag.Parse()

// Handle help flag
if len(os.Args) == 3 && (os.Args[2] == "-h" || os.Args[2] == "--help") {
flag.Usage()
if utils.CheckHelpFlag(&output, flag.Usage) {
return output.String(), nil
}

flag.Parse()

// Validate arguments
if err := utils.ValidateBerryArgs(os.Args); err != nil {
output.WriteString(err.Error())
Expand Down
8 changes: 3 additions & 5 deletions cmd/card/card.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ func CardCommand() (string, error) {
output.WriteString(helpMessage)
}

flag.Parse()

// Handle help flag
if len(os.Args) == 3 && (os.Args[2] == "-h" || os.Args[2] == "--help") {
flag.Usage()
if utils.CheckHelpFlag(&output, flag.Usage) {
return output.String(), nil
}

flag.Parse()

// Validate arguments
if err := utils.ValidateCardArgs(os.Args); err != nil {
output.WriteString(err.Error())
Expand Down
17 changes: 7 additions & 10 deletions cmd/item/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"github.com/digitalghost-dev/poke-cli/connections"
"github.com/digitalghost-dev/poke-cli/structs"
"github.com/digitalghost-dev/poke-cli/styling"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

func ItemCommand() (string, error) {
Expand All @@ -22,8 +20,8 @@ func ItemCommand() (string, error) {
helpMessage := styling.HelpBorder.Render(
"Get details about a specific item.\n\n",
styling.StyleBold.Render("USAGE:"),
fmt.Sprintf("\n\t%s %s %s %s", "poke-cli", styling.StyleBold.Render("item"), "<item-name>", "[flag]"),
fmt.Sprintf("\n\t%-30s", styling.StyleItalic.Render("Use a hyphen when typing a name with a space.")),
fmt.Sprintf("\n\t%s %s %s", "poke-cli", styling.StyleBold.Render("item"), "<item-name>"),
fmt.Sprintf("\n\t%-30s", styling.StyleItalic.Render(styling.HyphenHint)),
"\n\n",
styling.StyleBold.Render("FLAGS:"),
fmt.Sprintf("\n\t%-30s %s", "-h, --help", "Prints the help menu."),
Expand All @@ -33,13 +31,12 @@ func ItemCommand() (string, error) {

args := os.Args

flag.Parse()

if len(os.Args) == 3 && (os.Args[2] == "-h" || os.Args[2] == "--help") {
flag.Usage()
if utils.CheckHelpFlag(&output, flag.Usage) {
return output.String(), nil
}

flag.Parse()

if err := utils.ValidateItemArgs(os.Args); err != nil {
output.WriteString(err.Error())
return output.String(), err
Expand All @@ -60,9 +57,9 @@ func ItemCommand() (string, error) {
}

func itemInfoContainer(output *strings.Builder, itemStruct structs.ItemJSONStruct, itemName string) {
capitalizedItem := styling.StyleBold.Render(cases.Title(language.English).String(strings.ReplaceAll(itemName, "-", " ")))
capitalizedItem := styling.StyleBold.Render(styling.CapitalizeResourceName(itemName))
itemCost := fmt.Sprintf("Cost: %d", itemStruct.Cost)
itemCategory := "Category: " + cases.Title(language.English).String(strings.ReplaceAll(itemStruct.Category.Name, "-", " "))
itemCategory := "Category: " + styling.CapitalizeResourceName(itemStruct.Category.Name)

docStyle := lipgloss.NewStyle().
Padding(1, 2).
Expand Down
21 changes: 12 additions & 9 deletions cmd/move/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ package move
import (
"flag"
"fmt"
"os"
"strconv"
"strings"

"github.com/charmbracelet/lipgloss"
"github.com/digitalghost-dev/poke-cli/cmd/utils"
"github.com/digitalghost-dev/poke-cli/connections"
"github.com/digitalghost-dev/poke-cli/structs"
"github.com/digitalghost-dev/poke-cli/styling"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"os"
"strconv"
"strings"
)

func MoveCommand() (string, error) {
Expand All @@ -23,18 +24,20 @@ func MoveCommand() (string, error) {
"Get details about a specific move.\n\n",
styling.StyleBold.Render("USAGE:"),
"\n\t"+"poke-cli"+" "+styling.StyleBold.Render("move")+" <move-name>",
"\n\n"+styling.StyleItalic.Render("Use a hyphen when typing a name with a space."),
fmt.Sprintf("\n\t%-30s", styling.StyleItalic.Render(styling.HyphenHint)),
"\n\n",
styling.StyleBold.Render("FLAGS:"),
fmt.Sprintf("\n\t%-30s %s", "-h, --help", "Prints the help menu."),
)
output.WriteString(helpMessage)
}

flag.Parse()

if len(os.Args) == 3 && (os.Args[2] == "-h" || os.Args[2] == "--help") {
flag.Usage()
if utils.CheckHelpFlag(&output, flag.Usage) {
return output.String(), nil
}

flag.Parse()

if err := utils.ValidateMoveArgs(os.Args); err != nil {
output.WriteString(err.Error())
return output.String(), err
Expand All @@ -57,7 +60,7 @@ func MoveCommand() (string, error) {
}

func moveInfoContainer(output *strings.Builder, moveStruct structs.MoveJSONStruct, moveName string) {
capitalizedMove := cases.Title(language.English).String(strings.ReplaceAll(moveName, "-", " "))
capitalizedMove := styling.CapitalizeResourceName(moveName)

docStyle := lipgloss.NewStyle().
Padding(1, 2).
Expand Down
12 changes: 6 additions & 6 deletions cmd/natures/natures.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package natures
import (
"flag"
"fmt"
"os"
"strings"

"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/lipgloss/table"
"github.com/digitalghost-dev/poke-cli/cmd/utils"
"github.com/digitalghost-dev/poke-cli/styling"
"os"
"strings"
)

func NaturesCommand() (string, error) {
Expand All @@ -23,13 +24,12 @@ func NaturesCommand() (string, error) {
output.WriteString(helpMessage)
}

flag.Parse()

if len(os.Args) == 3 && (os.Args[2] == "-h" || os.Args[2] == "--help") {
flag.Usage()
if utils.CheckHelpFlag(&output, flag.Usage) {
return output.String(), nil
}

flag.Parse()

if err := utils.ValidateNaturesArgs(os.Args); err != nil {
output.WriteString(err.Error())
return output.String(), err
Expand Down
13 changes: 6 additions & 7 deletions cmd/pokemon/pokemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func PokemonCommand() (string, error) {
"Get details about a specific Pokémon.\n\n",
styling.StyleBold.Render("USAGE:"),
fmt.Sprintf("\n\t%s %s %s %s", "poke-cli", styling.StyleBold.Render("pokemon"), "<pokemon-name>", "[flag]"),
fmt.Sprintf("\n\t%-30s", styling.StyleItalic.Render("Use a hyphen when typing a name with a space.")),
fmt.Sprintf("\n\t%-30s", styling.StyleItalic.Render(styling.HyphenHint)),
"\n\n",
styling.StyleBold.Render("FLAGS:"),
fmt.Sprintf("\n\t%-30s %s", "-a, --abilities", "Prints the Pokémon's abilities."),
Expand All @@ -49,13 +49,12 @@ func PokemonCommand() (string, error) {

args := os.Args

flag.Parse()

if len(os.Args) == 3 && (os.Args[2] == "-h" || os.Args[2] == "--help") {
flag.Usage()
if utils.CheckHelpFlag(&output, flag.Usage) {
return output.String(), nil
}

flag.Parse()

err := utils.ValidatePokemonArgs(args)
if err != nil {
output.WriteString(err.Error()) // This is the styled error
Expand Down Expand Up @@ -83,7 +82,7 @@ func PokemonCommand() (string, error) {
return output.String(), err
}

capitalizedString := cases.Title(language.English).String(strings.ReplaceAll(pokemonName, "-", " "))
capitalizedString := styling.CapitalizeResourceName(pokemonName)

entry := func(w io.Writer) {
for _, entry := range pokemonSpeciesStruct.FlavorTextEntries {
Expand Down Expand Up @@ -173,7 +172,7 @@ func PokemonCommand() (string, error) {
if pokemonSpeciesStruct.EvolvesFromSpecies.Name != "" {
evolvesFrom := pokemonSpeciesStruct.EvolvesFromSpecies.Name

capitalizedPokemonName := cases.Title(language.English).String(strings.ReplaceAll(evolvesFrom, "-", " "))
capitalizedPokemonName := styling.CapitalizeResourceName(evolvesFrom)
fmt.Fprintf(w, "%s %s %s", styling.ColoredBullet, "Evolves from:", capitalizedPokemonName)
} else {
fmt.Fprintf(w, "%s %s", styling.ColoredBullet, "Basic Pokémon")
Expand Down
Loading