add week1 study #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: PR Blog Summarizer | |
on: | |
pull_request: | |
types: [opened, synchronize] | |
permissions: | |
issues: write | |
pull-requests: write | |
jobs: | |
process: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Check out the code | |
- name: Check out code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
# Set up Python | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.8" | |
# Install dependencies | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install openai requests | |
# Step 2: Get Changed Files | |
- name: Get Changed Files | |
id: get_files | |
run: | | |
CHANGED_FILES=$(git diff --name-only origin/main ${{ github.sha }}) | |
if [ -z "$CHANGED_FILES" ]; then | |
echo "changed_files=" >> $GITHUB_ENV | |
else | |
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 3: Process Changed Files | |
- name: Process Changed Files | |
env: | |
OPENAI_API_KEY: ${{ secrets.GPT_KEY }} | |
run: | | |
if [ -z "${{ env.changed_files }}" ]; then | |
exit 0 | |
fi | |
SUMMARY_MESSAGE="### Automated Review\n" | |
IFS=$'\n' | |
for file_path in ${{ env.changed_files }}; do | |
# Check if the file contains a "link" field | |
link=$(grep 'link: ' "$file_path" | sed 's/link: //') | |
if [ -n "$link" ]; then | |
# Run summarize.py if "link" is found | |
SUMMARY=$(python summarize.py "$link") | |
SUMMARY_MESSAGE+="Blog Link: $link\n" | |
SUMMARY_MESSAGE+="$SUMMARY\n" | |
else | |
# Run feedback.py with the file's content if no "link" is found | |
FILE_CONTENT=$(cat "$file_path") | |
FEEDBACK=$(python feedback.py --content "$FILE_CONTENT") | |
SUMMARY_MESSAGE+="Feedback for file: $file_path\n" | |
SUMMARY_MESSAGE+="$FEEDBACK\n" | |
fi | |
done | |
echo "summary_message<<EOF" >> $GITHUB_ENV | |
echo -e "$SUMMARY_MESSAGE" >> $GITHUB_ENV | |
echo "EOF" >> $GITHUB_ENV | |
# Step 4: Post Comment on Pull Request | |
- name: Post Comment on Pull Request | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const summary = process.env.summary_message; | |
if (summary && summary.trim().length > 0) { | |
await github.rest.issues.createComment({ | |
...context.repo, | |
issue_number: context.payload.pull_request.number, | |
body: summary | |
}); | |
} |