Docs: Add link to week2 #38
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: | |
summarize: | |
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: Extract Links and Summarize | |
- name: Extract Links and Summarize | |
env: | |
OPENAI_API_KEY: ${{ secrets.GPT_KEY }} | |
run: | | |
if [ -z "${{ env.changed_files }}" ]; then | |
exit 0 | |
fi | |
SUMMARY_MESSAGE="### Chat GPT's review\n" | |
IFS=$'\n' | |
for file_path in ${{ env.changed_files }}; do | |
link=$(grep 'link: ' "$file_path" | sed 's/link: //') | |
if [ -z "$link" ]; then | |
continue | |
fi | |
SUMMARY=$(python summarize.py "$link") | |
SUMMARY_MESSAGE+="Blog Link: $link\n" | |
SUMMARY_MESSAGE+="$SUMMARY\n" | |
done | |
echo "summary_message<<EOF" >> $GITHUB_ENV | |
echo -e "$SUMMARY_MESSAGE" >> $GITHUB_ENV | |
echo "EOF" >> $GITHUB_ENV | |
# Step 4: Post Comment on Pull Request Using `octokit/rest.js` | |
- 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 provided by actions/github-script | |
await github.rest.issues.createComment({ | |
...context.repo, | |
issue_number: context.payload.pull_request.number, | |
body: summary | |
}); | |
} |