|
1 | 1 | #!/bin/bash |
| 2 | +set -euo pipefail |
2 | 3 |
|
3 | 4 | # Check if gh CLI is installed |
4 | 5 | if ! command -v gh &> /dev/null; then |
|
10 | 11 | current_branch=$(git branch --show-current) |
11 | 12 | echo "Current branch: $current_branch" |
12 | 13 |
|
| 14 | +repo_root=$(git rev-parse --show-toplevel) |
| 15 | + |
13 | 16 | # Try to extract issue number from branch name |
14 | 17 | # Common patterns: issue-123, 123-description, feature/123-description |
15 | 18 | issue_number="" |
|
25 | 28 | # If no issue found in branch name, try to get the PR that this branch is for |
26 | 29 | if [[ -z "$issue_number" ]]; then |
27 | 30 | echo "Trying to find associated PR for this branch..." |
28 | | - pr_data=$(gh pr list --head "$current_branch" --json number --limit 1 2>/dev/null) |
29 | | - |
30 | | - if [[ -n "$pr_data" && "$pr_data" != "[]" ]]; then |
31 | | - pr_number=$(echo "$pr_data" | grep -o '"number":[0-9]*' | grep -o '[0-9]*') |
32 | | - if [[ -n "$pr_number" ]]; then |
33 | | - echo "Found PR #$pr_number, checking for linked issues..." |
34 | | - issue_data=$(gh pr view "$pr_number" --json closingIssues --jq '.closingIssues[0].number' 2>/dev/null) |
35 | | - if [[ -n "$issue_data" && "$issue_data" != "null" ]]; then |
36 | | - issue_number=$issue_data |
37 | | - fi |
38 | | - fi |
| 31 | + pr_number=$(gh pr list --head "$current_branch" --json number --limit 1 --jq '.[0].number // empty' 2>/dev/null || true) |
| 32 | + if [[ -n "$pr_number" ]]; then |
| 33 | + echo "Found PR #$pr_number, checking for linked issues..." |
| 34 | + issue_data=$(gh pr view "$pr_number" --json closingIssuesReferences --jq '.closingIssues[0].number // empty' 2>/dev/null || true) |
| 35 | + if [[ -n "$issue_data" ]]; then |
| 36 | + issue_number=$issue_data |
39 | 37 | fi |
| 38 | + fi |
40 | 39 | fi |
41 | 40 |
|
42 | 41 | # If still no issue found, ask user |
|
55 | 54 | echo "Using issue number: $issue_number" |
56 | 55 |
|
57 | 56 | # Create the directory if it doesn't exist |
58 | | -mkdir -p "/workspaces/terraform-provider-power-platform/.github/prompts" |
| 57 | +mkdir -p "$repo_root/.github/prompts" |
59 | 58 |
|
60 | 59 | # Use gh CLI to get the issue content and save it to file |
61 | | -output_file="/workspaces/terraform-provider-power-platform/.github/prompts/.userstory.prompt.md" |
| 60 | +output_file="$repo_root/.github/prompts/.userstory.prompt.md" |
62 | 61 | if gh issue view "$issue_number" > "$output_file" 2>/dev/null; then |
63 | 62 | echo "Successfully saved issue #$issue_number to $output_file" |
64 | 63 | echo "Path: $output_file" |
|
0 commit comments