Skip to content

Commit

Permalink
Add comment.js and update slither.yml workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Aboudjem committed Feb 20, 2024
1 parent 5331043 commit b94114a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
23 changes: 23 additions & 0 deletions .github/scripts/comment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = async ({ github, context, header, body }) => {
const comment = [header, body].join("\n");

const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
});

const botComment = comments.find(
comment => comment.user.type === 'Bot' && comment.body.startsWith(header)
);

const commentFn = botComment ? 'updateComment' : 'createComment';

await github.rest.issues[commentFn]({
owner: context.repo.owner,
repo: context.repo.repo,
body: comment,
...(botComment ? { comment_id: botComment.id } : { issue_number: context.payload.pull_request.number }),
});
};

26 changes: 18 additions & 8 deletions .github/workflows/slither.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
name: Slither Analysis
on: [push]

on: push

jobs:
analyze:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Checkout repository
uses: actions/checkout@v4

- name: Run Slither
uses: crytic/[email protected]
id: slither
with:
sarif: results.sarif
fail-on: medium
node-version: '16'
fail-on: 'none'
slither-args: '--checklist --markdown-root ${{ github.server_url }}/${{ github.repository }}/blob/${{ github.sha }}/'

- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v3
- name: Create/update checklist as PR comment
uses: actions/github-script@v7
if: github.event_name == 'pull_request'
env:
REPORT: ${{ steps.slither.outputs.stdout }}
with:
sarif_file: ${{ steps.slither.outputs.sarif }}
token: ${{ secrets.PAT_TOKEN }}
script: |
const script = require('.github/scripts/comment')
const header = '# Slither report'
const body = process.env.REPORT
await script({ github, context, header, body })

0 comments on commit b94114a

Please sign in to comment.