Skip to content

Commit 80f19c4

Browse files
Merge pull request #126 from sailpoint-oss/cursor-command
Cursor command
2 parents 6297be5 + 7d50d52 commit 80f19c4

3 files changed

Lines changed: 139 additions & 0 deletions

File tree

.cursor/commands/build-sdk.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Build SDK and Run Validation Tests
2+
3+
## Overview
4+
5+
Build all API versions of the Python SDK from the OpenAPI specs and run the validation test suite. Use the same behavior as the GitHub action with default inputs: `api-specs-path=api-specs`, `skip-tests=false`.
6+
7+
Works on Windows, macOS, and Linux (no shell required).
8+
9+
## What to do
10+
11+
1. Run the build-and-validate script from the repository root:
12+
- **Command:** `python scripts/build_and_validate_sdk.py`
13+
- Run from the workspace root directory.
14+
2. Use default options (do not set `API_SPECS_PATH` or `SKIP_TESTS` unless the user asks otherwise).
15+
3. Report the outcome: whether the build and validation tests completed successfully or any errors that occurred.
16+
17+
If the user provides extra instructions after the command (e.g. "skip tests" or a different api-specs path), follow those:
18+
19+
- To skip tests: set env and run, e.g. `SKIP_TESTS=true python scripts/build_and_validate_sdk.py` (Unix/macOS) or `set SKIP_TESTS=true && python scripts/build_and_validate_sdk.py` (Windows cmd) or `$env:SKIP_TESTS="true"; python scripts/build_and_validate_sdk.py` (Windows PowerShell).
20+
- Different api-specs path: `API_SPECS_PATH=<path> python scripts/build_and_validate_sdk.py` (Unix/macOS) or set `API_SPECS_PATH` then run the Python command (Windows).

.cursor/commands/create-pr.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Create Pull Request
2+
3+
## Overview
4+
5+
Create a pull request using the GitHub CLI (`gh`). The PR uses the **current branch** as the head and **main** as the base. The PR title is whatever the user types after the slash command.
6+
7+
## What to do
8+
9+
1. **Title:** Use the text the user provided after the command as the PR title (e.g. `/create-pr Add streaming pagination` → title is "Add streaming pagination"). If the user did not provide any text after the command, ask them for a PR title.
10+
2. **Push if needed:** From the repository root, if the current branch does not have an upstream on origin yet, push it first so `gh pr create` can open a PR:
11+
- Check: `git rev-parse --abbrev-ref @{u} 2>/dev/null` or equivalent (e.g. if `git status` says "no upstream branch").
12+
- If the branch is not yet pushed: run `git push -u origin $(git branch --show-current)`.
13+
- If the push fails (e.g. uncommitted changes, auth), report the error and stop; otherwise continue.
14+
3. **Create the PR:** From the repository root, run:
15+
- **Command:** `gh pr create --base main --title "<title>" --body "<body>"`
16+
- Replace `<title>` with the title from step 1. For `<body>`, use a short description (e.g. same as title or "See commits for details"). Quote both so special characters or spaces are handled correctly. (Non-interactive `gh` requires `--body`.)
17+
4. Report the outcome: the PR URL if successful, or any error from `git push` or `gh` (e.g. not logged in, uncommitted changes, conflicts).
18+
19+
## Notes
20+
21+
- Ensure you are in the workspace (repo) root when running `git` and `gh`.
22+
- The current branch is used automatically as the head by `gh pr create`.
23+
- If the user asks for a custom body/description, use that for `--body "..."` instead of the default.

scripts/build_and_validate_sdk.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Build the Python SDK and run validation tests.
4+
Cross-platform (Windows, macOS, Linux).
5+
6+
Prerequisites: Node.js, Python 3.x, Java 17+ on PATH.
7+
Optional env: API_SPECS_PATH (default api-specs), SKIP_TESTS (default false).
8+
9+
Usage (from repo root):
10+
python scripts/build_and_validate_sdk.py
11+
SKIP_TESTS=true python scripts/build_and_validate_sdk.py
12+
API_SPECS_PATH=other-specs python scripts/build_and_validate_sdk.py
13+
"""
14+
15+
import os
16+
import shutil
17+
import subprocess
18+
import sys
19+
import urllib.request
20+
21+
22+
def repo_root():
23+
return os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
24+
25+
26+
def main():
27+
root = repo_root()
28+
os.chdir(root)
29+
30+
api_specs_path = os.environ.get("API_SPECS_PATH", "api-specs")
31+
skip_tests = os.environ.get("SKIP_TESTS", "false").lower() in ("1", "true", "yes")
32+
33+
print(f"Building SDK (api-specs-path={api_specs_path}, skip-tests={skip_tests})")
34+
35+
# Download OpenAPI Generator if not present
36+
jar_path = os.path.join(root, "openapi-generator-cli.jar")
37+
if not os.path.isfile(jar_path):
38+
print("Downloading OpenAPI Generator...")
39+
url = "https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.12.0/openapi-generator-cli-7.12.0.jar"
40+
urllib.request.urlretrieve(url, jar_path)
41+
42+
# Prescript
43+
print("Running prescript...")
44+
idn_path = os.path.join(api_specs_path, "idn")
45+
subprocess.run(["node", "sdk-resources/prescript.js", idn_path], check=True, cwd=root)
46+
47+
def build_sdk(name, spec, config, out_dir):
48+
print(f"Building {name} SDK...")
49+
sailpoint_dir = os.path.join(root, "sailpoint", out_dir)
50+
if os.path.isdir(sailpoint_dir):
51+
shutil.rmtree(sailpoint_dir)
52+
spec_path = os.path.join(api_specs_path, "idn", spec)
53+
subprocess.run(
54+
[
55+
"java", "-jar", jar_path, "generate",
56+
"-i", spec_path,
57+
"-g", "python", "-o", ".",
58+
"--global-property", "skipFormModel=false,apiDocs=true,modelDocs=true",
59+
"--config", f"sdk-resources/{config}",
60+
],
61+
check=True,
62+
cwd=root,
63+
)
64+
subprocess.run(
65+
["node", "sdk-resources/postscript.js", sailpoint_dir],
66+
check=True,
67+
cwd=root,
68+
)
69+
70+
build_sdk("V3", "sailpoint-api.v3.yaml", "v3-config.yaml", "v3")
71+
build_sdk("Beta", "sailpoint-api.beta.yaml", "beta-config.yaml", "beta")
72+
build_sdk("V2024", "sailpoint-api.v2024.yaml", "v2024-config.yaml", "v2024")
73+
build_sdk("V2025", "sailpoint-api.v2025.yaml", "v2025-config.yaml", "v2025")
74+
build_sdk("V2026", "sailpoint-api.v2026.yaml", "v2026-config.yaml", "v2026")
75+
76+
# Install and test (use current Python / venv)
77+
pip_cmd = [sys.executable, "-m", "pip"]
78+
print("Installing dependencies and SDK...")
79+
subprocess.run(pip_cmd + ["install", "-r", "requirements.txt"], check=True, cwd=root)
80+
subprocess.run(pip_cmd + ["install", "-e", "."], check=True, cwd=root)
81+
82+
if not skip_tests:
83+
print("Running validation tests...")
84+
subprocess.run(
85+
[sys.executable, "validation_test.py", "-v"],
86+
check=True,
87+
cwd=root,
88+
)
89+
else:
90+
print(f"Skipping tests (SKIP_TESTS={os.environ.get('SKIP_TESTS', '')})")
91+
92+
print("Done.")
93+
94+
95+
if __name__ == "__main__":
96+
main()

0 commit comments

Comments
 (0)