Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Step 4b

Step 4b #3

name: Step 4b # Copilot on GitHub
on:
# Trigger if PR Description is edited
# pull_request:
# branches:
# - main
# types:
# - edited
# Trigger if Copilot adds a review comment
pull_request_review:
permissions:
contents: write
actions: write
issues: write
pull-requests: read
repository-projects: read
jobs:
find_exercise:
if: |
!github.event.repository.is_template
name: Find exercise by issue title
runs-on: ubuntu-latest
outputs:
issue-url: ${{ steps.get-issue-url.outputs.ISSUE_URL }}
steps:
- id: get-issue-url
run: |
# Get the issue url from the event or search for it.
if [ -n "${{ github.event.issue }}" ]; then
issue_url="${{ github.event.issue.html_url }}"
else
issue_url=$(gh issue list --repo $REPO --search "in:title Exercise:" --json url,title --jq '.[].url')
fi
# Save to output
echo "ISSUE_URL=$issue_url" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
check_step_work:
name: Check step work
runs-on: ubuntu-latest
needs: [find_exercise]
env:
ISSUE_URL: ${{ needs.find_exercise.outputs.issue-url }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get response templates
uses: actions/checkout@v4
with:
repository: skills/response-templates
path: skills-response-templates
# START: Check practical exercise
- name: Check for pr description and copilot review
id: check-user-work
run: |
# Checks to perform
checks='{
"pr_description": {
"name": "PR Description",
"passed": true,
"message": ""
},
"copilot_review": {
"name": "Copilot Review",
"passed": true,
"message": ""
}
}'
# Check if PR has a description and minimum length
min_length=15
body_length=$(echo "$PR_Body" | wc -c)
echo "PR decription length: $body_length"
if [ "$body_length" -lt $min_length ]; then
checks=$(echo $checks | jq '.pr_description.passed = false')
checks=$(echo $checks | jq '.pr_description.message = "Please use Copilot to generate a pull request description."')
fi
# Check for a PR Review from Copilot
reviews=$(gh pr view --repo $REPO $PR_NUMBER --json reviews)
authors=$(echo "$reviews" | jq '.reviews[].author.login')
if echo "$authors" | grep -q "copilot-pull-request-reviewer"; then
echo "Copilot has reviewed this PR."
else
echo "Copilot has NOT reviewed this PR."
checks=$(echo $checks | jq '.copilot_review.passed = false')
checks=$(echo $checks | jq '.copilot_review.message = "Please request a review from Copilot."')
fi
# Verify all checks passed
passed=$(echo $checks | jq '. | all(.passed?)')
# Flatten to an array for returning. Allows iteration during rendering.
results=$(echo $checks | jq 'to_entries | map({name: .key} + .value)')
# Save pass status to output
echo "passed=$passed" >> $GITHUB_OUTPUT
# Save results to output
echo 'results<<EOF' >> $GITHUB_OUTPUT
echo $results >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_Body: ${{ github.event.pull_request.body }}
REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
- name: Build message - step results
id: build-message-step-results
uses: skills/action-text-variables@v1
with:
template-file: skills-response-templates/step-feedback/step-results.md
template-vars: '{
"step_number": 4,
"passed": ${{ steps.check-user-work.outputs.passed }},
"results_table": ${{ steps.check-user-work.outputs.results }},
"tips": [
"Copilot review will also suggest changes for common mistakes and typos.",
"You can use repository rulesets to automatically require a review from Copilot."
]
}'
- name: Create comment - step results
run: |
gh issue comment "$ISSUE_URL" \
--body "$COMMENT_BODY"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMENT_BODY: ${{ steps.build-message-step-results.outputs.updated-text }}
- name: Fail job if not all checks passed
if: steps.check-user-work.outputs.passed == 'false'
run: exit 1
# END: Check practical exercise
Morty Proxy This is a proxified and sanitized view of the page, visit original site.