Skip to content

Commit 7d7f0f5

Browse files
authored
Merge pull request #1002 from Divyansh013/main
fixed stewards fetching and contributor guideline link
2 parents 085e780 + eb18571 commit 7d7f0f5

File tree

2 files changed

+65
-42
lines changed

2 files changed

+65
-42
lines changed

.github/actions/translation-tracker/index.js

Lines changed: 65 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const { execSync } = require('child_process');
22
const fs = require('fs');
33
const path = require('path');
4+
const https = require('https');
45
const { Octokit } = require('@octokit/rest');
56
const yaml = require('js-yaml');
67

@@ -43,27 +44,64 @@ function getSlugFromEnglishPath(englishFilePath, contentType) {
4344
return relative;
4445
}
4546

46-
function loadStewardsConfig() {
47-
try {
48-
const stewardsPath = path.join(process.cwd(), '.github', 'stewards.yml');
49-
if (fs.existsSync(stewardsPath)) {
50-
const stewardsContent = fs.readFileSync(stewardsPath, 'utf8');
51-
return yaml.load(stewardsContent);
52-
}
53-
} catch (error) {
54-
console.log(`⚠️ Could not load stewards config: ${error.message}`);
55-
}
56-
return null;
47+
async function loadStewardsConfig() {
48+
const STEWARDS_URL = 'https://raw.githubusercontent.com/processing/p5.js/main/stewards.yml';
49+
50+
return new Promise((resolve, reject) => {
51+
https.get(STEWARDS_URL, (res) => {
52+
let data = '';
53+
54+
res.on('data', (chunk) => {
55+
data += chunk;
56+
});
57+
58+
res.on('end', () => {
59+
try {
60+
const config = yaml.load(data);
61+
console.log('Successfully loaded stewards config from p5.js repository');
62+
resolve(config);
63+
} catch (error) {
64+
console.log(`Could not parse stewards config: ${error.message}`);
65+
resolve(null);
66+
}
67+
});
68+
}).on('error', (error) => {
69+
console.log(` Could not load stewards config from remote: ${error.message}`);
70+
resolve(null);
71+
});
72+
});
5773
}
5874

5975
function getStewardsForLanguage(stewardsConfig, language) {
60-
if (!stewardsConfig || !stewardsConfig.stewards) return [];
76+
if (!stewardsConfig) return [];
6177

62-
const stewards = stewardsConfig.stewards.filter(s =>
63-
s.languages && s.languages.includes(language)
64-
);
78+
// Map website language codes to stewards.yml language codes
79+
const languageMap = {
80+
'zh-Hans': 'zh', // Simplified Chinese
81+
'hi': 'hi',
82+
'ko': 'ko',
83+
'es': 'es'
84+
};
85+
86+
const stewardsLangCode = languageMap[language] || language;
87+
const stewards = [];
6588

66-
return stewards.map(s => `@${s.github}`);
89+
for (const [username, areas] of Object.entries(stewardsConfig)) {
90+
if (!Array.isArray(areas)) continue;
91+
92+
// Check if this steward has i18n area with the target language
93+
for (const area of areas) {
94+
if (typeof area === 'object' && area.i18n) {
95+
const languages = area.i18n;
96+
if (Array.isArray(languages) && languages.includes(stewardsLangCode)) {
97+
stewards.push(`@${username}`);
98+
break;
99+
}
100+
}
101+
}
102+
}
103+
104+
return stewards;
67105
}
68106

69107
class GitHubCommitTracker {
@@ -72,7 +110,14 @@ class GitHubCommitTracker {
72110
this.owner = owner;
73111
this.repo = repo;
74112
this.currentBranch = this.detectCurrentBranch();
75-
this.stewardsConfig = loadStewardsConfig();
113+
this.stewardsConfig = null;
114+
}
115+
116+
117+
static async create(token, owner, repo) {
118+
const instance = new GitHubCommitTracker(token, owner, repo);
119+
instance.stewardsConfig = await loadStewardsConfig();
120+
return instance;
76121
}
77122

78123
/**
@@ -380,7 +425,7 @@ class GitHubCommitTracker {
380425
${outdatedLanguages.length > 0 || missingLanguages.length > 0 ? `**Change Type**: English file was updated. ${outdatedLanguages.length > 0 ? `${outdatedLanguages.map(l => this.getLanguageDisplayName(l.language)).join(', ')} translation${outdatedLanguages.length > 1 ? 's' : ''} may be outdated.` : ''} ${missingLanguages.length > 0 ? `${missingLanguages.map(l => this.getLanguageDisplayName(l.language)).join(', ')} translation${missingLanguages.length > 1 ? 's are' : ' is'} missing.` : ''}` : ''}
381426
382427
---
383-
ℹ️ **Need help?** See our [Translation Guidelines](https://github.com/processing/p5.js-website/blob/main/contributor_docs/translation.md)
428+
ℹ️ **Need help?** See our [Contributor Guidelines](https://p5js.org/contribute/contributor_guidelines/)
384429
385430
🤖 *This issue was auto-generated by the p5.js Translation Tracker*`;
386431
return body;
@@ -574,7 +619,7 @@ async function checkTranslationStatus(changedFiles, githubTracker = null, create
574619
fileTranslations.upToDateLanguages.push(upToDateItem);
575620
}
576621
} else {
577-
// Week 1: Fallback to file modification time comparison
622+
// Fallback to file modification time comparison
578623
const englishModTime = getFileModTime(englishFile);
579624
if (!englishModTime) {
580625
console.log(` ⚠️ Could not get modification time for English file`);
@@ -661,7 +706,7 @@ async function main(testFiles = null, options = {}) {
661706
if (hasToken) {
662707
try {
663708
const [owner, repo] = (process.env.GITHUB_REPOSITORY || 'processing/p5.js-website').split('/');
664-
githubTracker = new GitHubCommitTracker(process.env.GITHUB_TOKEN, owner, repo);
709+
githubTracker = await GitHubCommitTracker.create(process.env.GITHUB_TOKEN, owner, repo);
665710
console.log(`📡 Connected to ${owner}/${repo}`);
666711
} catch (error) {
667712
console.error('❌ GitHub API failed, using file-based tracking');

.github/stewards.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)