mirror of
https://github.com/lucide-icons/lucide.git
synced 2025-12-16 14:07:41 +01:00
ci(suggest-tags): Switch to pull_request_target with suggest tags
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
name: Pull request tags suggestions
|
name: Pull request tags suggestions
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request_target:
|
||||||
|
types: [opened, reopened]
|
||||||
paths:
|
paths:
|
||||||
- 'icons/*.json'
|
- 'icons/*.json'
|
||||||
|
|
||||||
@@ -14,7 +15,11 @@ jobs:
|
|||||||
pull-requests: write
|
pull-requests: write
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
# We checkout the main branch of main repository for security reasons.
|
||||||
|
# This is to prevent the workflow from running on a forked repository.
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
repository: lucide-icons/lucide
|
||||||
- uses: pnpm/action-setup@v4
|
- uses: pnpm/action-setup@v4
|
||||||
- uses: actions/setup-node@v4
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
"generate:contributors": "node ./scripts/updateContributors.mts icons/*.svg",
|
"generate:contributors": "node ./scripts/updateContributors.mts icons/*.svg",
|
||||||
"generate:nextJSAliases": "node ./scripts/generateNextJSAliases.mts",
|
"generate:nextJSAliases": "node ./scripts/generateNextJSAliases.mts",
|
||||||
"suggest:tags": "node ./scripts/suggestTags.mts",
|
"suggest:tags": "node ./scripts/suggestTags.mts",
|
||||||
"suggest:tags:watch": "node --watch ./scripts/suggestTags.mts",
|
"suggest:tags:watch": "node --env-file .env --watch ./scripts/suggestTags.mts ",
|
||||||
"postinstall": "husky install",
|
"postinstall": "husky install",
|
||||||
"lint:es": "eslint .",
|
"lint:es": "eslint .",
|
||||||
"lint:format": "prettier \"**/*.{js,mjs,ts,jsx,tsx,html,css,scss,json,yml,yaml}\" --check",
|
"lint:format": "prettier \"**/*.{js,mjs,ts,jsx,tsx,html,css,scss,json,yml,yaml}\" --check",
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
|
|||||||
const pullRequestNumber = Number(process.env.PULL_REQUEST_NUMBER);
|
const pullRequestNumber = Number(process.env.PULL_REQUEST_NUMBER);
|
||||||
const username = process.env.REVIEWER ?? 'github-actions[bot]';
|
const username = process.env.REVIEWER ?? 'github-actions[bot]';
|
||||||
const commitSha = process.env.COMMIT_SHA ?? "HEAD";
|
const commitSha = process.env.COMMIT_SHA ?? "HEAD";
|
||||||
|
const useFileSystem = process.env.USE_FILE_SYSYEM === 'true' || false;
|
||||||
|
|
||||||
const owner = 'lucide-icons';
|
const owner = 'lucide-icons';
|
||||||
const repo = 'lucide';
|
const repo = 'lucide';
|
||||||
@@ -40,10 +41,9 @@ if(hasUserReviews) {
|
|||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const changedFiles = files
|
const changedFiles = files.filter(
|
||||||
.map((file) => file.filename)
|
({filename}) => filename.startsWith('icons/') && filename.includes('.json')
|
||||||
.filter((file) => file.startsWith('icons/') && file.includes('.json'))
|
)
|
||||||
.filter((file, idx, arr) => arr.indexOf(file) === idx);;
|
|
||||||
|
|
||||||
if (changedFiles.length === 0) {
|
if (changedFiles.length === 0) {
|
||||||
console.log('No changed icons found');
|
console.log('No changed icons found');
|
||||||
@@ -54,8 +54,8 @@ const client = new OpenAI({
|
|||||||
apiKey: process.env.OPENAI_API_KEY,
|
apiKey: process.env.OPENAI_API_KEY,
|
||||||
});
|
});
|
||||||
|
|
||||||
const suggestionsByFile = changedFiles.map(async (file) => {
|
const suggestionsByFile = changedFiles.map(async ({ filename, raw_url }) => {
|
||||||
const filePath = file.replace('.json', '');
|
const filePath = filename.replace('.json', '');
|
||||||
const iconName = filePath.split('/').pop();
|
const iconName = filePath.split('/').pop();
|
||||||
|
|
||||||
const input = `Create a list of tags for a \`${iconName}\` icon. Don't include words like: 'icon' and preferably use single words.`;
|
const input = `Create a list of tags for a \`${iconName}\` icon. Don't include words like: 'icon' and preferably use single words.`;
|
||||||
@@ -72,15 +72,26 @@ const suggestionsByFile = changedFiles.map(async (file) => {
|
|||||||
|
|
||||||
console.log(`Suggesting tags for ${iconName}:`, suggestedTags);
|
console.log(`Suggesting tags for ${iconName}:`, suggestedTags);
|
||||||
|
|
||||||
// const currentContent = require(`../${filePath}`);
|
let fileContent: string
|
||||||
const jsonFile = path.join(process.cwd(), file);
|
|
||||||
const currentFileContent = await fs.readFile(jsonFile, 'utf-8') as unknown as string;
|
|
||||||
const metaData = JSON.parse(currentFileContent);
|
|
||||||
|
|
||||||
console.log(`Current tags for ${iconName}:`, metaData.tags || []);
|
if( useFileSystem ) {
|
||||||
|
const jsonFile = path.join(process.cwd(), filename);
|
||||||
|
fileContent = await fs.readFile(jsonFile, 'utf-8') as unknown as string;
|
||||||
|
} else {
|
||||||
|
const fileGithubRequest = await octokit.request(`GET ${raw_url}`, {
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/vnd.github.v3.raw',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
fileContent = fileGithubRequest.data
|
||||||
|
}
|
||||||
|
|
||||||
|
const metadata = JSON.parse(fileContent)
|
||||||
|
|
||||||
|
console.log(`Current tags for ${iconName}:`, metadata.tags || []);
|
||||||
|
|
||||||
const tagSuggestionsWithoutDuplicates = suggestedTags.filter((tag) => {
|
const tagSuggestionsWithoutDuplicates = suggestedTags.filter((tag) => {
|
||||||
return !metaData.tags?.includes(tag) && tag !== iconName;
|
return !metadata.tags?.includes(tag) && tag !== iconName;
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`Tag suggestions for ${iconName} without duplicates:`, tagSuggestionsWithoutDuplicates);
|
console.log(`Tag suggestions for ${iconName} without duplicates:`, tagSuggestionsWithoutDuplicates);
|
||||||
@@ -90,7 +101,7 @@ const suggestionsByFile = changedFiles.map(async (file) => {
|
|||||||
return Promise.resolve(null);
|
return Promise.resolve(null);
|
||||||
}
|
}
|
||||||
// Find the startLine in the json file
|
// Find the startLine in the json file
|
||||||
const startLine = currentFileContent.split('\n').findIndex((line) => line.includes('"tags":')) + 1;
|
const startLine = fileContent.split('\n').findIndex((line) => line.includes('"tags":')) + 1;
|
||||||
|
|
||||||
const codeSuggestion = tagSuggestionsWithoutDuplicates.map((tag) => ` "${tag}"`).join(',\n');
|
const codeSuggestion = tagSuggestionsWithoutDuplicates.map((tag) => ` "${tag}"`).join(',\n');
|
||||||
|
|
||||||
@@ -100,7 +111,7 @@ Here are the suggestions:
|
|||||||
\`\`\`suggestion\n "tags": [\n${codeSuggestion},`;
|
\`\`\`suggestion\n "tags": [\n${codeSuggestion},`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
path: file,
|
path: filename,
|
||||||
line: startLine,
|
line: startLine,
|
||||||
body: message,
|
body: message,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user