Skip to content

github action, summarize.py 추가 #22

github action, summarize.py 추가

github action, summarize.py 추가 #22

Workflow file for this run

name: PR Blog Summarizer
on:
pull_request:
types: [opened, synchronize]
permissions:
issues: write
pull-requests: write
jobs:
summarize:
runs-on: ubuntu-latest
steps:
# Step 1: Check out the code
- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 0
# Step 2: Set up Python
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.8"
# Step 3: Install dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install openai requests
# Step 4: Get Changed Files
- name: Get Changed Files
id: get_files
run: |
# Get the list of changed files between the two commits
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }})
if [ -z "$CHANGED_FILES" ]; then
echo "changed_files=" >> $GITHUB_ENV
else
# Filter files that match the pattern week[0-9]+/.*_link.md
FILTERED_FILES=$(echo "$CHANGED_FILES" | grep -E 'week[0-9]+/.*_link\.md$')
if [ -z "$FILTERED_FILES" ]; then
echo "changed_files=" >> $GITHUB_ENV
else
echo "changed_files=$FILTERED_FILES" >> $GITHUB_ENV
fi
fi
# Step 5: Extract Links and Summarize
- name: Extract Links and Summarize
env:
OPENAI_API_KEY: ${{ secrets.GPT_KEY }}
run: |
# Check if there are any changed files that match the criteria
if [ -z "${{ env.changed_files }}" ]; then
exit 0 # No files to process, exit successfully
fi
SUMMARY_MESSAGE="### Chat GPT's review \n"
IFS=$'\n'
for file_path in ${{ env.changed_files }}; do
# Extract the link from the _link.md file
link=$(grep 'link: ' "$file_path" | sed 's/link: //')
if [ -z "$link" ]; then
continue # Skip if no link is found
fi
# Summarize the link using the Python script
SUMMARY=$(python summarize.py "$link")
SUMMARY_MESSAGE+="Blog Link: $link \n $SUMMARY\n"
done
# Save the summary message as an environment variable
echo "summary_message<<EOF" >> $GITHUB_ENV
echo "$SUMMARY_MESSAGE" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
# Step 6: Post Comment on Pull Request
- name: Post Comment on Pull Request
uses: actions/github-script@v6
with:
github-token: ${{ github.token }}
script: |
const summary = process.env.summary_message;
if (summary && summary.trim().length > 0) {
// Use the existing github object to post the comment
await github.rest.issues.createComment({
...context.repo,
issue_number: context.payload.pull_request.number,
body: summary
});
}