-
-
Notifications
You must be signed in to change notification settings - Fork 137
140 lines (122 loc) · 5.52 KB
/
Copy pathissue-star-thanks.yml
File metadata and controls
140 lines (122 loc) · 5.52 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# When an issue is closed as completed or a discussion is marked as answered
# (GitHub Actions has no "discussion closed" trigger), post a short automated
# message: a thank-you if the author already starred the repo, otherwise an
# invitation to star it. Bots and the project's own team (owner, members,
# collaborators) are skipped. Since June 2026 GitHub restricts a repo's
# stargazer list to admins/collaborators, so the star check reads the
# author's own starred-repos list instead; if that check fails it falls
# back to the invitation message.
name: Thank issue and discussion authors when resolved
on:
issues:
types:
- closed
discussion:
types:
- answered
permissions: {}
jobs:
thank-on-issue:
if: github.event_name == 'issues'
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Post a short thank-you comment
uses: actions/github-script@v8
with:
script: |
const { owner, repo } = context.repo;
const issue = context.payload.issue;
if (issue.state_reason !== 'completed') {
console.log(`Issue #${issue.number} closed as "${issue.state_reason}", not completed. Skipping.`);
return;
}
const author = issue.user.login;
if (issue.user.type === 'Bot' || author.endsWith('[bot]')) {
console.log(`Skipping bot account ${author}.`);
return;
}
if (['OWNER', 'MEMBER', 'COLLABORATOR'].includes(issue.author_association)) {
console.log(`Skipping team member ${author} (${issue.author_association}).`);
return;
}
const fullName = `${owner}/${repo}`.toLowerCase();
let hasStarred = false;
try {
let pages = 0;
for await (const { data } of github.paginate.iterator(
github.rest.activity.listReposStarredByUser,
{ username: author, per_page: 100 },
)) {
if (data.some((r) => ((r.full_name || (r.repo && r.repo.full_name) || '')).toLowerCase() === fullName)) {
hasStarred = true;
break;
}
if (++pages >= 30) {
console.log(`Stopped star check for ${author} after ${pages} pages.`);
break;
}
}
} catch (error) {
console.log(`Could not check stars for ${author}: ${error.message}`);
}
const thanksForStar = `We've closed the issue now, thanks for having starred AudioMuse-AI and supporting self-hosted music here on GitHub! It really helps the project grow!`;
const pleaseStar = `We've closed the issue now, so if you like AudioMuse-AI and want to improve self-hosted music, why not consider giving us a star here on GitHub? It helps the project grow!`;
await github.rest.issues.createComment({
owner,
repo,
issue_number: issue.number,
body: hasStarred ? thanksForStar : pleaseStar,
});
thank-on-discussion:
if: github.event_name == 'discussion'
runs-on: ubuntu-latest
permissions:
discussions: write
steps:
- name: Post a short thank-you comment
uses: actions/github-script@v8
with:
script: |
const { owner, repo } = context.repo;
const discussion = context.payload.discussion;
const author = discussion.user.login;
if (discussion.user.type === 'Bot' || author.endsWith('[bot]')) {
console.log(`Skipping bot account ${author}.`);
return;
}
if (['OWNER', 'MEMBER', 'COLLABORATOR'].includes(discussion.author_association)) {
console.log(`Skipping team member ${author} (${discussion.author_association}).`);
return;
}
const fullName = `${owner}/${repo}`.toLowerCase();
let hasStarred = false;
try {
let pages = 0;
for await (const { data } of github.paginate.iterator(
github.rest.activity.listReposStarredByUser,
{ username: author, per_page: 100 },
)) {
if (data.some((r) => ((r.full_name || (r.repo && r.repo.full_name) || '')).toLowerCase() === fullName)) {
hasStarred = true;
break;
}
if (++pages >= 30) {
console.log(`Stopped star check for ${author} after ${pages} pages.`);
break;
}
}
} catch (error) {
console.log(`Could not check stars for ${author}: ${error.message}`);
}
const thanksForStar = `Your discussion has its answer now - thanks for having starred AudioMuse-AI and supporting self-hosted music here on GitHub! It really helps the project grow!`;
const pleaseStar = `Your discussion has its answer now, so if you like AudioMuse-AI and want to improve self-hosted music, why not consider giving us a star here on GitHub? It helps the project grow!`;
await github.graphql(
`mutation($discussionId: ID!, $body: String!) {
addDiscussionComment(input: { discussionId: $discussionId, body: $body }) {
comment { id }
}
}`,
{ discussionId: discussion.node_id, body: hasStarred ? thanksForStar : pleaseStar },
);