diff --git a/.github/actions/translation-tracker/index.js b/.github/actions/translation-tracker/index.js index 220f5deddd..6be6fd5bc0 100644 --- a/.github/actions/translation-tracker/index.js +++ b/.github/actions/translation-tracker/index.js @@ -1,6 +1,7 @@ const { execSync } = require('child_process'); const fs = require('fs'); const path = require('path'); +const https = require('https'); const { Octokit } = require('@octokit/rest'); const yaml = require('js-yaml'); @@ -43,27 +44,64 @@ function getSlugFromEnglishPath(englishFilePath, contentType) { return relative; } -function loadStewardsConfig() { - try { - const stewardsPath = path.join(process.cwd(), '.github', 'stewards.yml'); - if (fs.existsSync(stewardsPath)) { - const stewardsContent = fs.readFileSync(stewardsPath, 'utf8'); - return yaml.load(stewardsContent); - } - } catch (error) { - console.log(`⚠️ Could not load stewards config: ${error.message}`); - } - return null; +async function loadStewardsConfig() { + const STEWARDS_URL = 'https://raw.githubusercontent.com/processing/p5.js/main/stewards.yml'; + + return new Promise((resolve, reject) => { + https.get(STEWARDS_URL, (res) => { + let data = ''; + + res.on('data', (chunk) => { + data += chunk; + }); + + res.on('end', () => { + try { + const config = yaml.load(data); + console.log('Successfully loaded stewards config from p5.js repository'); + resolve(config); + } catch (error) { + console.log(`Could not parse stewards config: ${error.message}`); + resolve(null); + } + }); + }).on('error', (error) => { + console.log(` Could not load stewards config from remote: ${error.message}`); + resolve(null); + }); + }); } function getStewardsForLanguage(stewardsConfig, language) { - if (!stewardsConfig || !stewardsConfig.stewards) return []; + if (!stewardsConfig) return []; - const stewards = stewardsConfig.stewards.filter(s => - s.languages && s.languages.includes(language) - ); + // Map website language codes to stewards.yml language codes + const languageMap = { + 'zh-Hans': 'zh', // Simplified Chinese + 'hi': 'hi', + 'ko': 'ko', + 'es': 'es' + }; + + const stewardsLangCode = languageMap[language] || language; + const stewards = []; - return stewards.map(s => `@${s.github}`); + for (const [username, areas] of Object.entries(stewardsConfig)) { + if (!Array.isArray(areas)) continue; + + // Check if this steward has i18n area with the target language + for (const area of areas) { + if (typeof area === 'object' && area.i18n) { + const languages = area.i18n; + if (Array.isArray(languages) && languages.includes(stewardsLangCode)) { + stewards.push(`@${username}`); + break; + } + } + } + } + + return stewards; } class GitHubCommitTracker { @@ -72,7 +110,14 @@ class GitHubCommitTracker { this.owner = owner; this.repo = repo; this.currentBranch = this.detectCurrentBranch(); - this.stewardsConfig = loadStewardsConfig(); + this.stewardsConfig = null; + } + + + static async create(token, owner, repo) { + const instance = new GitHubCommitTracker(token, owner, repo); + instance.stewardsConfig = await loadStewardsConfig(); + return instance; } /** @@ -380,7 +425,7 @@ class GitHubCommitTracker { ${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.` : ''}` : ''} --- -ℹ️ **Need help?** See our [Translation Guidelines](https://github.com/processing/p5.js-website/blob/main/contributor_docs/translation.md) +ℹ️ **Need help?** See our [Contributor Guidelines](https://p5js.org/contribute/contributor_guidelines/) 🤖 *This issue was auto-generated by the p5.js Translation Tracker*`; return body; @@ -574,7 +619,7 @@ async function checkTranslationStatus(changedFiles, githubTracker = null, create fileTranslations.upToDateLanguages.push(upToDateItem); } } else { - // Week 1: Fallback to file modification time comparison + // Fallback to file modification time comparison const englishModTime = getFileModTime(englishFile); if (!englishModTime) { console.log(` ⚠️ Could not get modification time for English file`); @@ -661,7 +706,7 @@ async function main(testFiles = null, options = {}) { if (hasToken) { try { const [owner, repo] = (process.env.GITHUB_REPOSITORY || 'processing/p5.js-website').split('/'); - githubTracker = new GitHubCommitTracker(process.env.GITHUB_TOKEN, owner, repo); + githubTracker = await GitHubCommitTracker.create(process.env.GITHUB_TOKEN, owner, repo); console.log(`📡 Connected to ${owner}/${repo}`); } catch (error) { console.error('❌ GitHub API failed, using file-based tracking'); diff --git a/.github/stewards.yml b/.github/stewards.yml deleted file mode 100644 index ce5653f10f..0000000000 --- a/.github/stewards.yml +++ /dev/null @@ -1,22 +0,0 @@ -stewards: - - name: Divyansh013 - github: Divyansh013 - languages: - - hi - - name: takshittt - github: takshittt - languages: - - hi - - name: hana-cho - github: hana-cho - languages: - - ko - - name: limzykenneth - github: limzykenneth - languages: - - zh-Hans - - name: lirenjie95 - github: lirenjie95 - languages: - - zh-Hans -