Skip to content

Provide method to focus on edit #52

Provide method to focus on edit

Provide method to focus on edit #52

Workflow file for this run

name: Create Issue from Commit
on:
push:
branches:
- main
jobs:
create_issues:
runs-on: ubuntu-latest
permissions:
issues: write
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Process all commits
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BEFORE_SHA="${{ github.event.before }}"
CURRENT_SHA="${{ github.event.after }}"
echo "Processing commits from $BEFORE_SHA to $CURRENT_SHA"
COMMITS=$(git log --pretty=format:"%H|%s|%an" $BEFORE_SHA..$CURRENT_SHA)
while IFS='|' read -r COMMIT_ID COMMIT_MSG COMMIT_AUTHOR; do
echo "Processing commit: $COMMIT_ID by $COMMIT_AUTHOR"
upper_msg=$(echo "$COMMIT_MSG" | tr '[:lower:]' '[:upper:]')
case "$upper_msg" in
*"FIX:"*|*"FIXED:"*)
type="Bug"
;;
*"FEATURE:"*|*"FEAT:"*)
type="Feature"
;;
*"ENHANCEMENT:"*|*"ENHANCE:"*)
type="Enhancement"
;;
*"DOC:"*|*"DOCUMENTATION:"*)
type="Documentation"
;;
*)
type="None"
;;
esac
if [ "$type" != "None" ]; then
echo "Creating $type issue for commit: $COMMIT_ID"
TITLE=$(echo "$COMMIT_MSG" | sed -E 's/^(FIX|FIXED|FEATURE|FEAT|ENHANCEMENT|ENHANCE|DOC|DOCUMENTATION):\s*//i')
BODY="**Commit:** https://github.com/$GITHUB_REPOSITORY/commit/$COMMIT_ID\n**Author:** $COMMIT_AUTHOR\n\nThis issue was automatically created from commit $COMMIT_ID"
JSON="{\"title\":\"$TITLE\",\"body\":\"$BODY\",\"labels\":[\"$type\",\"Auto\"]}"
RESPONSE=$(curl -s -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github+json" \
-H "Content-Type: application/json" \
https://api.github.com/repos/${GITHUB_REPOSITORY}/issues \
-d "$JSON")
ISSUE_NUMBER=$(echo "$RESPONSE" | grep -o '"number":[[:space:]]*[0-9]*' | grep -o '[0-9]*')
if [ -z "$ISSUE_NUMBER" ]; then
ISSUE_NUMBER=$(echo "$RESPONSE" | sed -n 's/.*"number":\([0-9]*\).*/\1/p')
fi
if [ -n "$ISSUE_NUMBER" ] && [ "$ISSUE_NUMBER" != "null" ]; then
echo "Waiting 5 seconds before closing issue..."
sleep 5
curl -s -X PATCH \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github+json" \
-H "Content-Type: application/json" \
https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/$ISSUE_NUMBER \
-d '{"state":"closed"}'
echo "Created and closed issue #$ISSUE_NUMBER for commit $COMMIT_ID"
fi
else
echo "Skipping commit $COMMIT_ID - no matching type"
fi
done <<< "$COMMITS"