87 lines
3.0 KiB
YAML
87 lines
3.0 KiB
YAML
name: Queue Skill Optimization Apply
|
|
on:
|
|
issue_comment:
|
|
types: [created]
|
|
|
|
jobs:
|
|
queue:
|
|
if: >-
|
|
github.event.issue.pull_request &&
|
|
contains(github.event.comment.body, '/apply-optimize')
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
actions: write
|
|
contents: read
|
|
issues: write
|
|
pull-requests: read
|
|
steps:
|
|
- uses: actions/github-script@v7
|
|
with:
|
|
github-token: ${{ github.token }}
|
|
script: |
|
|
const trusted = new Set(['OWNER', 'MEMBER', 'COLLABORATOR']);
|
|
const prNumber = context.payload.issue?.number;
|
|
const association = context.payload.comment?.author_association ?? 'NONE';
|
|
|
|
if (!prNumber) {
|
|
core.setFailed('No pull request number found in issue_comment payload.');
|
|
return;
|
|
}
|
|
|
|
const { data: pr } = await github.rest.pulls.get({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
pull_number: prNumber,
|
|
});
|
|
|
|
if (!trusted.has(association)) {
|
|
await github.rest.issues.createComment({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: prNumber,
|
|
body:
|
|
'⚠️ `/apply-optimize` can only be queued by repository maintainers ' +
|
|
'(OWNER, MEMBER, or COLLABORATOR).',
|
|
});
|
|
return;
|
|
}
|
|
|
|
if (pr.head.repo.full_name !== `${context.repo.owner}/${context.repo.repo}`) {
|
|
await github.rest.issues.createComment({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: prNumber,
|
|
body:
|
|
'⚠️ `/apply-optimize` only auto-applies for pull requests whose head branch ' +
|
|
'lives in this repository. Fork PRs must apply the suggested changes manually.',
|
|
});
|
|
return;
|
|
}
|
|
|
|
await github.rest.actions.createWorkflowDispatch({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
workflow_id: 'skill-apply-optimize-run.yml',
|
|
ref: context.payload.repository.default_branch,
|
|
inputs: {
|
|
pr_number: String(prNumber),
|
|
},
|
|
});
|
|
|
|
await github.rest.reactions.createForIssueComment({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
comment_id: context.payload.comment.id,
|
|
content: 'eyes',
|
|
});
|
|
|
|
await github.rest.issues.createComment({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: prNumber,
|
|
body:
|
|
'👀 Queued the trusted `/apply-optimize` workflow for this PR. ' +
|
|
'It will fetch the repository branch from a separate workflow and apply the ' +
|
|
'latest Tessl optimization suggestion if one is available.',
|
|
});
|