-
Notifications
You must be signed in to change notification settings - Fork 0
71 lines (60 loc) · 2.33 KB
/
upload-plugin.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: Upload plugin
on:
issue_comment:
types:
- created
- edited
jobs:
check-and-upload-plugin:
name: Check and upload plugin
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- uses: denoland/setup-deno@v1
with:
deno-version: v1.37.2
- name: Check plugin and valid accept
id: check
uses: actions/github-script@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue = context.payload.issue;
const comment = context.payload.comment;
const description = issue.body;
if (description.includes('#request-upload-plugin')) {
const commentBody = comment.body.toLowerCase();
const commentAuthor = comment.user.login;
const repoOwner = context.repo.owner;
const repoName = context.repo.repo;
// Get repository collaborators
const collaborators = await github.rest.repos.listCollaborators({
owner: repoOwner,
repo: repoName,
per_page: 100,
});
// Check if the comment author is a collaborator with write access
const isCollaboratorWithWriteAccess = collaborators.data.some(collaborator => {
return collaborator.login === commentAuthor && collaborator.permissions.push;
});
if (commentBody.includes('accept') && isCollaboratorWithWriteAccess) {
console.log('Accepted issue:', issue.number);
return JSON.stringify({ id: issue.number, user: issue.user.login })
} else {
console.log('Issue not accepted:', issue.number);
return false
}
}
return false
- name: Setup env
run: |
echo '' > .env
echo 'GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}"' >> .env
echo 'OK_OWNER="manga-raiku"' >> .env
echo 'OK_REPO="plugins"' >> .env
echo 'OK_BRANCH="plugins"' >> .env
- name: Run scripts upload plugin
id: run
if: steps.check.outputs.result != 'false'
run: deno run --allow-read --allow-env --allow-net ./scripts/upload-plugin.ts ${{ steps.check.outputs.result }}