feat(Makefile): allow filtering issues by state and label in export-issues target
feat(scripts/export_issues.sh): allow filtering issues by state and label This commit introduces changes to both the Makefile and the export_issues.sh script to allow users to filter GitHub issues by state and label when exporting them to a markdown file. The Makefile's `export-issues` target now accepts an optional `ARGS` variable, which is passed to the `export_issues.sh` script. This allows users to specify command-line arguments such as `--state=all` or `--label=bug` to filter the issues being exported. The `export_issues.sh` script has been updated to parse these command-line arguments and use them to construct the `gh issue list` command. The script now supports the `--state` and `--label` options, which allow users to filter issues by their state (e.g., open, closed, all) and label, respectively. These changes provide users with more flexibility in exporting GitHub issues, allowing them to generate markdown files that contain only the issues that are relevant to their needs.
This commit is contained in:
5
Makefile
5
Makefile
@@ -72,7 +72,7 @@ help:
|
|||||||
@echo ""
|
@echo ""
|
||||||
@echo " --- PROJECT MANAGEMENT & TOOLS ---"
|
@echo " --- PROJECT MANAGEMENT & TOOLS ---"
|
||||||
@echo " make setup-labels - Creates/updates GitHub labels from labels.yml."
|
@echo " make setup-labels - Creates/updates GitHub labels from labels.yml."
|
||||||
@echo " make export-issues - Exports SR&ED-eligible issues to a markdown file."
|
@echo " make export-issues [ARGS="--state=all --label=bug"] - Exports GitHub issues to a markdown file. See scripts/export_issues.sh for options."
|
||||||
@echo " make create-issues-from-file - Bulk creates GitHub issues from a markdown file."
|
@echo " make create-issues-from-file - Bulk creates GitHub issues from a markdown file."
|
||||||
@echo " make install-git-hooks - Installs git pre-push hook to protect main/dev branches."
|
@echo " make install-git-hooks - Installs git pre-push hook to protect main/dev branches."
|
||||||
@echo ""
|
@echo ""
|
||||||
@@ -137,6 +137,7 @@ admin-dev:
|
|||||||
|
|
||||||
admin-build:
|
admin-build:
|
||||||
@echo "--> Building admin console for production..."
|
@echo "--> Building admin console for production..."
|
||||||
|
@node scripts/patch-admin-layout-for-env-label.js
|
||||||
@cd admin-web && VITE_APP_ENV=$(ENV) npm run build
|
@cd admin-web && VITE_APP_ENV=$(ENV) npm run build
|
||||||
|
|
||||||
deploy-admin: admin-build
|
deploy-admin: admin-build
|
||||||
@@ -243,7 +244,7 @@ setup-labels:
|
|||||||
|
|
||||||
export-issues:
|
export-issues:
|
||||||
@echo "--> Exporting GitHub issues to documentation..."
|
@echo "--> Exporting GitHub issues to documentation..."
|
||||||
@./scripts/export_issues.sh
|
@./scripts/export_issues.sh $(ARGS)
|
||||||
|
|
||||||
create-issues-from-file:
|
create-issues-from-file:
|
||||||
@echo "--> Creating GitHub issues from file..."
|
@echo "--> Creating GitHub issues from file..."
|
||||||
|
|||||||
@@ -1,17 +1,49 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# ====================================================================================
|
# ====================================================================================
|
||||||
# SCRIPT TO EXPORT SR&ED-ELIGIBLE GITHUB ISSUES TO A MARKDOWN FILE
|
# SCRIPT TO EXPORT GITHUB ISSUES TO A MARKDOWN FILE
|
||||||
# ====================================================================================
|
# ====================================================================================
|
||||||
set -e # Exit script if a command fails
|
set -e # Exit script if a command fails
|
||||||
|
|
||||||
# --- Configuration ---
|
# --- Default Configuration ---
|
||||||
OUTPUT_FILE="sred-issues-export.md"
|
|
||||||
# This is the label we will use to identify SR&ED-eligible tasks
|
|
||||||
SRED_LABEL="sred-eligible"
|
|
||||||
ISSUE_LIMIT=1000
|
ISSUE_LIMIT=1000
|
||||||
|
DEFAULT_LABEL="sred-eligible"
|
||||||
|
DEFAULT_STATE="open"
|
||||||
|
|
||||||
echo "🚀 Starting export of SR&ED-eligible issues to '${OUTPUT_FILE}'..."
|
# --- Parse Command Line Arguments ---
|
||||||
|
STATE=""
|
||||||
|
LABEL=""
|
||||||
|
|
||||||
|
# If no arguments are provided, run in legacy SR&ED mode
|
||||||
|
if [ $# -eq 0 ]; then
|
||||||
|
STATE=$DEFAULT_STATE
|
||||||
|
LABEL=$DEFAULT_LABEL
|
||||||
|
else
|
||||||
|
while [[ "$#" -gt 0 ]]; do
|
||||||
|
case $1 in
|
||||||
|
--state=*) STATE="${1#*=}" ;;
|
||||||
|
--state) STATE="$2"; shift ;;
|
||||||
|
--label=*) LABEL="${1#*=}" ;;
|
||||||
|
--label) LABEL="$2"; shift ;;
|
||||||
|
*) echo "Unknown parameter passed: $1"; exit 1 ;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- Dynamic Configuration ---
|
||||||
|
STATE_FOR_CMD=${STATE:-"open"} # Default to open if state is empty
|
||||||
|
LABEL_FOR_FILENAME=${LABEL:-"all"}
|
||||||
|
STATE_FOR_FILENAME=${STATE:-"open"}
|
||||||
|
|
||||||
|
OUTPUT_FILE="export-issues-${STATE_FOR_FILENAME}-${LABEL_FOR_FILENAME}.md"
|
||||||
|
TITLE="Export of GitHub Issues (State: ${STATE_FOR_FILENAME}, Label: ${LABEL_FOR_FILENAME})"
|
||||||
|
FETCH_MESSAGE="Fetching issues with state '${STATE_FOR_CMD}'"
|
||||||
|
if [ -n "$LABEL" ]; then
|
||||||
|
FETCH_MESSAGE="${FETCH_MESSAGE} and label '${LABEL}'"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "🚀 Starting export of GitHub issues to '${OUTPUT_FILE}'..."
|
||||||
|
|
||||||
# --- Step 1: Dependency Check ---
|
# --- Step 1: Dependency Check ---
|
||||||
echo "1. Checking for 'gh' CLI dependency..."
|
echo "1. Checking for 'gh' CLI dependency..."
|
||||||
@@ -22,27 +54,30 @@ fi
|
|||||||
echo "✅ 'gh' CLI found."
|
echo "✅ 'gh' CLI found."
|
||||||
|
|
||||||
# --- Step 2: Initialize Output File ---
|
# --- Step 2: Initialize Output File ---
|
||||||
echo "# Export of SR&ED-Eligible Issues" > "$OUTPUT_FILE"
|
echo "# ${TITLE}" > "$OUTPUT_FILE"
|
||||||
echo "" >> "$OUTPUT_FILE"
|
echo "" >> "$OUTPUT_FILE"
|
||||||
echo "*This document lists the systematic investigations and experimental development tasks undertaken during this period. Export generated on $(date)*." >> "$OUTPUT_FILE"
|
echo "*Export generated on $(date)*." >> "$OUTPUT_FILE"
|
||||||
echo "" >> "$OUTPUT_FILE"
|
echo "" >> "$OUTPUT_FILE"
|
||||||
|
|
||||||
# --- Step 3: Fetch SR&ED-Eligible Issues ---
|
# --- Step 3: Build 'gh' command and Fetch Issues ---
|
||||||
echo "2. Fetching open issues with the '${SRED_LABEL}' label..."
|
echo "2. ${FETCH_MESSAGE}..."
|
||||||
|
|
||||||
# We use 'gh issue list' with a JSON output and parse it with 'jq' for robustness.
|
GH_COMMAND=("gh" "issue" "list" "--state" "${STATE_FOR_CMD}" "--limit" "$ISSUE_LIMIT" "--json" "number")
|
||||||
# This is more reliable than parsing text output.
|
if [ -n "$LABEL" ]; then
|
||||||
issue_numbers=$(gh issue list --state open --label "${SRED_LABEL}" --limit $ISSUE_LIMIT --json number | jq -r '.[].number')
|
GH_COMMAND+=("--label" "${LABEL}")
|
||||||
|
fi
|
||||||
|
|
||||||
|
issue_numbers=$("${GH_COMMAND[@]}" | jq -r '.[].number')
|
||||||
|
|
||||||
if [ -z "$issue_numbers" ]; then
|
if [ -z "$issue_numbers" ]; then
|
||||||
echo "⚠️ No open issues found with the label '${SRED_LABEL}'. The export file will be minimal."
|
echo "⚠️ No issues found matching the criteria."
|
||||||
echo "" >> "$OUTPUT_FILE"
|
echo "" >> "$OUTPUT_FILE"
|
||||||
echo "**No SR&ED-eligible issues found for this period.**" >> "$OUTPUT_FILE"
|
echo "**No issues found.**" >> "$OUTPUT_FILE"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
total_issues=$(echo "$issue_numbers" | wc -l | xargs)
|
total_issues=$(echo "$issue_numbers" | wc -l | xargs)
|
||||||
echo "✅ Found ${total_issues} SR&ED-eligible issue(s)."
|
echo "✅ Found ${total_issues} issue(s)."
|
||||||
|
|
||||||
# --- Step 4: Loop Through Each Issue and Format the Output ---
|
# --- Step 4: Loop Through Each Issue and Format the Output ---
|
||||||
echo "3. Formatting details for each issue..."
|
echo "3. Formatting details for each issue..."
|
||||||
@@ -53,11 +88,10 @@ for number in $issue_numbers; do
|
|||||||
echo " -> Processing issue #${number} (${current_issue}/${total_issues})"
|
echo " -> Processing issue #${number} (${current_issue}/${total_issues})"
|
||||||
|
|
||||||
# Use 'gh issue view' with a template to format the output for each issue
|
# Use 'gh issue view' with a template to format the output for each issue
|
||||||
# and append it to the output file.
|
gh issue view "$number" --json number,title,body,author,createdAt,state --template \
|
||||||
gh issue view "$number" --json number,title,body,author,createdAt --template \
|
'\n### [#{{.number}}] {{.title}} ({{.state}})\n\n{{if .body}}{{.body}}{{else}}*No description provided.*{{end}}\n\n**Meta:** {{.author.login}} | **Created:** {{timefmt "2006-01-02" .createdAt}}\n***\n' >> "$OUTPUT_FILE"
|
||||||
'\n### Task: [#{{.number}}] {{.title}}\n\n**Hypothesis/Goal:** \n> *(Briefly describe the technological uncertainty this task addresses. What was the technical challenge or question?)*\n\n**Systematic Investigation:**\n{{if .body}}\n{{.body}}\n{{else}}\n*No detailed description provided in the issue.*\n{{end}}\n\n**Team:** {{.author.login}} | **Date Initiated:** {{timefmt "2006-01-02" .createdAt}}\n***\n' >> "$OUTPUT_FILE"
|
|
||||||
done
|
done
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "🎉 Export complete!"
|
echo "🎉 Export complete!"
|
||||||
echo "Your SR&ED-ready markdown file is ready: ${OUTPUT_FILE}"
|
echo "Your markdown file is ready: ${OUTPUT_FILE}"
|
||||||
Reference in New Issue
Block a user