Revision fb87d7dff80139f56f3dd3c37b58e1e9cc79f02d authored by Andrey Zhavoronkov on 14 June 2023, 21:13:38 UTC, committed by GitHub on 14 June 2023, 21:13:38 UTC
<!-- Raise an issue to propose your change
(https://github.com/opencv/cvat/issues).
It helps to avoid duplication of efforts from multiple independent
contributors.
Discuss your ideas with maintainers to be sure that changes will be
approved and merged.
Read the [Contribution
guide](https://opencv.github.io/cvat/docs/contributing/). -->

<!-- Provide a general summary of your changes in the Title above -->

### Motivation and context
<!-- Why is this change required? What problem does it solve? If it
fixes an open
issue, please link to the issue here. Describe your changes in detail,
add
screenshots. -->

### How has this been tested?
<!-- Please describe in detail how you tested your changes.
Include details of your testing environment, and the tests you ran to
see how your change affects other areas of the code, etc. -->
Manually with docker-compose.https.yml config enabled

### Checklist
<!-- Go over all the following points, and put an `x` in all the boxes
that apply.
If an item isn't applicable for some reason, then ~~explicitly
strikethrough~~ the whole
line. If you don't do that, GitHub will show incorrect progress for the
pull request.
If you're unsure about any of these, don't hesitate to ask. We're here
to help! -->
- [x] I submit my changes into the `develop` branch
- [ ] I have added a description of my changes into the
[CHANGELOG](https://github.com/opencv/cvat/blob/develop/CHANGELOG.md)
file
- [ ] I have updated the documentation accordingly
- [ ] I have added tests to cover my changes
- [ ] I have linked related issues (see [GitHub docs](

https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword))
- [ ] I have increased versions of npm packages if it is necessary

([cvat-canvas](https://github.com/opencv/cvat/tree/develop/cvat-canvas#versioning),

[cvat-core](https://github.com/opencv/cvat/tree/develop/cvat-core#versioning),

[cvat-data](https://github.com/opencv/cvat/tree/develop/cvat-data#versioning)
and

[cvat-ui](https://github.com/opencv/cvat/tree/develop/cvat-ui#versioning))

### License

- [x] I submit _my code changes_ under the same [MIT License](
https://github.com/opencv/cvat/blob/develop/LICENSE) that covers the
project.
  Feel free to contact the maintainers if that's a concern.

---------

Co-authored-by: Nikita Manovich <nikita@cvat.ai>
1 parent b19e925
Raw File
comment.yml
name: Comment
on:
  issue_comment:
    types: [created]

env:
  WORKFLOW_RUN_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}

jobs:
  verify_author:
    if: contains(github.event.issue.html_url, '/pull') &&
      contains(github.event.comment.body, '/check')
    runs-on: ubuntu-latest
    outputs:
      ref: ${{ steps.get-ref.outputs.ref }}
      cid: ${{ steps.send-status.outputs.cid }}
    env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    steps:
      - name: Check author of comment
        id: check-author
        run: |
          PERM=$(gh api repos/${{ github.repository }}/collaborators/${{ github.event.comment.user.login }}/permission | jq -r '.permission')
          if [[ $PERM == "write" || $PERM == "maintain" || $PERM == "admin" ]];
          then
            ALLOW="true"
          fi
          echo "allow=${ALLOW}" >> $GITHUB_OUTPUT

      - name: Verify that author of comment is collaborator
        if: steps.check-author.outputs.allow == ''
        uses: actions/github-script@v3
        with:
          script: |
            core.setFailed('User that send comment with /check command is not collaborator')

      - name: Get branch name
        id: get-ref
        run: |
          SHA=$(gh api /repos/${{ github.repository }}/pulls/${{ github.event.issue.number }} | jq -r '.head.sha')
          echo "ref=${SHA}" >> $GITHUB_OUTPUT

      - name: Send comment. Test are executing
        id: send-status
        run: |
          BODY=":hourglass: Tests are executing, see more information [here](${{ env.WORKFLOW_RUN_URL }})"
          BODY=$BODY"\n :warning: Cancel [this](${{ env.WORKFLOW_RUN_URL }}) workflow manually first, if you want to restart full check"
          BODY=$(echo -e $BODY)

          COMMENT_ID=$(gh api --method POST \
            /repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments \
            -f body="${BODY}" | jq '.id')

          echo "cid=${COMMENT_ID}" >> $GITHUB_OUTPUT

  run-full:
    needs: verify_author
    uses: ./.github/workflows/full.yml
    with:
      ref: ${{ needs.verify_author.outputs.ref }}

  send_status:
    runs-on: ubuntu-latest
    needs: [run-full, verify_author]
    if: needs.run-full.result != 'skipped' && always()
    env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    steps:
      - name: Send status in comments
        run: |
          BODY=""

          if [[ "${{ needs.run-full.result }}" == "failure" ]]
          then
            BODY=":x: Some checks failed"
          elif [[ "${{ needs.run-full.result }}" == "success" ]]
          then
            BODY=":heavy_check_mark: All checks completed successfully"
          elif [[ "${{ needs.run-full.result }}" == "cancelled" ]]
          then
            BODY=":no_entry_sign: Workflows has been canceled"
          fi

          BODY=$BODY"\n :page_facing_up: See logs [here](${WORKFLOW_RUN_URL})"
          BODY=$(echo -e $BODY)

          gh api --method PATCH \
            /repos/${{ github.repository }}/issues/comments/${{ needs.verify_author.outputs.cid }} \
            -f body="${BODY}"
back to top