|
| 1 | +name: Compare Fork |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + fork_url: |
| 7 | + description: 'Fork URL to compare with' |
| 8 | + required: true |
| 9 | + default: 'https://github.com/planetoftheorg/react-in-action-from-setup-to-deployment-5972102' |
| 10 | + |
| 11 | +jobs: |
| 12 | + compare-fork: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout repository |
| 17 | + uses: actions/checkout@v2 |
| 18 | + |
| 19 | + - name: Extract fork information |
| 20 | + id: extract_fork_info |
| 21 | + run: | |
| 22 | + echo "Fork URL: ${{ github.event.inputs.fork_url }}" |
| 23 | + # Extract owner and repo from the fork URL |
| 24 | + FORK_OWNER=$(echo "${{ github.event.inputs.fork_url }}" | awk -F '/' '{print $4}') |
| 25 | + FORK_REPO=$(echo "${{ github.event.inputs.fork_url }}" | awk -F '/' '{print $5}') |
| 26 | + echo "fork_owner=$FORK_OWNER" >> $GITHUB_ENV |
| 27 | + echo "fork_repo=$FORK_REPO" >> $GITHUB_ENV |
| 28 | +
|
| 29 | + - name: Fetch changes between main branch and fork |
| 30 | + id: fetch_changes |
| 31 | + run: | |
| 32 | + BASE_BRANCH="main" |
| 33 | + FORK_BRANCH="main" |
| 34 | + FORK_OWNER=${{ env.fork_owner }} |
| 35 | + FORK_REPO=${{ env.fork_repo }} |
| 36 | + CHANGES=$(git diff $BASE_BRANCH...$FORK_OWNER/$FORK_REPO:$FORK_BRANCH --name-only) |
| 37 | + echo "changes=$CHANGES" >> $GITHUB_ENV |
| 38 | +
|
| 39 | + - name: Generate document using AI |
| 40 | + id: generate_document |
| 41 | + env: |
| 42 | + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} # Reference the secret here |
| 43 | + run: | |
| 44 | + CHANGES=${{ env.changes }} |
| 45 | + PROMPT=$(cat <<-END |
| 46 | + Pretend the changes haven't been done and write a document that asks someone to make the changes as part of a capstone document. I don't need the actual changes, just the document describing a project that might contain the changes. |
| 47 | +
|
| 48 | + I don't need the code. Just a summary of what sort of changes the student might make. Keep it short and make the explanations simple for a beginner audience. |
| 49 | +
|
| 50 | + At the end, add a short list of other suggestions, but don't show any code. Assume that the student is a beginner, Junior Developer, so make the changes simple and something a beginner might implement. |
| 51 | + END |
| 52 | + ) |
| 53 | + RESPONSE=$(curl -X POST "https://api.openai.com/v1/engines/davinci-codex/completions" \ |
| 54 | + -H "Content-Type: application/json" \ |
| 55 | + -H "Authorization: Bearer $OPENAI_API_KEY" \ |
| 56 | + -d '{ |
| 57 | + "prompt": "'"$PROMPT"'", |
| 58 | + "max_tokens": 500 |
| 59 | + }') |
| 60 | + echo "response=$RESPONSE" >> $GITHUB_ENV |
| 61 | +
|
| 62 | + - name: Save document |
| 63 | + run: | |
| 64 | + echo "${{ env.response }}" > CAPSTONE_DOCUMENT.md |
| 65 | + git config --global user.name 'github-actions' |
| 66 | + git config --global user.email '[email protected]' |
| 67 | + git add CAPSTONE_DOCUMENT.md |
| 68 | + git commit -m "Add generated capstone document" |
| 69 | + git push |
0 commit comments