Skip to content

Commit 80ead5f

Browse files
polatenginmawasile
andauthored
fix: improve issue extraction logic and ensure correct output file path (#1015)
Co-authored-by: Mateusz Wasilewski <50197777+mawasile@users.noreply.github.com>
1 parent cd38df1 commit 80ead5f

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

scripts/user_story_prompt.sh

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
set -euo pipefail
23

34
# Check if gh CLI is installed
45
if ! command -v gh &> /dev/null; then
@@ -10,6 +11,8 @@ fi
1011
current_branch=$(git branch --show-current)
1112
echo "Current branch: $current_branch"
1213

14+
repo_root=$(git rev-parse --show-toplevel)
15+
1316
# Try to extract issue number from branch name
1417
# Common patterns: issue-123, 123-description, feature/123-description
1518
issue_number=""
@@ -25,18 +28,14 @@ fi
2528
# If no issue found in branch name, try to get the PR that this branch is for
2629
if [[ -z "$issue_number" ]]; then
2730
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
3937
fi
38+
fi
4039
fi
4140

4241
# If still no issue found, ask user
@@ -55,10 +54,10 @@ fi
5554
echo "Using issue number: $issue_number"
5655

5756
# 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"
5958

6059
# 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"
6261
if gh issue view "$issue_number" > "$output_file" 2>/dev/null; then
6362
echo "Successfully saved issue #$issue_number to $output_file"
6463
echo "Path: $output_file"

0 commit comments

Comments
 (0)