This is an automated email from the ASF dual-hosted git repository.

shuai pushed a commit to branch team-data
in repository https://gitbox.apache.org/repos/asf/incubator-answer-website.git

commit 0f7188d10bea09b55690eaa553dd933d83c6480e
Author: shuai <[email protected]>
AuthorDate: Tue Jun 4 15:04:16 2024 +0800

    chore: update generate team.json's script
---
 scripts/contributor.js | 121 +++++++++++++++++++++++++++++++++++--------------
 1 file changed, 86 insertions(+), 35 deletions(-)

diff --git a/scripts/contributor.js b/scripts/contributor.js
index 684afdf9..cc79b97e 100644
--- a/scripts/contributor.js
+++ b/scripts/contributor.js
@@ -1,44 +1,95 @@
-// Usage: node scripts/contributor.js
-// get contributors from github reset api and save to team.json
-// Notice: per_page max is 100, so if contributors more than 100, need to 
change page number
-
 var fs = require('fs');
 var path = require('path');
+var TeamJson = require('../community/team.json');
 
-var url = 
'https://api.github.com/repos/apache/incubator-answer/contributors?page=1&per_page=100';
 var outputFile = path.resolve(__dirname, '../community/team.json');
 
 // ignore PPMC and committers members
-var ignoreList = ['PrimmaAnna', 'chrisdutz', 'fenbox', 'joyqi', 
'justinmclean', 'kumfo', 'LinkinStars', 'mingcheng', 'jiangbonadia', 
'WillemJiang', 'robinv8', 'shuashuai', 'aichy126', 'haitaojarvis'];
-
-fetch(url).then(function(res) {
-  return res.json();
-}).then(function(data) {
-  console.log('data', data.length);
-  var contributors = data.map(function(contributor) {
-    return {
-      name: contributor.login,
-      github: contributor.html_url,
-      avatar: contributor.avatar_url,
-    };
-  }).filter(function(contributor) {
-    return !ignoreList.includes(contributor.name);
-  });
-  // 按照name字段进行排序
-  contributors.sort(function(a, b) {
-    return a.name.localeCompare(b.name);
+var ignoreList = [];
+TeamJson.forEach(function(u) {
+  if (u.type === 'ppmc' || u.type === 'committer') {
+    u.users.forEach(function(user) {
+      ignoreList.push(user.name);
+    });
+  }
+});
+
+console.log('ignoreList', ignoreList);
+
+// 获取所有仓库的地址
+var repositoryUrls = [
+  
'https://api.github.com/repos/apache/incubator-answer/contributors?page=%d&per_page=100',
+  
'https://api.github.com/repos/apache/incubator-answer-plugins/contributors?page=%d&per_page=100',
+  
'https://api.github.com/repos/apache/incubator-answer-website/contributors?page=%d&per_page=100',
+];
+
+var allContributors = [];
+
+function fetchContributors() {
+  var promises = repositoryUrls.map(function(url, index) {
+    return fetchPagedContributors(url, index, 1, []);
   });
 
-  // read existing data from team.json
-  var existingData = fs.readFileSync(outputFile, 'utf8');
-  var jsonData = JSON.parse(existingData);
-  jsonData[2].users = contributors;
-  // save data to team.json
-  fs.writeFile(outputFile, JSON.stringify(jsonData, null, 2), function(err) {
-    if (err) {
-      console.error('write file err:', err);
-    }
+  return Promise.all(promises).then(function(results) {
+    // 去重
+    var uniqueContributors = [];
+    allContributors.forEach(function(contributor) {
+      var existingContributor = uniqueContributors.find(function(c) {
+        return c.name === contributor.name;
+      });
+      if (!existingContributor) {
+        uniqueContributors.push(contributor);
+      }
+    });
+
+    // Sort by name field
+    uniqueContributors.sort(function(a, b) {
+      return a.name.localeCompare(b.name);
+    });
+
+    // read existing data from team.json
+    var existingData = fs.readFileSync(outputFile, 'utf8');
+    var jsonData = JSON.parse(existingData);
+    jsonData[2].count = uniqueContributors.length;
+    jsonData[2].users = uniqueContributors;
+
+    // save data to team.json
+    fs.writeFile(outputFile, JSON.stringify(jsonData, null, 2), function(err) {
+      if (err) {
+        console.error('write file err:', err);
+      }
+    });
   });
-}).catch(function(err) {
-  console.log('err', err);
-});
+}
+
+function fetchPagedContributors(url, index, page, currentResults) {
+  return fetch(url.replace('%d', page))
+    .then(function(res) {
+      return res.json();
+    })
+    .then(function(data) {
+      // 将新获取的数据添加到 currentResults 中
+      var newResults = currentResults.concat(
+        data.map(function(contributor) {
+          return {
+            name: contributor.login,
+            github: contributor.html_url,
+            avatar: contributor.avatar_url,
+          };
+        }).filter(function(contributor) {
+          return !ignoreList.includes(contributor.name);
+        })
+      );
+
+      // If the returned data length is equal to 100, continue to request the 
next page
+      if (data.length === 100) {
+        return fetchPagedContributors(url, index, page + 1, newResults);
+      } else {
+        // Add the final newResults to the allContributors array.
+        allContributors = allContributors.concat(newResults);
+        return newResults;
+      }
+    });
+}
+
+fetchContributors();

Reply via email to