From e43417921091ad6f50a5cd7a60d21bc7ca8c532a Mon Sep 17 00:00:00 2001 From: "Ignacio Ceballos (Yayo)" Date: Wed, 16 Oct 2024 18:23:44 +0200 Subject: [PATCH 1/7] action for branch table --- .github/branch-table/branch-table.py | 152 +++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 .github/branch-table/branch-table.py diff --git a/.github/branch-table/branch-table.py b/.github/branch-table/branch-table.py new file mode 100644 index 0000000000..a8c16e7427 --- /dev/null +++ b/.github/branch-table/branch-table.py @@ -0,0 +1,152 @@ +import requests +import pandas as pd +import os + +# Función para obtener la información de un archivo de Figma, utilizando el parámetro branch_data=true +def get_figma_file_data(file_key, figma_token): + headers = { + "X-Figma-Token": figma_token + } + url = f"https://api.figma.com/v1/files/{file_key}?branch_data=true" + response = requests.get(url, headers=headers, verify=True) # Desactivar verificación SSL + + if response.status_code == 200: + return response.json() + else: + print(f"Error fetching data for file {file_key}: {response.status_code}") + return None + +# Función para procesar los archivos y generar una tabla con la información deseada +def analyze_files(file_keys, figma_token): + table_data = [] + + for file_key in file_keys: + file_data = get_figma_file_data(file_key, figma_token) + + if file_data: + file_name = file_data.get("name", "Unknown") + branches = file_data.get("branches", []) + num_branches = len(branches) + + # Solo agregamos el archivo si tiene ramas + if num_branches > 0: + # Crear enlaces para cada rama, en formato de lista Markdown + branch_links = [f"- [{branch['name']}](https://www.figma.com/file/{file_key}/branch/{branch['key']})" + for branch in branches] + + branch_links_str = "\n".join(branch_links) + + table_data.append({ + "File Name": file_name, + "Branches": num_branches, + "Branch Names": branch_links_str + }) + + # Crear un DataFrame con la información recopilada + df = pd.DataFrame(table_data) + return df + +# Función para actualizar la issue en GitHub +def update_github_issue(issue_number, repo_owner, repo_name, markdown_content, github_token): + url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/issues/{issue_number}" + headers = { + "Authorization": f"token {github_token}", + "Accept": "application/vnd.github.v3+json" + } + data = { + "body": markdown_content + } + + response = requests.patch(url, json=data, headers=headers) + + if response.status_code == 200: + print("Issue updated successfully") + else: + print(f"Failed to update issue: {response.status_code} - {response.text}") + + +# Lista de keys de los archivos de Figma a analizar +file_keys = [ + "WCkDDzlXE16R6yXaljxddj", + "DSWhPLyJzbliP1fBrLxDUR", + "w7fBxCsEb8WrMVVuxDnCQd", + "JHuzksh01yxExMeMQBvymq", + "ObNHOLPtrIytjy9BH7M9jW", + "m8srmP3eedfvDaqYnbM6PI", + "19IXMaFqdYeC1IIdTwXBgY", + "czemeClWRGBI8oF7caNa5m", + "CjvgrHEIycSQ6exznxnFXT", + "EApRpjaTyUOwW5VQU2ZqgP", + "JXy7Y07eb0Axg0ThVRWKju", + "jWWCJ9kYl6I5uHLz3GcgRp", + "KDxPjcTXq2NCvQZjb4FXgi", + "U4ipIXOk64bdM5tSvaqPKS", + "gUZfZajV9Zfade0rBYWZQg", + "BctaFHf0PVPX2uwRSl8taf", + "koROdh3HpEPG2O8jG52Emh", + "LzhzNPzE8nY9d7Yvo10d5d", + "tKdPOfcUALzVIh5oizFbm7", + "hxJvuIQQ1xf50xIOQFUZbQ", + "6IN1rHqpYLILjgWMuUGKvJ", + "512a5Ke4EldL0GYffCXGCJ", + "LhZ5g2KAckJLzBIA1720H0", + "XiGe8xqm5OOjUSmdhU4rzA", + "DAXzyfp6gf7G9SUsnKgTzJ", + "LpjgnU1xpmEzQvlXKwAHmn", + "Xm3r8nRNlbAiZNlkaH5YX1", + "M8t65SWdTUyM44YjxuzCyu", + "3iEvVzfHBtg3sROXBHzkn7", + "e8d3PkXitUJ1Jwgc9Y3mNc", + "ncQ4GRI3ZEjEtNW6pyROX2", + "Be8QB9onmHunKCCAkIBAVr", + "KYdCKU8obcDapI8ihpsaWs", + "YYWgtxCOpR87Nq5SbSzI8k", + "a1pgrI7Wg41iyXWU8ETqlU", + "8TXIyWTJ8plJ06i1qwv97k", + "4GmsXwcMOapuCa0Atm6E84", + "Os5UfsnhLtQ9rnzmtcX8J4", + "gmcy7hwB9WXxqT05jBnA3W", + "3IO1EsGDeBRiFdF23mrvuj", + "RkHDrAELuQIlwNSQBfjSBx", + "lqCbeKPfXwOWxSFGOO4bY4", + "nxToAYk7FGC86TS0mY61TU", + "w7E0mmB92eio0zHw7h9iS2", + "UZHm7V3gO7nVnbf1b0Vj7b", + "yCHLIfy4WMfRdlADwyL4kZ", + "O3uLKJQ1MNsMFXYqmyPTn8", + "3ME86VKaAQ2BoeqoQuHMYx", + "YIQIeK0R4bQNNkw2Friv6b", + "J0LzwXn0tzGNIkgvFnt0Yz", + "WtF16bfvE9kKS4yx3VtLuE", + "tOb2OmRf6gnEK3fnSWPKOG", + "wseConngNv2MYEXgCk5uI4", + "f9tAOJproMIiJJuPchDEhG", + "81rPCqGchGf54aoh2kpF1o", + "MU9VZyeyzTSDPLWmZMGYkK", + "yQRVCOmRQNM98bnXndLPxK", + "5xDoAS5UTtTPMP8zDsxiMt", + "il3GkMh7p85wpXvtWuvLRT", + "InXkFcu9cBzKmMjZtKXSy7", + "dvMqeg6s8tDh9Hyxu7IYDl", + "aNHyvXe1mqjaelE8XWVQD5", + "pzcfoIj4osTMiOHoChiCFm", + "PApssATUkePZnIOB4GmAeI", + # Agrega aquí más keys de archivos +] + +# Token de acceso personal a la API de Figma y GitHub +figma_token = os.getenv("FIGMA_TOKEN") +github_token = os.getenv("GITHUB_TOKEN") + +# Analizar los archivos y generar la tabla +df = analyze_files(file_keys, figma_token) + +# Convertir la tabla a formato markdown +markdown_table = df.to_markdown(index=False) + +# Actualizar la issue en GitHub +repo_owner = "Telefonica" +repo_name = "mistica-design" +issue_number = 1927 # Cambia este número por el número de la issue que quieras actualizar + +update_github_issue(issue_number, repo_owner, repo_name, markdown_table, github_token) \ No newline at end of file From c9d72c74b1bf1e1fad30bc97b22b1b9ed7097a4c Mon Sep 17 00:00:00 2001 From: "Ignacio Ceballos (Yayo)" Date: Wed, 16 Oct 2024 18:23:53 +0200 Subject: [PATCH 2/7] cleaning old workflows --- .github/workflows/archived/auto-release.yml | 27 ---- .../archived/issue-task-reminder.yml | 17 -- .github/workflows/archived/jira-issues.yml | 23 --- .../archived/new-component-notification.yml | 22 --- .../workflows/archived/new-issue-label.yml | 17 -- .github/workflows/archived/send-files.yml | 40 ----- .github/workflows/archived/sendBrands.yml | 31 ---- .github/workflows/archived/sendComponents.yml | 27 ---- .github/workflows/archived/sendFiles.yml | 71 -------- .github/workflows/dashboard.yml | 153 ------------------ .github/workflows/open-branches.yml | 31 ++++ 11 files changed, 31 insertions(+), 428 deletions(-) delete mode 100644 .github/workflows/archived/auto-release.yml delete mode 100644 .github/workflows/archived/issue-task-reminder.yml delete mode 100644 .github/workflows/archived/jira-issues.yml delete mode 100644 .github/workflows/archived/new-component-notification.yml delete mode 100644 .github/workflows/archived/new-issue-label.yml delete mode 100644 .github/workflows/archived/send-files.yml delete mode 100644 .github/workflows/archived/sendBrands.yml delete mode 100644 .github/workflows/archived/sendComponents.yml delete mode 100644 .github/workflows/archived/sendFiles.yml delete mode 100644 .github/workflows/dashboard.yml create mode 100644 .github/workflows/open-branches.yml diff --git a/.github/workflows/archived/auto-release.yml b/.github/workflows/archived/auto-release.yml deleted file mode 100644 index fe20c825d9..0000000000 --- a/.github/workflows/archived/auto-release.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: "Release" - -on: - push: - branches: - - "production" - -jobs: - pre-release: - name: "Release" - runs-on: "ubuntu-latest" - - steps: - # ... - - name: "Build & test" - run: | - echo "done!" - - - uses: "marvinpinto/action-automatic-releases@latest" - with: - repo_token: "${{ secrets.GITHUB_TOKEN }}" - automatic_release_tag: "${{github.event.commits[0].message}}" - prerelease: false - title: "${{github.event.commits[0].message}}" - files: | - LICENSE.txt - *.jar diff --git a/.github/workflows/archived/issue-task-reminder.yml b/.github/workflows/archived/issue-task-reminder.yml deleted file mode 100644 index f642cca084..0000000000 --- a/.github/workflows/archived/issue-task-reminder.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: Pending task notification - -on: - workflow_dispatch: - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: allanwsilva/check-pending-tasks@v1.0.0 - with: - sendgrid-from-email: ignacio.ceballostorres@telefonica.com - email-subject: "Check out these Github tasks assigned to you that are still pending" - env: - GITHUB_TOKEN: ${{ secrets.NOVUM_PRIVATE_REPOS }} - SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }} diff --git a/.github/workflows/archived/jira-issues.yml b/.github/workflows/archived/jira-issues.yml deleted file mode 100644 index 5b520281e3..0000000000 --- a/.github/workflows/archived/jira-issues.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Jira Sync - -on: - issues: - types: [opened, labeled, unlabeled] - issue_comment: - types: [created] - -jobs: - sync: - name: Sync Items - runs-on: ubuntu-latest - steps: - - name: Sync - uses: mheap/github-action-issue-to-jira@v1 - env: - GITHUB_TOKEN: ${{ secrets.PERSONAL_TOKEN }} - with: - jiraHost: ${{ secrets.JIRA_HOST }} - jiraUsername: ${{ secrets.JIRA_USERNAME }} - jiraPassword: ${{ secrets.JIRA_PASSWORD }} # See https://id.atlassian.com/manage/api-tokens - project: DSNCORE - assignee: ${{ secrets.JIRA_USERNAME }} diff --git a/.github/workflows/archived/new-component-notification.yml b/.github/workflows/archived/new-component-notification.yml deleted file mode 100644 index ba9e793827..0000000000 --- a/.github/workflows/archived/new-component-notification.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: New component request notification - -on: - issues: - types: [labeled] - -jobs: - build: - # runs-on: [self-hosted, Linux] - runs-on: ubuntu-latest - if: (github.event.label.name == '✨ Component request') || (github.event.label.name == '✨ Component request') - - steps: - - uses: actions/checkout@v2 - - uses: timheuer/issue-notifier@v1 - env: - SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }} - with: - fromMailAddress: 'ignacio.ceballostorres@telefonica.com' - toMailAddress: 'yceballost@gmail.com' - subject: 'A new component request!' - labelsToMonitor: '✨ Component request' diff --git a/.github/workflows/archived/new-issue-label.yml b/.github/workflows/archived/new-issue-label.yml deleted file mode 100644 index 8b216aef7a..0000000000 --- a/.github/workflows/archived/new-issue-label.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: Bug reported - -on: - workflow_dispatch: - issues: - types: [labeled] - -jobs: - Move_Labeled_Issue_On_Project_Board: - runs-on: ubuntu-latest - steps: - - uses: konradpabjan/move-labeled-or-milestoned-issue@v2.0 - with: - action-token: "${{ secrets.PERSONAL_TOKEN }}" - project-url: "https://github.com/Telefonica/mistica-design/projects/2" - column-name: "Bugs reported" - label-name: "bug 🐞" diff --git a/.github/workflows/archived/send-files.yml b/.github/workflows/archived/send-files.yml deleted file mode 100644 index 5076786e25..0000000000 --- a/.github/workflows/archived/send-files.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Cloning libraries to mistica-sketch-libraries - -on: - push: - branches: - - production - paths: - - 'libs/**' - # - '.github/workflows/sendFiles.yml' - -jobs: - send-files: - # runs-on: [self-hosted, Linux] - runs-on: ubuntu-latest - steps: - # comando solo para Self-Hosted machines - # - run: sudo chown -R $USER:$USER /home/pi/actions-github/mistica-design-libraries/_work/ - - - name: Cleanup - run: | - sudo chown -R $USER:$USER $GITHUB_WORKSPACE - - # Checkout para self-hosted Telefonica - - uses: actions/checkout@v2 - - - name: Get branch name - uses: rlespinasse/github-slug-action@v3.x - - - name: Copy Brands to ${{ env.GITHUB_REF_SLUG_URL }} - uses: andstor/copycat-action@v3.2.3 - with: - personal_token: ${{ secrets.PERSONAL_TOKEN }} - src_branch: ${{ env.GITHUB_REF_SLUG_URL }} - src_path: libs/. - dst_branch: ${{ env.GITHUB_REF_SLUG_URL }} - dst_path: libraries/. - dst_owner: yceballost - dst_repo_name: mistica-sketch-libraries - commit_message: Libs uploaded to ${{ env.GITHUB_REF_SLUG_URL }} - clean: true \ No newline at end of file diff --git a/.github/workflows/archived/sendBrands.yml b/.github/workflows/archived/sendBrands.yml deleted file mode 100644 index 2709b9cefa..0000000000 --- a/.github/workflows/archived/sendBrands.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Cloning brands to mistica-sketch-libraries - -on: - schedule: - - cron: "03 03 * * *" - -jobs: - copy: - runs-on: self-hosted - steps: - - - name: Sleep for 90 seconds - uses: jakejarvis/wait-action@master - with: - time: '90s' - - - name: Get branch name - uses: rlespinasse/github-slug-action@v2.x - - - name: Copy Brands (${{ env.GITHUB_REF_SLUG_URL }}) - uses: andstor/copycat-action@v3 - with: - personal_token: ${{ secrets.PERSONAL_TOKEN }} - src_branch: ${{ env.GITHUB_REF_SLUG_URL }} - src_path: /Brand Libraries/. - dst_branch: ${{ env.GITHUB_REF_SLUG_URL }} - dst_path: /BrandLibraries/. - dst_owner: yceballost - dst_repo_name: mistica-sketch-libraries - commit_message: Brands uploaded - clean: true diff --git a/.github/workflows/archived/sendComponents.yml b/.github/workflows/archived/sendComponents.yml deleted file mode 100644 index 9b36785c66..0000000000 --- a/.github/workflows/archived/sendComponents.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Cloning folder libraries to mistica-sketch-libraries — PRODUCTION - -on: - push: - schedule: - - cron: "03 03 * * *" - -jobs: - copy: - runs-on: self-hosted - steps: - - - name: Get branch name - uses: rlespinasse/github-slug-action@v2.x - - - name: Copy Components (${{ env.GITHUB_REF_SLUG_URL }}) - uses: andstor/copycat-action@v3 - with: - personal_token: ${{ secrets.PERSONAL_TOKEN }} - src_branch: ${{ env.GITHUB_REF_SLUG_URL }} - src_path: /Component Libraries/. - dst_branch: ${{ env.GITHUB_REF_SLUG_URL }} - dst_path: /ComponentLibraries/. - dst_owner: yceballost - dst_repo_name: mistica-sketch-libraries - commit_message: Components uploaded - clean: true diff --git a/.github/workflows/archived/sendFiles.yml b/.github/workflows/archived/sendFiles.yml deleted file mode 100644 index a7e8889698..0000000000 --- a/.github/workflows/archived/sendFiles.yml +++ /dev/null @@ -1,71 +0,0 @@ -name: Cloning libraries to mistica-sketch-libraries - -on: - push: - branches: - - production - -jobs: - # generator: - # runs-on: [self-hosted, macOS] - # steps: - - # - uses: actions/checkout@v2 - - # - name: Inject slug/short variables - # uses: rlespinasse/github-slug-action@v3.x - - # - run: npm install --global kactus-cli --force - - # - name: convert folder to sketch file - # run: | - # kactus import libs/Movistar - # kactus import libs/O2 - # kactus import libs/ClassicO2 - # kactus import libs/Vivo - # kactus import libs/Telefonica - # kactus import libs/Mistica\ iOS - # kactus import libs/Mistica\ Android - - # # - name: stage changed files - # # run: git add -f . - - # # - name: config - # # run: | - # # git config --global user.name "🤖GeneratorBot" - # # git config --global user.email "users.noreply.github.com" - - # # - name: commit changed files - # # run: git commit -m "sketch generated and folders removed" - - # # - name: push code to ${{ env.GITHUB_REF_SLUG_URL }} - # # run: git push origin HEAD:${{ env.GITHUB_REF_SLUG_URL }} - - send-files: - # needs: generator - runs-on: [self-hosted, Linux] - steps: - # comando solo para Self-Hosted machines - # - run: sudo chown -R $USER:$USER /home/pi/actions-github/mistica-design-libraries/_work/ - - - name: Get branch name - uses: rlespinasse/github-slug-action@v2.x - - - name: Copy Brands to ${{ env.GITHUB_REF_SLUG_URL }} - uses: andstor/copycat-action@v3.2.3 - with: - personal_token: ${{ secrets.PERSONAL_TOKEN }} - src_branch: ${{ env.GITHUB_REF_SLUG_URL }} - src_path: libs/. - dst_branch: ${{ env.GITHUB_REF_SLUG_URL }} - dst_path: libraries/. - dst_owner: yceballost - dst_repo_name: mistica-sketch-libraries - commit_message: Libs uploaded to ${{ env.GITHUB_REF_SLUG_URL }} - clean: true - - # - name: removed sketch force - # run: | - # git rm *.sketch - # git commit -m "sketch removed" - # git push origin HEAD:${{ env.GITHUB_REF_SLUG_URL }} diff --git a/.github/workflows/dashboard.yml b/.github/workflows/dashboard.yml deleted file mode 100644 index 63e52c47e8..0000000000 --- a/.github/workflows/dashboard.yml +++ /dev/null @@ -1,153 +0,0 @@ -name: Build Dashboard - -on: - # push: - # paths: - # - ".github/workflows/dashboard.yml" - # issues: - # types: [opened, closed, reopened] - -jobs: - build-dashboard: - runs-on: ubuntu-latest - - steps: - - name: Cleanup - run: | - sudo chown -R $USER:$USER $GITHUB_WORKSPACE - - - name: Check out repository - uses: actions/checkout@v2 - - name: Check out GitHub Pages branch - uses: actions/checkout@v2 - with: - ref: "gh-pages" - path: "./dashboard" - - - name: "Generate Dashboard" - uses: ethomson/issue-dashboard@v1 - with: - config: | - output: - format: html - filename: 'dashboard/index.html' - - sections: - - title: 'Open Issues by Type' - description: 'Queries of issues by type, using their label.' - widgets: - - type: 'number' - title: 'New components' - issue_query: 'repo:Telefonica/mistica-design is:open is:issue label:"New component 🔸"' - color: 'tertiary' - - type: 'number' - title: 'Component requests' - issue_query: 'repo:Telefonica/mistica-design is:open is:issue label:"request ✨"' - color: 'primary' - - type: 'number' - title: 'Bugs' - issue_query: 'repo:Telefonica/mistica-design is:open is:issue label:"bug 🐞"' - color: 'secondary' - - type: 'table' - title: 'New components list' - fields: - - title: 'Issue' - property: 'number' - - title: 'Date' - value: '{{ date(item.created_date) }}' - - title: 'Title' - property: 'title' - issue_query: 'repo:Telefonica/mistica-design is:open is:issue label:"New component 🔸"' - limit: 15 - - type: 'table' - title: 'Component request list' - fields: - - title: 'Issue' - property: 'number' - - title: 'Date' - value: '{{ date(item.created_date) }}' - - title: 'Title' - property: 'title' - issue_query: 'repo:Telefonica/mistica-design is:open is:issue label:"request ✨"' - limit: 15 - - type: 'table' - title: 'Bugs list' - fields: - - title: 'Issue' - property: 'number' - - title: 'Date' - value: '{{ date(item.created_date) }}' - - title: 'Title' - property: 'title' - issue_query: 'repo:Telefonica/mistica-design is:open is:issue label:"bug 🐞"' - limit: 15 - - - title: 'Open Issues by Age' - description: 'Queries of open issues by their creation date.' - widgets: - - type: 'graph' - title: 'Age' - elements: - - title: '7 days' - issue_query: 'repo:Telefonica/mistica-design is:open is:issue created:>{{ date("-7 days") }}' - color: 'primary' - - title: '15 days' - issue_query: 'repo:Telefonica/mistica-design is:open is:issue created:>{{ date("-15 days") }}' - color: 'primary' - - title: '30 days' - issue_query: 'repo:Telefonica/mistica-design is:open is:issue created:{{ date("-30 days") }}..{{ date("-7 days") }}' - color: 'primary' - - title: '90 days' - issue_query: 'repo:Telefonica/mistica-design is:open is:issue created:{{ date("-90 days") }}..{{ date("-30 days") }}' - - title: '180 days' - issue_query: 'repo:Telefonica/mistica-design is:open is:issue created:{{ date("-180 days") }}..{{ date("-60 days") }}' - - - - title: 'Pull Requests' - widgets: - - type: 'number' - title: 'Opened' - issue_query: 'repo:Telefonica/mistica-design is:open is:pr review:none' - color: 'secondary' - - type: 'table' - title: 'Open Pull Requests' - fields: - - title: 'Issue' - property: 'number' - - title: 'Date' - value: '{{ date(item.created_date) }}' - - title: 'Title' - property: 'title' - issue_query: 'repo:Telefonica/mistica-design is:open is:pr review:none sort:created-asc' - limit: 15 - token: ${{ github.token }} - - - name: "Generate bugs" - uses: ethomson/issue-dashboard@v1 - with: - config: | - output: - format: html - filename: 'dashboard/bugs.html' - - sections: - - title: 'Test' - widgets: - - type: 'number' - title: 'Bug' - issue_query: 'repo:Telefonica/mistica-design is:open is:issue label:"bug 🐞"' - color: 'primary' - - type: 'number' - title: 'Component Requests' - issue_query: 'repo:Telefonica/mistica-design is:open is:issue label:"request ✨"' - color: 'secondary' - token: ${{ github.token }} - - - name: Publish Documentation - run: | - git add . - git config user.name 'Dashboard User' - git config user.email 'nobody@nowhere' - git commit -m 'Documentation update' --allow-empty - git push origin gh-pages - working-directory: dashboard diff --git a/.github/workflows/open-branches.yml b/.github/workflows/open-branches.yml new file mode 100644 index 0000000000..131c6a9836 --- /dev/null +++ b/.github/workflows/open-branches.yml @@ -0,0 +1,31 @@ +name: Open branches in Figma + +on: + workflow_dispatch: + schedule: + - cron: 30 8 * * MON-FRI + +jobs: + sync-figma-brand: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: "3.x" + + # Paso 3: Instalar dependencias de Python + - name: Install dependencies + run: | + pip install requests pandas + + - name: Run sync for the brand(s) + env: + FIGMA_TOKEN: ${{ secrets.FIGMA_TOKEN }} + GITHUB_TOKEN: ${{ secrets.NOVUM_PRIVATE_REPOS }} + working-directory: .github/branch-table + run: python3 branch-table.py From 367c687b6724b18c7074da0cd9f603764010404a Mon Sep 17 00:00:00 2001 From: "Ignacio Ceballos (Yayo)" Date: Wed, 16 Oct 2024 18:28:50 +0200 Subject: [PATCH 3/7] translate comments --- .github/branch-table/branch-table.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/branch-table/branch-table.py b/.github/branch-table/branch-table.py index a8c16e7427..5b36be1d2a 100644 --- a/.github/branch-table/branch-table.py +++ b/.github/branch-table/branch-table.py @@ -2,13 +2,13 @@ import pandas as pd import os -# Función para obtener la información de un archivo de Figma, utilizando el parámetro branch_data=true +# Function to get information from a Figma file, using the branch_data=true parameter def get_figma_file_data(file_key, figma_token): headers = { "X-Figma-Token": figma_token } url = f"https://api.figma.com/v1/files/{file_key}?branch_data=true" - response = requests.get(url, headers=headers, verify=True) # Desactivar verificación SSL + response = requests.get(url, headers=headers, verify=True) if response.status_code == 200: return response.json() @@ -16,7 +16,7 @@ def get_figma_file_data(file_key, figma_token): print(f"Error fetching data for file {file_key}: {response.status_code}") return None -# Función para procesar los archivos y generar una tabla con la información deseada +# Function to process files and generate a table with the desired information def analyze_files(file_keys, figma_token): table_data = [] @@ -28,9 +28,9 @@ def analyze_files(file_keys, figma_token): branches = file_data.get("branches", []) num_branches = len(branches) - # Solo agregamos el archivo si tiene ramas + # Only add the file if it has branches if num_branches > 0: - # Crear enlaces para cada rama, en formato de lista Markdown + # Create links for each branch, in Markdown list format branch_links = [f"- [{branch['name']}](https://www.figma.com/file/{file_key}/branch/{branch['key']})" for branch in branches] @@ -42,11 +42,11 @@ def analyze_files(file_keys, figma_token): "Branch Names": branch_links_str }) - # Crear un DataFrame con la información recopilada + # Create a DataFrame with the collected information df = pd.DataFrame(table_data) return df -# Función para actualizar la issue en GitHub +# Function to update the issue on GitHub def update_github_issue(issue_number, repo_owner, repo_name, markdown_content, github_token): url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/issues/{issue_number}" headers = { @@ -65,7 +65,7 @@ def update_github_issue(issue_number, repo_owner, repo_name, markdown_content, g print(f"Failed to update issue: {response.status_code} - {response.text}") -# Lista de keys de los archivos de Figma a analizar +# List of Figma file keys to analyze file_keys = [ "WCkDDzlXE16R6yXaljxddj", "DSWhPLyJzbliP1fBrLxDUR", @@ -131,22 +131,22 @@ def update_github_issue(issue_number, repo_owner, repo_name, markdown_content, g "aNHyvXe1mqjaelE8XWVQD5", "pzcfoIj4osTMiOHoChiCFm", "PApssATUkePZnIOB4GmAeI", - # Agrega aquí más keys de archivos + # Add more file keys here ] -# Token de acceso personal a la API de Figma y GitHub +# Personal access token for Figma and GitHub APIs figma_token = os.getenv("FIGMA_TOKEN") github_token = os.getenv("GITHUB_TOKEN") -# Analizar los archivos y generar la tabla +# Analyze the files and generate the table df = analyze_files(file_keys, figma_token) -# Convertir la tabla a formato markdown +# Convert the table to markdown format markdown_table = df.to_markdown(index=False) -# Actualizar la issue en GitHub +# Update the issue on GitHub repo_owner = "Telefonica" repo_name = "mistica-design" -issue_number = 1927 # Cambia este número por el número de la issue que quieras actualizar +issue_number = 1927 # Change this number to the issue number you want to update update_github_issue(issue_number, repo_owner, repo_name, markdown_table, github_token) \ No newline at end of file From c48cea26e36a9add24a1331381f8d01e117f3d0e Mon Sep 17 00:00:00 2001 From: "Ignacio Ceballos (Yayo)" Date: Wed, 16 Oct 2024 19:14:30 +0200 Subject: [PATCH 4/7] get files from projects --- .github/branch-table/branch-table.py | 108 +++++++++------------------ 1 file changed, 36 insertions(+), 72 deletions(-) diff --git a/.github/branch-table/branch-table.py b/.github/branch-table/branch-table.py index 5b36be1d2a..ee968c0cb2 100644 --- a/.github/branch-table/branch-table.py +++ b/.github/branch-table/branch-table.py @@ -2,13 +2,34 @@ import pandas as pd import os +# Function to get the files from specific Figma projects +def get_figma_project_files(project_ids, figma_token): + headers = { + "X-Figma-Token": figma_token + } + file_keys = [] + + for project_id in project_ids: + print(f"Fetching files for project ID: {project_id}") + project_files_url = f"https://api.figma.com/v1/projects/{project_id}/files" + files_response = requests.get(project_files_url, headers=headers) + + if files_response.status_code == 200: + files = files_response.json().get("files", []) + for file in files: + file_keys.append(file["key"]) + else: + print(f"Error fetching files for project {project_id}: {files_response.status_code}") + + return file_keys + # Function to get information from a Figma file, using the branch_data=true parameter def get_figma_file_data(file_key, figma_token): headers = { "X-Figma-Token": figma_token } url = f"https://api.figma.com/v1/files/{file_key}?branch_data=true" - response = requests.get(url, headers=headers, verify=True) + response = requests.get(url, headers=headers, verify=False) if response.status_code == 200: return response.json() @@ -63,81 +84,24 @@ def update_github_issue(issue_number, repo_owner, repo_name, markdown_content, g print("Issue updated successfully") else: print(f"Failed to update issue: {response.status_code} - {response.text}") - - -# List of Figma file keys to analyze -file_keys = [ - "WCkDDzlXE16R6yXaljxddj", - "DSWhPLyJzbliP1fBrLxDUR", - "w7fBxCsEb8WrMVVuxDnCQd", - "JHuzksh01yxExMeMQBvymq", - "ObNHOLPtrIytjy9BH7M9jW", - "m8srmP3eedfvDaqYnbM6PI", - "19IXMaFqdYeC1IIdTwXBgY", - "czemeClWRGBI8oF7caNa5m", - "CjvgrHEIycSQ6exznxnFXT", - "EApRpjaTyUOwW5VQU2ZqgP", - "JXy7Y07eb0Axg0ThVRWKju", - "jWWCJ9kYl6I5uHLz3GcgRp", - "KDxPjcTXq2NCvQZjb4FXgi", - "U4ipIXOk64bdM5tSvaqPKS", - "gUZfZajV9Zfade0rBYWZQg", - "BctaFHf0PVPX2uwRSl8taf", - "koROdh3HpEPG2O8jG52Emh", - "LzhzNPzE8nY9d7Yvo10d5d", - "tKdPOfcUALzVIh5oizFbm7", - "hxJvuIQQ1xf50xIOQFUZbQ", - "6IN1rHqpYLILjgWMuUGKvJ", - "512a5Ke4EldL0GYffCXGCJ", - "LhZ5g2KAckJLzBIA1720H0", - "XiGe8xqm5OOjUSmdhU4rzA", - "DAXzyfp6gf7G9SUsnKgTzJ", - "LpjgnU1xpmEzQvlXKwAHmn", - "Xm3r8nRNlbAiZNlkaH5YX1", - "M8t65SWdTUyM44YjxuzCyu", - "3iEvVzfHBtg3sROXBHzkn7", - "e8d3PkXitUJ1Jwgc9Y3mNc", - "ncQ4GRI3ZEjEtNW6pyROX2", - "Be8QB9onmHunKCCAkIBAVr", - "KYdCKU8obcDapI8ihpsaWs", - "YYWgtxCOpR87Nq5SbSzI8k", - "a1pgrI7Wg41iyXWU8ETqlU", - "8TXIyWTJ8plJ06i1qwv97k", - "4GmsXwcMOapuCa0Atm6E84", - "Os5UfsnhLtQ9rnzmtcX8J4", - "gmcy7hwB9WXxqT05jBnA3W", - "3IO1EsGDeBRiFdF23mrvuj", - "RkHDrAELuQIlwNSQBfjSBx", - "lqCbeKPfXwOWxSFGOO4bY4", - "nxToAYk7FGC86TS0mY61TU", - "w7E0mmB92eio0zHw7h9iS2", - "UZHm7V3gO7nVnbf1b0Vj7b", - "yCHLIfy4WMfRdlADwyL4kZ", - "O3uLKJQ1MNsMFXYqmyPTn8", - "3ME86VKaAQ2BoeqoQuHMYx", - "YIQIeK0R4bQNNkw2Friv6b", - "J0LzwXn0tzGNIkgvFnt0Yz", - "WtF16bfvE9kKS4yx3VtLuE", - "tOb2OmRf6gnEK3fnSWPKOG", - "wseConngNv2MYEXgCk5uI4", - "f9tAOJproMIiJJuPchDEhG", - "81rPCqGchGf54aoh2kpF1o", - "MU9VZyeyzTSDPLWmZMGYkK", - "yQRVCOmRQNM98bnXndLPxK", - "5xDoAS5UTtTPMP8zDsxiMt", - "il3GkMh7p85wpXvtWuvLRT", - "InXkFcu9cBzKmMjZtKXSy7", - "dvMqeg6s8tDh9Hyxu7IYDl", - "aNHyvXe1mqjaelE8XWVQD5", - "pzcfoIj4osTMiOHoChiCFm", - "PApssATUkePZnIOB4GmAeI", - # Add more file keys here -] # Personal access token for Figma and GitHub APIs figma_token = os.getenv("FIGMA_TOKEN") github_token = os.getenv("GITHUB_TOKEN") +# List of project IDs to fetch files from +project_ids = [ + "25719143", # Mística Libraries + "266390224", # Mística Skins Libraries + "27955986", # Specs + "170790970", # Community Specs + "30110755", # Materials + # Add more project id here +] + +# Fetch all file keys from the specified Figma projects +file_keys = get_figma_project_files(project_ids, figma_token) + # Analyze the files and generate the table df = analyze_files(file_keys, figma_token) @@ -149,4 +113,4 @@ def update_github_issue(issue_number, repo_owner, repo_name, markdown_content, g repo_name = "mistica-design" issue_number = 1927 # Change this number to the issue number you want to update -update_github_issue(issue_number, repo_owner, repo_name, markdown_table, github_token) \ No newline at end of file +update_github_issue(issue_number, repo_owner, repo_name, markdown_table, github_token) From 0149f6fb4d11fe443dc2fc86b1aac85c649843fd Mon Sep 17 00:00:00 2001 From: "Ignacio Ceballos (Yayo)" Date: Wed, 16 Oct 2024 22:30:27 +0200 Subject: [PATCH 5/7] add issue number column --- .github/branch-table/branch-table.py | 35 ++++++++++++++++------------ 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/.github/branch-table/branch-table.py b/.github/branch-table/branch-table.py index ee968c0cb2..582579a526 100644 --- a/.github/branch-table/branch-table.py +++ b/.github/branch-table/branch-table.py @@ -1,6 +1,7 @@ import requests import pandas as pd import os +import re # Function to get the files from specific Figma projects def get_figma_project_files(project_ids, figma_token): @@ -17,7 +18,7 @@ def get_figma_project_files(project_ids, figma_token): if files_response.status_code == 200: files = files_response.json().get("files", []) for file in files: - file_keys.append(file["key"]) + file_keys.append({"key": file["key"], "name": file["name"]}) else: print(f"Error fetching files for project {project_id}: {files_response.status_code}") @@ -29,7 +30,7 @@ def get_figma_file_data(file_key, figma_token): "X-Figma-Token": figma_token } url = f"https://api.figma.com/v1/files/{file_key}?branch_data=true" - response = requests.get(url, headers=headers, verify=False) + response = requests.get(url, headers=headers, verify=True) if response.status_code == 200: return response.json() @@ -41,27 +42,31 @@ def get_figma_file_data(file_key, figma_token): def analyze_files(file_keys, figma_token): table_data = [] - for file_key in file_keys: + for file in file_keys: + file_key = file["key"] + file_name = file["name"] file_data = get_figma_file_data(file_key, figma_token) if file_data: - file_name = file_data.get("name", "Unknown") branches = file_data.get("branches", []) num_branches = len(branches) # Only add the file if it has branches if num_branches > 0: - # Create links for each branch, in Markdown list format - branch_links = [f"- [{branch['name']}](https://www.figma.com/file/{file_key}/branch/{branch['key']})" - for branch in branches] - - branch_links_str = "\n".join(branch_links) - - table_data.append({ - "File Name": file_name, - "Branches": num_branches, - "Branch Names": branch_links_str - }) + for branch in branches: + branch_name = branch["name"] + branch_link = f"[{branch_name}](https://www.figma.com/file/{file_key}/branch/{branch['key']})" + + # Extract the issue number using regex + issue_match = re.match(r"#(\d{4}).*", branch_name) + issue_number = "#" + issue_match.group(1) if issue_match else "" + + table_data.append({ + "File Name": file_name, + "Branches": num_branches, + "Branch Names": branch_link, + "Issue": issue_number + }) # Create a DataFrame with the collected information df = pd.DataFrame(table_data) From 564b0f38abce384a31f842aaa59fffd527cfd50b Mon Sep 17 00:00:00 2001 From: "Ignacio Ceballos (Yayo)" Date: Wed, 16 Oct 2024 22:34:05 +0200 Subject: [PATCH 6/7] fix duplicated filenames --- .github/branch-table/branch-table.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/branch-table/branch-table.py b/.github/branch-table/branch-table.py index 582579a526..82f4b2e060 100644 --- a/.github/branch-table/branch-table.py +++ b/.github/branch-table/branch-table.py @@ -53,6 +53,7 @@ def analyze_files(file_keys, figma_token): # Only add the file if it has branches if num_branches > 0: + first_branch = True for branch in branches: branch_name = branch["name"] branch_link = f"[{branch_name}](https://www.figma.com/file/{file_key}/branch/{branch['key']})" @@ -62,11 +63,14 @@ def analyze_files(file_keys, figma_token): issue_number = "#" + issue_match.group(1) if issue_match else "" table_data.append({ - "File Name": file_name, - "Branches": num_branches, + "File Name": file_name if first_branch else "", + "Branches": num_branches if first_branch else "", "Branch Names": branch_link, "Issue": issue_number }) + + # After the first branch, set first_branch to False + first_branch = False # Create a DataFrame with the collected information df = pd.DataFrame(table_data) From 50060aec5b6739dd8b31a6f79db9e6ce449867d1 Mon Sep 17 00:00:00 2001 From: "Ignacio Ceballos (Yayo)" Date: Wed, 16 Oct 2024 22:58:01 +0200 Subject: [PATCH 7/7] fix regex --- .github/branch-table/branch-table.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/branch-table/branch-table.py b/.github/branch-table/branch-table.py index 82f4b2e060..697a06728c 100644 --- a/.github/branch-table/branch-table.py +++ b/.github/branch-table/branch-table.py @@ -59,7 +59,7 @@ def analyze_files(file_keys, figma_token): branch_link = f"[{branch_name}](https://www.figma.com/file/{file_key}/branch/{branch['key']})" # Extract the issue number using regex - issue_match = re.match(r"#(\d{4}).*", branch_name) + issue_match = re.match(r"#(\d+)", branch_name) issue_number = "#" + issue_match.group(1) if issue_match else "" table_data.append({ @@ -104,7 +104,7 @@ def update_github_issue(issue_number, repo_owner, repo_name, markdown_content, g "266390224", # Mística Skins Libraries "27955986", # Specs "170790970", # Community Specs - "30110755", # Materials + "30110755" # Materials # Add more project id here ]