-
Notifications
You must be signed in to change notification settings - Fork 323
71 lines (66 loc) · 2.56 KB
/
lints.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
name: lints
on:
pull_request:
types: [opened, reopened, synchronize, ready_for_review]
workflow_dispatch:
jobs:
safe-prompts-lint:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- name: checkout
run: |
commits=${{ github.event.pull_request.commits }}
if [[ -n "$commits" ]]; then
# Prepare enough depth for diffs with master
git fetch --depth="$(( commits + 1 ))"
fi
- uses: actions/setup-node@v3
with:
node-version: 20
- uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # SECURITY: pin third-party action hashes
- run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
shell: bash
id: pnpm-cache
- name: Cache pnpm store
uses: actions/cache@v3
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-20-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: ${{ runner.os }}-20-pnpm-store-
- run: pnpm install
- name: Run lints
run: pnpm ts-node lints/safe-prompts.ts `pnpm ts-node lints/git-diff-ts-ranges.ts`
- uses: actions/github-script@v6
if: ${{ failure() }}
with:
script: |
const pull_number = context.issue.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
const body = '‼️ Hey @sourcegraph/cody-security, please review this PR carefully as it introduces the usage of an `unsafe_` function or abuses PromptString.';
const {data: comments } = await github.rest.issues.listComments({
owner,
repo,
issue_number: pull_number,
});
const previousCommentIndex = comments.findIndex(comment => comment.body === body);
if (previousCommentIndex < 0) {
// Post a comment and tag @sourcegraph/cody-security as reviewers
github.rest.issues.createComment({
issue_number: pull_number,
owner,
repo,
body,
});
// For this to work we need a different access_token, see:
// https://github.com/peter-evans/create-pull-request/issues/155#issuecomment-611904487
//
// github.rest.pulls.requestReviewers({
// owner,
// repo,
// pull_number,
// team_reviewers: ['cody-security']
// });
}