-
Notifications
You must be signed in to change notification settings - Fork 408
94 lines (82 loc) · 3.12 KB
/
follow_and_star_check.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
name: PR Follow and Star Check
on:
pull_request:
types: [opened, reopened]
jobs:
check-follow-and-star:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Check if user is following
id: check-follow
uses: actions/github-script@v6
with:
script: |
const { github, context } = require('@actions/github');
const owner = context.repo.owner;
const prAuthor = context.payload.pull_request.user.login;
const result = await github.rest.users.checkFollowing({
username: prAuthor,
target_user: owner
});
return result.data;
- name: Check if user has starred the repository
id: check-star
uses: actions/github-script@v6
with:
script: |
const { github, context } = require('@actions/github');
const owner = context.repo.owner;
const repo = context.repo.repo;
const prAuthor = context.payload.pull_request.user.login;
try {
const result = await github.rest.activity.getRepoSubscription({
owner: owner,
repo: repo,
username: prAuthor
});
return result.data.subscribed;
} catch (error) {
return false; // User hasn't starred the repo
}
- name: Set check status and leave comment
uses: actions/github-script@v6
with:
script: |
const { github, context } = require('@actions/github');
const isFollowing = steps['check-follow'].outputs.result;
const hasStarred = steps['check-star'].outputs.result;
if (isFollowing && hasStarred) {
await github.rest.checks.create({
owner: context.repo.owner,
repo: context.repo.repo,
name: 'Follow and Star Check',
head_sha: context.payload.pull_request.head.sha,
status: 'completed',
conclusion: 'success',
output: {
title: 'Success',
summary: 'User is following and has starred the repository.'
}
});
} else {
await github.rest.checks.create({
owner: context.repo.owner,
repo: context.repo.repo,
name: 'Follow and Star Check',
head_sha: context.payload.pull_request.head.sha,
status: 'completed',
conclusion: 'failure',
output: {
title: 'Failure',
summary: 'User must follow and star the repository to proceed.'
}
});
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: 'Please follow and star the repository to proceed with your pull request.'
});
}