Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 65 additions & 20 deletions .github/actions/translation-tracker/index.js
Original file line number Diff line number Diff line change
@@ -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');

Expand Down Expand Up @@ -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 {
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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`);
Expand Down Expand Up @@ -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');
Expand Down
22 changes: 0 additions & 22 deletions .github/stewards.yml

This file was deleted.