Skip to content

Commit 7e9576d

Browse files
Merge pull request #228 from digitalghost-dev/1.8.5
1.8.5
2 parents 1192d4a + bd889d3 commit 7e9576d

File tree

27 files changed

+294
-105
lines changed

27 files changed

+294
-105
lines changed

.github/workflows/codspeed.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
name: Codspeed Benchmarks
22
on:
3+
push:
4+
branches:
5+
- main
6+
paths:
7+
- 'card_data/**'
38
pull_request:
49
types: [ opened, reopened, synchronize ]
510
paths:
@@ -26,7 +31,7 @@ jobs:
2631
python-version: '3.12'
2732

2833
- name: Install uv
29-
uses: astral-sh/setup-uv@v4
34+
uses: astral-sh/setup-uv@v7
3035

3136
- name: Install dependencies
3237
run: uv sync --dev

.github/workflows/go_test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Test
1+
name: Golang Tests
22

33
on:
44
pull_request:
@@ -13,7 +13,7 @@ jobs:
1313
- name: Checkout
1414
uses: actions/checkout@v6
1515

16-
- name: Set up Go
16+
- name: Setup Go
1717
uses: actions/setup-go@v5
1818
with:
1919
go-version: 1.24

card_data/pipelines/definitions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from .defs.extract.tcgcsv.extract_pricing import build_dataframe
88
from .defs.load.tcgcsv.load_pricing import load_pricing_data, data_quality_checks_on_pricing
9+
from .sensors import discord_success_sensor, discord_failure_sensor
910

1011

1112
@definitions
@@ -31,4 +32,5 @@ def defs() -> dg.Definitions:
3132
assets=[build_dataframe, load_pricing_data, data_quality_checks_on_pricing],
3233
jobs=[pricing_pipeline_job],
3334
schedules=[price_schedule],
35+
sensors=[discord_success_sensor, discord_failure_sensor]
3436
)

card_data/pipelines/sensors.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import requests
2+
from dagster import DagsterRunStatus, RunStatusSensorContext, run_status_sensor
3+
4+
from .utils.secret_retriever import fetch_n8n_webhook_secret
5+
6+
7+
@run_status_sensor(run_status=DagsterRunStatus.SUCCESS, name="discord_success_sensor")
8+
def discord_success_sensor(context: RunStatusSensorContext):
9+
context.log.info(f"Detected successful run: {context.dagster_run.run_id}")
10+
try:
11+
response = requests.post(
12+
fetch_n8n_webhook_secret(),
13+
json={
14+
"job_name": context.dagster_run.job_name,
15+
"status": "SUCCESS",
16+
"run_id": context.dagster_run.run_id,
17+
},
18+
timeout=10,
19+
)
20+
context.log.info(f"n8n response: {response.status_code}")
21+
except Exception as e:
22+
context.log.error(f"Failed to send notification: {e}")
23+
24+
25+
@run_status_sensor(run_status=DagsterRunStatus.FAILURE, name="discord_failure_sensor")
26+
def discord_failure_sensor(context: RunStatusSensorContext):
27+
context.log.info(f"Detected failed run: {context.dagster_run.run_id}")
28+
try:
29+
response = requests.post(
30+
fetch_n8n_webhook_secret(),
31+
json={
32+
"job_name": context.dagster_run.job_name,
33+
"status": "FAILURE",
34+
"run_id": context.dagster_run.run_id,
35+
},
36+
timeout=10,
37+
)
38+
context.log.info(f"n8n response: {response.status_code}")
39+
except Exception as e:
40+
context.log.error(f"Failed to send notification: {e}")

card_data/pipelines/utils/secret_retriever.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,14 @@ def fetch_secret() -> str:
2121
secret_dict: SupabaseSecret = json.loads(secret)
2222

2323
return secret_dict["database_uri"]
24+
25+
26+
def fetch_n8n_webhook_secret() -> str:
27+
client = botocore.session.get_session().create_client("secretsmanager")
28+
cache_config = SecretCacheConfig()
29+
cache = SecretCache(config=cache_config, client=client)
30+
31+
secret = cast(str, cache.get_secret_string("n8n_webhook"))
32+
secret_dict: dict[str, str] = json.loads(secret)
33+
34+
return secret_dict["n8n_webhook"]

