From 7889a1110ac3ff5ecacff6341bb21a29de7a465e Mon Sep 17 00:00:00 2001 From: ZL Asica <40444637+ZL-Asica@users.noreply.github.com> Date: Sun, 27 Oct 2024 23:57:06 -0500 Subject: [PATCH] ci: add color to action. --- .github/workflows/label-pr-based-on-paths.yml | 52 +++++++++++++++---- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/.github/workflows/label-pr-based-on-paths.yml b/.github/workflows/label-pr-based-on-paths.yml index 03309f1..25b8e44 100644 --- a/.github/workflows/label-pr-based-on-paths.yml +++ b/.github/workflows/label-pr-based-on-paths.yml @@ -15,7 +15,7 @@ jobs: - name: Checkout code uses: actions/checkout@v3 - - name: Label PR based on changes + - name: Label PR based on changes with colors uses: actions/github-script@v7 with: script: | @@ -25,30 +25,60 @@ jobs: pull_number: context.issue.number }); + // Define the labels and their colors + const labelsToColor = { + components: '1f77b4', // Blue - Components Related + pages: 'ff7f0e', // Orange - Pages Related + hooks: '2ca02c', // Green - Hooks Related + utils: '9467bd', // Purple - Utils Related + context: 'd62728', // Red - Context Related + assets: 'ffdd57' // Yellow - Assets Related + }; + const labels = new Set(); prFiles.data.forEach(file => { - if (file.filename.startsWith('src/components/common')) { - labels.add('common'); + if (file.filename.startsWith('src/components')) { + labels.add('components'); } - if (file.filename.startsWith('src/components/Profile')) { - labels.add('profile'); + if (file.filename.startsWith('src/pages')) { + labels.add('pages'); } if (file.filename.startsWith('src/hooks')) { labels.add('hooks'); } - if (file.filename.startsWith('src/utils/firebaseConfig.js') || file.filename.startsWith('src/utils/firestore') || file.filename.startsWith('src/utils/auth')) { - labels.add('firebase'); + if (file.filename.startsWith('src/utils') || file.filename.startsWith('src/utils/firebase')) { + labels.add('utils'); } - if (file.filename.startsWith('src/components/Home')) { - labels.add('home'); + if (file.filename.startsWith('src/context')) { + labels.add('context'); } - if (file.filename.startsWith('src/utils/theme')) { - labels.add('theme'); + if (file.filename.startsWith('public') || file.filename.startsWith('src/utils/theme')) { + labels.add('assets'); } }); if (labels.size > 0) { + for (const label of labels) { + try { + // Check if the label exists + await github.rest.issues.getLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + name: label + }); + } catch (error) { + // If label doesn't exist, create it with the specified color + await github.rest.issues.createLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + name: label, + color: labelsToColor[label] || 'b0b0b0', // Use default gray if no color specified + }); + } + } + + // Add labels to the PR await github.rest.issues.addLabels({ owner: context.repo.owner, repo: context.repo.repo,