Skip to content

Commit 0118bd8

Browse files
authored
Merge pull request #45 from MisRob/fix-slack-snippet
Fix Slack notification snippet
2 parents 2a8e1b1 + e93df69 commit 0118bd8

File tree

3 files changed

+79
-47
lines changed

3 files changed

+79
-47
lines changed

scripts/constants.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ const CLOSE_CONTRIBUTORS = [
2222
'muditchoudhary',
2323
'nathanaelg16',
2424
'nikkuAg',
25+
'Prashant-thakur77',
2526
'Sahil-Sinha-11',
2627
'shivam-daksh',
2728
'shruti862',
2829
'thesujai',
30+
'vtushar06',
2931
'WinnyChang',
3032
'yeshwanth235',
3133
];
@@ -96,6 +98,9 @@ const PR_STATS_REPOS = [
9698
'ricecooker',
9799
];
98100

101+
// Repositories in which we accept open-source contributions
102+
const COMMUNITY_REPOS = [...PR_STATS_REPOS];
103+
99104
module.exports = {
100105
LE_BOT_USERNAME,
101106
SENTRY_BOT_USERNAME,
@@ -109,4 +114,5 @@ module.exports = {
109114
TEAMS_WITH_CLOSE_CONTRIBUTORS,
110115
HOLIDAY_MESSAGE,
111116
PR_STATS_REPOS,
117+
COMMUNITY_REPOS,
112118
};

scripts/contributor-issue-comment.js

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,59 +6,18 @@ const {
66
ISSUE_LABEL_HELP_WANTED,
77
BOT_MESSAGE_ISSUE_NOT_OPEN,
88
BOT_MESSAGE_ALREADY_ASSIGNED,
9+
COMMUNITY_REPOS,
910
} = require('./constants');
1011
const {
1112
isCloseContributor,
1213
sendBotMessage,
1314
escapeIssueTitleForSlackMessage,
1415
hasRecentBotComment,
16+
hasLabel,
17+
getIssues,
18+
getPullRequests,
1519
} = require('./utils');
1620

17-
async function hasLabel(name, owner, repo, issueNumber, github, core) {
18-
let labels = [];
19-
try {
20-
const response = await github.rest.issues.listLabelsOnIssue({
21-
owner,
22-
repo,
23-
issue_number: issueNumber,
24-
});
25-
labels = response.data.map(label => label.name);
26-
} catch (error) {
27-
core.warning(`Failed to fetch labels on issue #${issueNumber}: ${error.message}`);
28-
labels = [];
29-
}
30-
return labels.some(label => label.toLowerCase() === name.toLowerCase());
31-
}
32-
33-
async function getIssues(assignee, state, owner, repo, github, core) {
34-
try {
35-
const response = await github.rest.issues.listForRepo({
36-
owner,
37-
repo,
38-
assignee,
39-
state,
40-
});
41-
return response.data.filter(issue => !issue.pull_request);
42-
} catch (error) {
43-
core.warning(`Failed to fetch issues: ${error.message}`);
44-
return [];
45-
}
46-
}
47-
48-
async function getPullRequests(assignee, state, owner, repo, github, core) {
49-
try {
50-
const response = await github.rest.pulls.list({
51-
owner,
52-
repo,
53-
state,
54-
});
55-
return response.data.filter(pr => pr.user.login === assignee);
56-
} catch (error) {
57-
core.warning(`Failed to fetch pull requests: ${error.message}`);
58-
return [];
59-
}
60-
}
61-
6221
// Format information about author's assigned open issues
6322
// as '(Issues #1 #2 | PRs #3)' and PRs for Slack message
6423
function formatAuthorActivity(issues, pullRequests) {
@@ -201,8 +160,8 @@ module.exports = async ({ github, context, core }) => {
201160

202161
if (contactSupport) {
203162
const [assignedOpenIssues, openPRs] = await Promise.all([
204-
getIssues(commentAuthor, 'open', owner, repo, github, core),
205-
getPullRequests(commentAuthor, 'open', owner, repo, github, core),
163+
getIssues(commentAuthor, 'open', owner, COMMUNITY_REPOS, github, core),
164+
getPullRequests(commentAuthor, 'open', owner, COMMUNITY_REPOS, github, core),
206165
]);
207166
const authorActivity = formatAuthorActivity(assignedOpenIssues, openPRs);
208167
slackMessage += ` _${authorActivity}_`;

scripts/utils.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,78 @@ async function hasRecentBotComment(
170170
}
171171
}
172172

173+
/**
174+
* Checks if an issue has a label with the given name (case-insensitive).
175+
*/
176+
async function hasLabel(name, owner, repo, issueNumber, github, core) {
177+
let labels = [];
178+
try {
179+
const allLabels = await github.paginate(github.rest.issues.listLabelsOnIssue, {
180+
owner,
181+
repo,
182+
issue_number: issueNumber,
183+
});
184+
labels = allLabels.map(label => label.name);
185+
} catch (error) {
186+
core.warning(`Failed to fetch labels on issue #${issueNumber}: ${error.message}`);
187+
labels = [];
188+
}
189+
return labels.some(label => label.toLowerCase() === name.toLowerCase());
190+
}
191+
192+
/**
193+
* Fetches issues assigned to an assignee in given repositories.
194+
*/
195+
async function getIssues(assignee, state, owner, repos, github, core) {
196+
const promises = repos.map(repo =>
197+
github
198+
.paginate(github.rest.issues.listForRepo, {
199+
owner,
200+
repo,
201+
assignee,
202+
state,
203+
})
204+
.then(issues => issues.filter(issue => !issue.pull_request))
205+
.catch(error => {
206+
core.warning(`Failed to fetch issues from ${repo}: ${error.message}`);
207+
return [];
208+
}),
209+
);
210+
211+
const results = await Promise.all(promises);
212+
return results.flat();
213+
}
214+
215+
/**
216+
* Fetches pull requests by an author in given repositories.
217+
*/
218+
async function getPullRequests(author, state, owner, repos, github, core) {
219+
const promises = repos.map(repo =>
220+
github
221+
.paginate(github.rest.pulls.list, {
222+
owner,
223+
repo,
224+
state,
225+
})
226+
.then(prs => prs.filter(pr => pr.user.login === author))
227+
.catch(error => {
228+
core.warning(`Failed to fetch pull requests from ${repo}: ${error.message}`);
229+
return [];
230+
}),
231+
);
232+
233+
const results = await Promise.all(promises);
234+
return results.flat();
235+
}
236+
173237
module.exports = {
174238
isContributor,
175239
isCloseContributor,
176240
isBot,
177241
sendBotMessage,
178242
escapeIssueTitleForSlackMessage,
179243
hasRecentBotComment,
244+
hasLabel,
245+
getIssues,
246+
getPullRequests,
180247
};

0 commit comments

Comments
 (0)