cli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func runCLI(args []string) int {
8080
fmt.Sprintf("\n\t%-15s %s", "search", "Search for a resource"),
8181
fmt.Sprintf("\n\t%-15s %s", "speed", "Calculate the speed of a Pokémon in battle"),
8282
fmt.Sprintf("\n\t%-15s %s", "types", "Get details about a typing"),
83-
"\n\n", styling.StyleItalic.Render("hint: when calling a resource with a space, use a hyphen"),
83+
"\n\n", styling.StyleItalic.Render(styling.HyphenHint),
8484
"\n", styling.StyleItalic.Render("example: poke-cli ability strong-jaw"),
8585
"\n", styling.StyleItalic.Render("example: poke-cli pokemon flutter-mane"),
8686
"\n\n", fmt.Sprintf("%s %s", "↓ ctrl/cmd + click for docs/guides\n", styling.DocsLink),

cmd/ability/ability.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
"github.com/digitalghost-dev/poke-cli/connections"
1111
"github.com/digitalghost-dev/poke-cli/flags"
1212
"github.com/digitalghost-dev/poke-cli/styling"
13-
"golang.org/x/text/cases"
14-
"golang.org/x/text/language"
1513
)
1614

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

3634
args := os.Args
3735

38-
flag.Parse()
39-
40-
if len(os.Args) == 3 && (os.Args[2] == "-h" || os.Args[2] == "--help") {
41-
flag.Usage()
36+
if utils.CheckHelpFlag(&output, flag.Usage) {
4237
return output.String(), nil
4338
}
4439

40+
flag.Parse()
41+
4542
if err := utils.ValidateAbilityArgs(args); err != nil {
4643
output.WriteString(err.Error())
4744
return output.String(), err
@@ -81,7 +78,7 @@ func AbilityCommand() (string, error) {
8178
}
8279
}
8380

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

8784
generationParts := strings.Split(abilitiesStruct.Generation.Name, "-")

cmd/ability/ability_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ func TestAbilityCommand(t *testing.T) {
3131
args: []string{"ability", "clear-body"},
3232
expectedOutput: utils.LoadGolden(t, "ability.golden"),
3333
},
34+
{
35+
name: "Ability command: beads-of-ruin",
36+
args: []string{"ability", "beads-of-ruin"},
37+
expectedOutput: utils.LoadGolden(t, "ability-ii.golden"),
38+
},
3439
{
3540
name: "Misspelled ability name",
3641
args: []string{"ability", "bulletproff"},

cmd/berry/berry.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,12 @@ func BerryCommand() (string, error) {
3030
output.WriteString(helpMessage)
3131
}
3232

33-
flag.Parse()
34-
35-
// Handle help flag
36-
if len(os.Args) == 3 && (os.Args[2] == "-h" || os.Args[2] == "--help") {
37-
flag.Usage()
33+
if utils.CheckHelpFlag(&output, flag.Usage) {
3834
return output.String(), nil
3935
}
4036

37+
flag.Parse()
38+
4139
// Validate arguments
4240
if err := utils.ValidateBerryArgs(os.Args); err != nil {
4341
output.WriteString(err.Error())

cmd/card/card.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@ func CardCommand() (string, error) {
2626
output.WriteString(helpMessage)
2727
}
2828

29-
flag.Parse()
30-
31-
// Handle help flag
32-
if len(os.Args) == 3 && (os.Args[2] == "-h" || os.Args[2] == "--help") {
33-
flag.Usage()
29+
if utils.CheckHelpFlag(&output, flag.Usage) {
3430
return output.String(), nil
3531
}
3632

33+
flag.Parse()
34+
3735
// Validate arguments
3836
if err := utils.ValidateCardArgs(os.Args); err != nil {
3937
output.WriteString(err.Error())

0 commit comments

Comments
 (0)