Skip to content

Commit

Permalink
Merge branch 'production' into movistar-skin-completed
Browse files Browse the repository at this point in the history
  • Loading branch information
yceballost committed May 20, 2024
2 parents 9aa0483 + 3e8eac0 commit 77dd0f3
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
76 changes: 76 additions & 0 deletions .github/scripts/label_discussion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import os
import json
import requests

# GitHub repository and token
REPO = 'Telefonica/mistica-design'
TOKEN = os.getenv('NOVUM_PRIVATE_REPOS')
API_URL = f"https://api.github.com/repos/{REPO}"

# Verifica si el token está presente
if not TOKEN:
raise ValueError("NOVUM_PRIVATE_REPOS no está configurado")

# Depuración: Imprime los primeros caracteres del token
print(f"TOKEN: {TOKEN[:4]}...")

# Get event data from environment variable
event_path = os.getenv('GITHUB_EVENT_PATH')
with open(event_path) as f:
event_data = json.load(f)

# Determine if the event is a discussion or a discussion comment
if 'discussion' in event_data:
discussion_id = event_data['discussion']['node_id']
discussion_title = event_data['discussion']['title']
discussion_body = event_data['discussion']['body']
elif 'comment' in event_data:
discussion_id = event_data['comment']['discussion_id']
discussion_title = "" # Comments do not have a title
discussion_body = event_data['comment']['body']
else:
raise ValueError("Evento no reconocido")

# Function to get existing labels
def get_existing_labels():
headers = {
'Authorization': f'token {TOKEN}',
'Accept': 'application/vnd.github.v3+json',
}
response = requests.get(f'{API_URL}/labels', headers=headers)
response.raise_for_status()
return [label['name'] for label in response.json()]

# Function to apply label
def apply_label(label):
headers = {
'Authorization': f'token {TOKEN}',
'Accept': 'application/vnd.github.v3+json',
}
data = {
'labels': [label]
}
response = requests.post(f'{API_URL}/discussions/{discussion_id}/labels', headers=headers, json=data)
response.raise_for_status()

# Function to determine appropriate label
def determine_label(title, body, labels):
# Simple keyword matching for demonstration; improve with NLP techniques as needed
keywords_to_labels = {
'bug': 'bug',
'feature': 'enhancement',
'question': 'question'
}

for keyword, label in keywords_to_labels.items():
if keyword in title.lower() or keyword in body.lower():
if label in labels:
return label
return None

# Main script logic
existing_labels = get_existing_labels()
label_to_apply = determine_label(discussion_title, discussion_body, existing_labels)

if label_to_apply:
apply_label(label_to_apply)
31 changes: 31 additions & 0 deletions .github/workflows/label-discussion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Label Discussions

on:
discussion:
types: [created, edited]
discussion_comment:
types: [created, edited]

jobs:
label_discussion:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.x"

- name: Install dependencies
run: pip install requests

- name: Debug environment variables
run: env

- name: Run labeling script
env:
NOVUM_PRIVATE_REPOS: ${{ secrets.NOVUM_PRIVATE_REPOS }}
run: python .github/scripts/label_discussion.py
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Figma Changelog

[13.3.0](changelog-versions/13.3.0.md)

[13.2.0](changelog-versions/13.2.0.md)

[13.1.0](changelog-versions/13.1.0.md)
Expand Down
Empty file removed changelog-versions/Vivo_a11y.md
Empty file.

0 comments on commit 77dd0f3

Please sign in to comment.