feat: label first-time contributor.
diff --git a/index.js b/index.js
index 95ea299..457729a 100644
--- a/index.js
+++ b/index.js
@@ -119,12 +119,17 @@
if (isCore) {
labelList.push('PR: author is committer');
}
+
const content = context.payload.pull_request.body;
if (content && content.indexOf('[x] The API has been changed.') > -1) {
labelList.push('PR: awaiting doc');
commentText += '\n\n' + text.PR_AWAITING_DOC;
}
+ if (await isFirstTimeContributor(context)) {
+ labelList.push('PR: first-time contributor');
+ }
+
const comment = context.octokit.issues.createComment(
context.issue({
body: commentText
@@ -234,6 +239,22 @@
);
}
+async function isFirstTimeContributor (context) {
+ try {
+ const response = await context.octokit.issues.listForRepo(
+ context.repo({
+ state: 'all',
+ creator: context.payload.pull_request.user.login
+ })
+ );
+ return response.data.filter(data => data.pull_request) === 1;
+ }
+ catch (e) {
+ logger.error('failed to check first-time contributor');
+ logger.error(e);
+ }
+}
+
async function translateIssue (context, createdIssue) {
if (!createdIssue) {
return;