Skip to content

Commit

Permalink
Add label to associated discussion
Browse files Browse the repository at this point in the history
  • Loading branch information
codycooperross authored Jul 24, 2024
1 parent b794416 commit c5fe37f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/scripts/update_discussion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from github import Github
import re
import os

# Initialize GitHub client
token = os.getenv('GITHUB_TOKEN')
label = os.getenv('TRANSFERRED_LABEL')
g = Github(token)

# Get repository
repo = g.get_repo(os.getenv('GITHUB_REPOSITORY'))

# Get the issue from the environment
issue_number = int(os.getenv('ISSUE_NUMBER'))
issue = repo.get_issue(number=issue_number)

# Regular expression to find GitHub Discussions links
discussions_pattern = re.compile(r'https://github.com/.*/discussions/(\d+)')

# Search for discussions link in the issue body
match = discussions_pattern.search(issue.body)

if match:
discussion_number = match.group(1)
discussion = repo.get_discussion(discussion_number)

# Add label to the discussion
discussion.edit(labels=[label]) # Replace 'your-label' with the desired label

print(f'Updated discussion #{discussion_number} with label.')
1 change: 1 addition & 0 deletions .github/workflows/new_issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- name: Run Python script
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TRANSFERRED_LABEL: ${{ vars.TRANSFERRED_LABEL }}
run: |
python .github/scripts/update_discussion.py
transfer_issue:
Expand Down

0 comments on commit c5fe37f

Please sign in to comment.