Skip to content

Commit

Permalink
Merge pull request #36287 from github/repo-sync
Browse files Browse the repository at this point in the history
Repo sync
  • Loading branch information
docs-bot authored Feb 14, 2025
2 parents fbed207 + 9e3b30f commit 9738344
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@
"remoteUser": "node",

"hostRequirements": {
"memory": "32gb"
"memory": "16gb"
}
}
51 changes: 39 additions & 12 deletions .github/workflows/alert-changed-branch-protections.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ on:
workflow_dispatch:
schedule:
- cron: '20 16 * * 3' # Run every Wednesday at 16:20 UTC / 8:20 PST
pull_request:
paths:
- .github/workflows/alert-changed-branch-protections.yml
- .github/branch_protection_settings/*.json

permissions:
contents: read
contents: write

jobs:
check-branch-protections:
Expand All @@ -29,30 +33,53 @@ jobs:
GH_TOKEN: ${{ secrets.DOCS_BOT_PAT_WORKFLOW }}
run: |
# Fetch branch protections and store them in a file
gh api /repos/GitHub/docs-internal/branches/${{ matrix.branch }}/protection > ${{ matrix.branch }}-actual.json
gh api /repos/GitHub/docs-internal/branches/${{ matrix.branch }}/protection \
> .github/branch_protection_settings/${{ matrix.branch }}.json
- name: Format fetched settings with prettier for comparison
id: format
run: |
npx prettier --write ${{ matrix.branch }}-actual.json
npx prettier --write .github/branch_protection_settings/${{ matrix.branch }}.json
- name: Compare branch protections
id: compare
run: |
# Compare the fetched branch protections with the committed ones
git diff --no-index .github/branch_protection_settings/${{ matrix.branch }}.json ${{ matrix.branch }}-actual.json || echo "diff_failed=true" >> $GITHUB_ENV
git diff --quiet .github/branch_protection_settings/${{ matrix.branch }}.json \
|| echo "diff_failed=true" >> $GITHUB_ENV
- name: Set failure message
if: env.diff_failed == 'true'
- name: Create a pull request to update branch protection settings
if: ${{ env.diff_failed == 'true' }}
env:
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_READPUBLICKEY }}
run: |
message="Alert due to changes in branch protections for ${{ matrix.branch }}. Please review the changes and ensure they are intentional. If valid, update the branch protection settings in .github/branch_protection_settings/${{ matrix.branch }}.json to match the diff in this workflow."
echo "failure_message=$message" >> $GITHUB_ENV
echo "$message"
echo "Set git config"
git config --global user.name "docs-bot"
git config --global user.email "[email protected]"
echo "Check out a new branch"
xbranch=update-branch-protection-settings-$(date +%s)
git checkout -b $xbranch
echo "Commit changes"
git commit -am "Update branch protection settings"
echo "Push changes"
git push origin $xbranch
echo "Create pull request"
gh pr create \
--title "Update branch protection settings" \
--body "Branch protections have changed." \
--head $xbranch \
--base main
echo "Define pr_url"
echo "pr_url=$(gh pr view --json url --jq .url)" >> $GITHUB_ENV
- uses: ./.github/actions/slack-alert
if: ${{ env.diff_failed == 'true' && github.event_name != 'workflow_dispatch' }}
if: ${{ env.diff_failed == 'true' }}
with:
slack_channel_id: ${{ secrets.DOCS_ALERTS_SLACK_CHANNEL_ID }}
slack_token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}
message: ${{ env.failure_message }}
message: "Branch protections have changed. I've created a pull request to update them. Please review and merge, or revert the change in the GitHub UI. ${{ env.pr_url }}"
color: purple
9 changes: 3 additions & 6 deletions src/frame/middleware/context/generic-toc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,9 @@ async function getTocItems(node: Tree, context: Context, opts: Options): Promise
}
}

let childTocItems = null
if (opts.recurse) {
childTocItems = []
if (child.childPages) {
childTocItems.push(...(await getTocItems(child, context, opts)))
}
let childTocItems = []
if (child.childPages) {
childTocItems.push(...(await getTocItems(child, context, opts)))
}

const fullPath = child.href
Expand Down

0 comments on commit 9738344

Please sign in to comment.