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

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


The following commit(s) were added to refs/heads/main by this push:
     new 8f09a322d feat: contribution list and github stars via ci
8f09a322d is described below

commit 8f09a322d054905d69f47db54f16e4bd47306593
Author: shuai <[email protected]>
AuthorDate: Tue Feb 25 10:20:10 2025 +0800

    feat: contribution list and github stars via ci
---
 scripts/contributor.js |  6 +++---
 scripts/fetchStars.js  | 28 ++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/scripts/contributor.js b/scripts/contributor.js
index a3b076459..91e71e375 100644
--- a/scripts/contributor.js
+++ b/scripts/contributor.js
@@ -18,7 +18,7 @@ TeamJson.forEach(function(u) {
 
 console.log('ignoreList', ignoreList);
 
-// 获取所有仓库的地址
+// all repo urls
 var repositoryUrls = [
   
'https://api.github.com/repos/apache/answer/contributors?page=%d&per_page=100',
   
'https://api.github.com/repos/apache/answer-plugins/contributors?page=%d&per_page=100',
@@ -33,7 +33,7 @@ function fetchContributors() {
   });
 
   return Promise.all(promises).then(function(results) {
-    // 去重
+    // filter duplicate contributors
     var uniqueContributors = [];
     allContributors.forEach(function(contributor) {
       var existingContributor = uniqueContributors.find(function(c) {
@@ -70,7 +70,7 @@ function fetchPagedContributors(url, index, page, 
currentResults) {
       return res.json();
     })
     .then(function(data) {
-      // 将新获取的数据添加到 currentResults 中
+      // Add the newly fetched data to currentResults
       var newResults = currentResults.concat(
         data.map(function(contributor) {
           return {
diff --git a/scripts/fetchStars.js b/scripts/fetchStars.js
new file mode 100644
index 000000000..33a33a48a
--- /dev/null
+++ b/scripts/fetchStars.js
@@ -0,0 +1,28 @@
+var fs = require('fs');
+var path = require('path');
+
+
+var url = 'https://api.github.com/repos/apache/answer';
+var outputPath = path.join(__dirname, '../static/data/stars.json');
+
+function fetchStars() {
+  fetch(url)
+    .then(function(response) {
+      if (!response.ok) {
+        throw new Error('HTTP error! status:', response.status);
+      }
+      return response.json();
+    })
+    .then(function(data) {
+      console.log(data);
+      fs.mkdirSync(path.dirname(outputPath), { recursive: true });
+      var res = { stars: data.stargazers_count };
+      fs.writeFileSync(outputPath, JSON.stringify(res, null, 2), 'utf8');
+      console.log('Data fetched and saved to', outputPath);
+    })
+    .catch(function (error) {
+      console.error('Error fetching data:', error.message);
+    });
+}
+
+fetchStars();

Reply via email to