Skip to content

Commit

Permalink
ci: add gh slither action
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey-N-Chernyshov committed Oct 13, 2023
1 parent 94eec2a commit b121f63
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
21 changes: 20 additions & 1 deletion .github/scripts/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
module.exports = async ({ github, context, header, body }) => {
const comment = [header, body].join("\n");

const pr_number = await get_pr_number(github, context);

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

const botComment = comments.find(
Expand All @@ -25,3 +27,20 @@ module.exports = async ({ github, context, header, body }) => {
: { issue_number: context.payload.number }),
});
};

// Returns gh PR number
async function get_pr_number(github, context) {
if (context.issue.number) {
// Return issue number if present
return context.issue.number;
} else {
// Otherwise return issue number from commit
return (
await github.rest.repos.listPullRequestsAssociatedWithCommit({
commit_sha: context.sha,
owner: context.repo.owner,
repo: context.repo.repo,
})
).data[0].number;
}
}
14 changes: 9 additions & 5 deletions .github/workflows/slither.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,25 @@ jobs:
id: slither
with:
fail-on: none
continue-on-error: true
sarif: results.sarif
slither-config: ethereum-bridge-contracts/slither.config.json
target: ethereum-bridge-contracts
slither-args: --checklist --markdown-root ${{ github.server_url }}/${{ github.repository }}/blob/${{ github.sha }}/

- name: ls
run: ls
- name: Push SARIF to DefectDojo
# TODO: push to DefectDojo
# run: ls results.sarif
run: echo ${{ github.event.number }}

- name: Create/update checklist as PR comment
uses: actions/github-script@v6
if: github.event_name == 'push'
env:
REPORT: ${{ steps.slither.outputs.stdout }}
with:
script: |
const script = require('.github/scripts/comment')
const header = '# Slither report'
# const body = `${{ steps.slither.outputs.stdout }}`
# await script({ github, context, header, body })
const { REPORT } = process.env
const { PR_NUMBER } = process.env
await script({ github, context, header, body: REPORT })

0 comments on commit b121f63

Please sign in to comment.