Open PrinceGupta1999 opened 1 year ago
Only push
, workflow_dispatch
, pull_request
, and pull_request_target
events are supported, see here.
Could you explain why you need to run the action on issue_comment
?
@ocean90 thanks for the reply. I wanted this action to run on issue_comment so that the lint does not run on each push of the pull request and can just be run when a dev wants to lint his PR (for ex: before putting it up for review).
Here is the way I am currently using it
name: Lint (auto fix)
on:
issue_comment:
types: [created]
jobs:
check-comment:
if: github.event.issue.pull_request
name: Check Comment
runs-on: ubuntu-latest
outputs:
status: ${{ steps.check.outputs.triggered }}
pr: ${{ steps.get-pr.outputs.result }}
steps:
- uses: Khan/pull-request-comment-trigger@1.0.0
id: check
with:
trigger: '@run-lint'
reaction: eyes
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
- uses: actions/github-script@v6.3.3
id: get-pr
with:
retries: 2
script: |
return github.rest.pulls.get({
pull_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
})
run-linters:
needs: check-comment
name: Run linters
runs-on: ubuntu-latest
if: needs.check-comment.outputs.status == 'true'
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ fromJson(needs.check-comment.outputs.pr).data.head.ref }}
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: 14.17.6
- name: Install Node.js dependencies
run: npm ci
- name: Run linters
run: npm run format && (npm run lint:fix || true) # Ideally I would want to use lint-action for the individual status checks for prettier / eslint
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Lint Fixes
branch: ${{ fromJson(needs.check-comment.outputs.pr).data.head.ref }}
The reason for not using lint with auto_fix: true
on PRs / Push is that I don't want to create potential extra commits in the PR when I am in make the code work phase.
I see. Please feel free to submit a PR that adds support for the issue_comment
event.
Sure, I will take this up in this or the next week. I am assuming the only change that needs to happed is to add support for issue_comment
event in this function https://github.com/wearerequired/lint-action/blob/640cbd3acbeb113f05067c41db28f1836e1861ce/src/github/context.js#L68-L82 by using some equivalent of this code from my workflow file
return github.rest.pulls.get({
pull_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
})
Hi @ocean90 can I use the @actions/github package or is the Rest API call (to fetch the repo branch from PR) to be made manually. The package does provide a Github client and context which should make the task easier and maybe even the current context fetching function and related logic can be done using this ?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Hi @ocean90 any update on this ?
I was trying to trigger this action when a specific comment is made on the PR. However I got the following error
Error: lint-action does not support "issue_comment" GitHub events
So, I would like to know which github events are supported by this action and how could I go about solving my use case ?