-
Notifications
You must be signed in to change notification settings - Fork 1.1k
67 lines (59 loc) · 1.85 KB
/
pr-cleanup.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
name: 'Cleanup Netlify PR Comments'
on:
workflow_dispatch:
issue_comment:
types:
- edited
- created
- deleted
defaults:
run:
shell: bash
env:
ACTIONS_RUNNER_DEBUG: true
NODE_OPTIONS: '--no-warnings'
jobs:
cleanup:
runs-on: ['ubuntu-latest']
name: 'Cleanup PR comments'
permissions:
issues: write
contents: write
if: |
contains(github.event.comment.body, 'Deploy Preview for *unionlabs* ready!') ||
github.event.comment.user.name == 'netlify[bot]'
steps:
- name: 'Checkout'
uses: actions/checkout@v4
- name: 'Get Changed Files'
id: 'changed-files'
uses: tj-actions/changed-files@v45
with:
since_last_remote_commit: true
files: |
./site/**/*
# delete Netlify comment if no site files changed
- name: 'Site Files Changed'
if: steps.changed-files.outputs.any_changed == 'false'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { owner, repo } = context.repo
// https://octokit.github.io/rest.js/v21/#issues-list-comments
const comments = await github.rest.issues.listComments({
repo: 'union',
owner: 'unionlabs',
issue_number: context.issue.number,
})
const relevantComment = comments.data.find(
comment => comment.user.login === 'netlify[bot]'
);
if (!relevantComment) return
// https://octokit.github.io/rest.js/v21/#issues-delete-comment
const deleteComment = await github.rest.issues.deleteComment({
repo: 'union',
owner: 'unionlabs',
comment_id: relevantComment.id,
})
console.info(deleteComment)