Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict cq permissions #33

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/comment-labeled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,23 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh pr comment ${{ github.event.pull_request.number }} --repo ${{ github.repository }} --body "Fast-track has been requested by @${{ github.actor }}. Please 👍 to approve."

commit-queue:
if: github.event_name == 'pull_request_target' && github.event.label.name == 'commit-queue'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Restrict Commit-Queue to collaborators
run: ./tools/get-collaborators.mjs | grep -q "${{ github.actor }}"
- name: Remove label if necessary
if: {{ failure() }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE_URL: ${{ github.event.pull_request.issue_url }}
COMMIT_QUEUE_LABEL: ${{ github.event.label.name }}
run: |
gh pr comment ${{ github.event.pull_request.number }} --repo ${{ github.repository }} \
--body "Only collaborators can use the commit queue." &&
curl -X DELETE "$ISSUE_URL/labels/$COMMIT_QUEUE_LABEL" \
-H "Content-Type: application/json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}"
17 changes: 17 additions & 0 deletions tools/get-collaborators.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env node
import { createInterface } from 'node:readline';
import fs from 'node:fs';

const README = new URL('../README.md', import.meta.url);
const input = fs.createReadStream(README);

let COLLABORATOR_LIST_START = '### Collaborators';
let COLLABORATOR_LIST_END = '### Collaborator emeriti';

let collaboratorListStarted = false;
for await (const line of createInterface({ input, crlfDelay: Infinity })) {
if (line === COLLABORATOR_LIST_END) break;
else if (collaboratorListStarted) console.log(line);
else if (line === COLLABORATOR_LIST_START)
collaboratorListStarted = true;
}