[CI] Update Stylebot Permissions (#792)
This commit is contained in:
parent
e81c36cf74
commit
9c1a893ee3
|
@ -5,17 +5,50 @@ on:
|
||||||
issue_comment:
|
issue_comment:
|
||||||
types: [created]
|
types: [created]
|
||||||
|
|
||||||
permissions:
|
permissions: {}
|
||||||
contents: write
|
|
||||||
pull-requests: write
|
env:
|
||||||
|
PYTHON_VERSION: "3.10"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
run-style-bot:
|
check-permissions:
|
||||||
if: >
|
if: >
|
||||||
contains(github.event.comment.body, '@bot /style') &&
|
contains(github.event.comment.body, '@bot /style') &&
|
||||||
github.event.issue.pull_request != null
|
github.event.issue.pull_request != null
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
is_authorized: ${{ steps.check_user_permission.outputs.has_permission }}
|
||||||
|
steps:
|
||||||
|
- name: Check user permission
|
||||||
|
id: check_user_permission
|
||||||
|
uses: actions/github-script@v6
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
const comment_user = context.payload.comment.user.login;
|
||||||
|
const { data: permission } = await github.rest.repos.getCollaboratorPermissionLevel({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
username: comment_user
|
||||||
|
});
|
||||||
|
|
||||||
|
const authorized =
|
||||||
|
permission.permission === 'admin' ||
|
||||||
|
permission.permission === 'write';
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`User ${comment_user} has permission level: ${permission.permission}, ` +
|
||||||
|
`authorized: ${authorized} (admins & maintainers allowed)`
|
||||||
|
);
|
||||||
|
|
||||||
|
core.setOutput('has_permission', authorized);
|
||||||
|
|
||||||
|
run-style-bot:
|
||||||
|
needs: check-permissions
|
||||||
|
if: needs.check-permissions.outputs.is_authorized == 'true'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
pull-requests: write
|
||||||
steps:
|
steps:
|
||||||
- name: Extract PR details
|
- name: Extract PR details
|
||||||
id: pr_info
|
id: pr_info
|
||||||
|
@ -61,6 +94,8 @@ jobs:
|
||||||
|
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: ${{ env.PYTHON_VERSION }}
|
||||||
|
|
||||||
- name: Get Ruff Version from pre-commit-config.yaml
|
- name: Get Ruff Version from pre-commit-config.yaml
|
||||||
id: get-ruff-version
|
id: get-ruff-version
|
||||||
|
|
Loading…
Reference in New Issue