2024-12-26 19:20:32 +00:00
|
|
|
#!/bin/sh
|
2024-12-06 21:31:20 -05:00
|
|
|
|
|
|
|
ROOT_DIR=$(git rev-parse --show-toplevel)
|
|
|
|
|
2024-12-26 19:20:32 +00:00
|
|
|
select_scope() {
|
|
|
|
cat "$ROOT_DIR/.github/scopes.json" | jq -r '.scopes[]' | fzf --prompt "Select scope:"
|
|
|
|
}
|
2024-12-06 21:31:20 -05:00
|
|
|
|
2024-12-26 19:20:32 +00:00
|
|
|
get_title() {
|
|
|
|
gum input --placeholder "Issue Title..."
|
|
|
|
}
|
2024-12-06 21:31:20 -05:00
|
|
|
|
2024-12-26 19:20:32 +00:00
|
|
|
add_requirement() {
|
|
|
|
requirement=$(gum input --placeholder "Add a requirement...")
|
|
|
|
if [ -n "$requirement" ]; then
|
|
|
|
REQUIREMENTS="$REQUIREMENTS
|
|
|
|
$requirement"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
return 1
|
|
|
|
}
|
2024-12-06 21:31:20 -05:00
|
|
|
|
2024-12-26 19:20:32 +00:00
|
|
|
collect_requirements() {
|
|
|
|
REQUIREMENTS=""
|
|
|
|
req_count=0
|
|
|
|
while true; do
|
|
|
|
if add_requirement; then
|
|
|
|
req_count=$((req_count + 1))
|
2024-12-26 19:32:23 +00:00
|
|
|
if [ $req_count -ge 2 ] && ! gum confirm --default=false "Do you want to add another requirement?"; then
|
2024-12-26 19:20:32 +00:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if [ $req_count -ge 2 ]; then
|
|
|
|
break
|
|
|
|
else
|
|
|
|
echo "Requirement cannot be empty. Please enter a valid requirement."
|
|
|
|
fi
|
2024-12-06 21:31:20 -05:00
|
|
|
fi
|
2024-12-26 19:20:32 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
get_docs() {
|
|
|
|
docs=$(cat "$ROOT_DIR/.github/scopes.json" | jq -c '.docs')
|
|
|
|
mods --role "determine-issue-docs" "$SCOPE" "$TITLE" "$docs"
|
|
|
|
}
|
|
|
|
|
|
|
|
get_goal() {
|
|
|
|
mods --role "determine-issue-goal" "$SCOPE $TITLE"
|
|
|
|
}
|
|
|
|
|
|
|
|
format_requirements() {
|
|
|
|
i=1
|
|
|
|
echo "$REQUIREMENTS" | while IFS= read -r req; do
|
|
|
|
if [ -n "$req" ]; then
|
|
|
|
echo "$i. $req"
|
|
|
|
i=$((i + 1))
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
2024-12-06 21:31:20 -05:00
|
|
|
|
|
|
|
create_body() {
|
2024-12-26 19:20:32 +00:00
|
|
|
goal=$(get_goal)
|
|
|
|
docs=$(get_docs)
|
|
|
|
|
2024-12-06 21:31:20 -05:00
|
|
|
echo "### Goal(s):"
|
2024-12-26 19:20:32 +00:00
|
|
|
echo "$goal"
|
|
|
|
echo
|
2024-12-06 21:31:20 -05:00
|
|
|
echo "### Requirements:"
|
2024-12-26 19:20:32 +00:00
|
|
|
format_requirements
|
|
|
|
echo
|
2024-12-06 21:31:20 -05:00
|
|
|
echo "### Resources:"
|
2024-12-26 19:20:32 +00:00
|
|
|
echo "$docs"
|
2024-12-06 21:31:20 -05:00
|
|
|
}
|
|
|
|
|
2024-12-26 19:20:32 +00:00
|
|
|
preview_issue() {
|
2024-12-27 06:23:10 +00:00
|
|
|
echo "# [$SCOPE] $TITLE"
|
2024-12-06 21:31:20 -05:00
|
|
|
echo "$ISSUE_BODY"
|
|
|
|
}
|
|
|
|
|
2024-12-26 19:20:32 +00:00
|
|
|
create_github_issue() {
|
|
|
|
draft_flag=""
|
|
|
|
if gum confirm "Assign this issue to yourself?"; then
|
|
|
|
draft_flag="-a @me"
|
|
|
|
fi
|
|
|
|
|
|
|
|
gh issue create \
|
|
|
|
--repo onsonr/sonr \
|
|
|
|
--title "[$SCOPE] $TITLE" \
|
|
|
|
--body "$ISSUE_BODY" \
|
|
|
|
$draft_flag
|
|
|
|
}
|
2024-12-06 21:31:20 -05:00
|
|
|
|
2024-12-26 19:20:32 +00:00
|
|
|
main() {
|
|
|
|
SCOPE=$(select_scope)
|
|
|
|
TITLE=$(get_title)
|
|
|
|
collect_requirements
|
|
|
|
ISSUE_BODY=$(create_body)
|
|
|
|
|
|
|
|
preview_issue | gum format
|
|
|
|
|
|
|
|
if gum confirm "Do you want to create a new GitHub issue with this information?"; then
|
|
|
|
create_github_issue
|
2024-12-23 13:35:52 -05:00
|
|
|
else
|
2024-12-26 19:20:32 +00:00
|
|
|
exit 1
|
2024-12-23 13:35:52 -05:00
|
|
|
fi
|
2024-12-26 19:20:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
main
|
2024-12-23 13:35:52 -05:00
|
|
|
|