Skip to content

Commit 5a95340

Browse files
committed
build: refactor script for creatin sub-issues more generally
1 parent 0a8192d commit 5a95340

File tree

2 files changed

+36
-40
lines changed

2 files changed

+36
-40
lines changed

Diff for: .github/workflows/lint_random_files.yml

+24-9
Original file line numberDiff line numberDiff line change
@@ -393,15 +393,30 @@ jobs:
393393
env:
394394
GITHUB_TOKEN: ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}
395395
run: |
396-
# Create a temporary file for storing lint error messages:
397-
ERROR_LOG=$(mktemp)
398-
grep -B 1 -A 2 "style:\|warning:\|error:" <<< "${{ steps.lint-c.outputs.stderr }}" > $ERROR_LOG
399-
400-
. "$GITHUB_WORKSPACE/.github/workflows/scripts/create_lint_sub_issue" \
401-
"${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
402-
"C" \
403-
"3235" \ # Number of C lint error tracking issue
404-
"$ERROR_LOG"
396+
BODY_FILE="$GITHUB_WORKSPACE/lint_issue_body.md"
397+
398+
cat << EOF > "$BODY_FILE"
399+
## C Linting Failures
400+
401+
Linting failures were detected in the automated lint workflow run.
402+
403+
### Workflow Details
404+
- Run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
405+
- Type: C Linting
406+
- Date: $(date -u +"%Y-%m-%d %H:%M:%S UTC")
407+
408+
### Error Details
409+
\`\`\`
410+
$(grep -B 1 -A 2 "style:\|warning:\|error:" <<< "${{ steps.lint-c.outputs.stderr }}")
411+
\`\`\`
412+
EOF
413+
414+
. "$GITHUB_WORKSPACE/.github/workflows/scripts/create_sub_issue" \
415+
'Fix C lint errors' \
416+
"$BODY_FILE" \
417+
"3235" # Number of C lint error tracking issue
418+
419+
rm "$BODY_FILE"
405420
406421
# Lint TypeScript declarations files:
407422
- name: 'Lint TypeScript declarations files'

Diff for: .github/workflows/scripts/create_lint_sub_issue renamed to .github/workflows/scripts/create_sub_issue

+12-31
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,15 @@
1616
# See the License for the specific language governing permissions and
1717
# limitations under the License.
1818

19-
# Script to create a sub-issue for linting failures
19+
# Script to create a sub-issue.
2020
#
21-
# Usage: ./create_lint_sub_issue.sh <workflow-url> <lint-type> <parent-issue-number>
21+
# Usage: ./create_sub_issue.sh <issue-title> <body-file> <parent-issue-number>
2222
#
2323
# Arguments:
2424
#
25-
# workflow-url URL of the workflow run.
26-
# lint-type Type of linting failure.
25+
# issue-title Title for the new sub-issue.
26+
# body-file Path to the file containing the issue body.
2727
# parent-issue-number Number of the parent issue.
28-
# error-log-file Path to the error log file.
29-
#
3028
#
3129
# Environment variables:
3230
#
@@ -41,10 +39,9 @@ set -o pipefail
4139
# VARIABLES #
4240

4341
# Assign command line arguments to variables:
44-
workflow_url="$1"
45-
lint_type="$2"
42+
issue_title="$1"
43+
body_file="$2"
4644
parent_issue_number="$3"
47-
error_log_file="$4"
4845

4946
# Repository information:
5047
owner="stdlib-js"
@@ -57,28 +54,12 @@ if [ -z "$github_token" ]; then
5754
exit 1
5855
fi
5956

60-
# Read and format the error log
61-
if [ ! -f "$error_log_file" ]; then
62-
echo -e "Error log file not found: ${error_log_file}"
57+
# Read and validate the body file:
58+
if [ ! -f "$body_file" ]; then
59+
echo -e "ERROR: Body file not found: ${body_file}"
6360
exit 1
6461
fi
65-
error_log_content=$(cat "$error_log_file")
66-
67-
# Create issue body with formatted error log
68-
issue_body="## ${lint_type} Linting Failures
69-
70-
Linting failures were detected in the automated lint workflow run.
71-
72-
### Workflow Details
73-
- Run: ${workflow_url}
74-
- Type: ${lint_type} Linting
75-
- Date: $(date -u +"%Y-%m-%d %H:%M:%S UTC")
76-
77-
### Error Details
78-
\`\`\`
79-
${error_log_content}
80-
\`\`\`
81-
"
62+
issue_body=$(cat "$body_file")
8263

8364
# FUNCTIONS #
8465

@@ -130,7 +111,7 @@ create_child_issue() {
130111
"query": "mutation CreateIssue(\$repositoryId: ID!, \$title: String!, \$body: String!) { createIssue(input: {repositoryId: \$repositoryId, title: \$title, body: \$body}) { issue { id number } } }",
131112
"variables": {
132113
"repositoryId": "${repo_id}",
133-
"title": "Fix ${lint_type} lint errors",
114+
"title": "${issue_title}",
134115
"body": $(echo "$issue_body" | jq -R -s '.')
135116
}
136117
}
@@ -194,7 +175,7 @@ main() {
194175
exit 1
195176
fi
196177

197-
echo "Creating child issue for ${lint_type} lint failures..."
178+
echo "Creating child issue..."
198179
child_issue_response=$(create_child_issue "$repo_id" "$issue_body")
199180

200181
child_issue_id=$(echo "$child_issue_response" | jq -r '.data.createIssue.issue.id')

0 commit comments

Comments
 (0)