mirror of
https://github.com/logos-storage/logos-storage-pm.git
synced 2026-01-05 23:13:10 +00:00
add vacuum.py script and vacuum.yml workflow to extract all removed labels from all issues across all repos in the Codex organization
This commit is contained in:
parent
88faeafada
commit
0d006ff591
28
.github/scripts/restore_labels.py
vendored
28
.github/scripts/restore_labels.py
vendored
@ -1,28 +0,0 @@
|
|||||||
import os
|
|
||||||
import requests
|
|
||||||
import json
|
|
||||||
|
|
||||||
# Replace with your GitHub username, organization, repository, and personal access token
|
|
||||||
username = "JessieBroke"
|
|
||||||
organization = "codex-storage"
|
|
||||||
repository = "nim-codex"
|
|
||||||
token = os.getenv("GH_PAT")
|
|
||||||
|
|
||||||
# GitHub API endpoint for listing issue events
|
|
||||||
api_url = f"https://api.github.com/repos/{organization}/{repository}/issues/events"
|
|
||||||
|
|
||||||
# Fetch issue events
|
|
||||||
response = requests.get(api_url, headers={"Authorization": f"Bearer {token}"})
|
|
||||||
events = response.json()
|
|
||||||
|
|
||||||
# Save events to a JSON file
|
|
||||||
with open("issue_events.json", "w") as file:
|
|
||||||
json.dump(events, file)
|
|
||||||
|
|
||||||
# Restore labels based on deletion events
|
|
||||||
for event in events:
|
|
||||||
if event["event"] == "label":
|
|
||||||
label_name = event["label"]["name"]
|
|
||||||
# Restore the label using your preferred method (GitHub API, gh CLI, etc.)
|
|
||||||
print(f"Restoring label: {label_name}")
|
|
||||||
# Add logic here to restore the label using the GitHub API or other methods
|
|
||||||
72
.github/scripts/vacuum.py
vendored
Normal file
72
.github/scripts/vacuum.py
vendored
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
import os
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
|
# Replace with your GitHub username, organization, and personal access token
|
||||||
|
username = "JessieBroke"
|
||||||
|
organization = "TheBasedmint"
|
||||||
|
token = os.getenv("GH_PAT")
|
||||||
|
|
||||||
|
# GitHub API endpoint for listing repositories in the organization
|
||||||
|
repositories_url = f"https://api.github.com/orgs/{organization}/repos"
|
||||||
|
|
||||||
|
# Fetch repositories
|
||||||
|
response = requests.get(repositories_url, headers={"Authorization": f"Bearer {token}"})
|
||||||
|
repositories_data = response.json()
|
||||||
|
|
||||||
|
# Extract repository names from the response
|
||||||
|
repositories = [repo["name"] for repo in repositories_data]
|
||||||
|
|
||||||
|
# Calculate the datetime 48 hours ago from now
|
||||||
|
time_threshold = datetime.utcnow() - timedelta(hours=48)
|
||||||
|
|
||||||
|
# Create a dictionary to store unique issues based on the combination of issue URL and label name
|
||||||
|
unique_issues = {}
|
||||||
|
|
||||||
|
# Iterate through each repository
|
||||||
|
for repository in repositories:
|
||||||
|
# GitHub API endpoint for listing issue events
|
||||||
|
api_url = f"https://api.github.com/repos/{organization}/{repository}/issues/events"
|
||||||
|
|
||||||
|
# Fetch issue events
|
||||||
|
response = requests.get(api_url, headers={"Authorization": f"Bearer {token}"})
|
||||||
|
events = response.json()
|
||||||
|
|
||||||
|
# Iterate through each event in the list
|
||||||
|
for event in events:
|
||||||
|
# Extracting information for each event
|
||||||
|
event_type = event.get('event')
|
||||||
|
created_at_str = event.get('created_at')
|
||||||
|
|
||||||
|
# Convert created_at string to datetime object
|
||||||
|
created_at = datetime.strptime(created_at_str, "%Y-%m-%dT%H:%M:%SZ")
|
||||||
|
|
||||||
|
# Check if the event is 'unlabeled' and updated in the past 48 hours
|
||||||
|
if event_type == 'unlabeled' and created_at > time_threshold:
|
||||||
|
actor_login = event.get('actor', {}).get('login')
|
||||||
|
label_name = event.get('label', {}).get('name')
|
||||||
|
label_color = event.get('label', {}).get('color')
|
||||||
|
issue_url = event.get('issue', {}).get('html_url')
|
||||||
|
|
||||||
|
if actor_login and label_name and label_color and issue_url:
|
||||||
|
# Use a unique identifier for each issue-label combination
|
||||||
|
unique_identifier = f"{issue_url}_{label_name}"
|
||||||
|
|
||||||
|
# Check if the unique identifier is not already in the dictionary
|
||||||
|
if unique_identifier not in unique_issues:
|
||||||
|
unique_issues[unique_identifier] = {
|
||||||
|
'login': actor_login,
|
||||||
|
'label_name': label_name,
|
||||||
|
'label_color': label_color,
|
||||||
|
'issue_url': issue_url
|
||||||
|
}
|
||||||
|
|
||||||
|
# Convert the dictionary values to a list
|
||||||
|
filtered_data = list(unique_issues.values())
|
||||||
|
|
||||||
|
# Write the filtered data to a new JSON file
|
||||||
|
output_path = os.path.join("output", "vacuum_data.json")
|
||||||
|
os.makedirs(os.path.dirname(output_path), exist_ok=True)
|
||||||
|
with open(output_path, 'w') as output_file:
|
||||||
|
json.dump(filtered_data, output_file, indent=2)
|
||||||
30
.github/workflows/add-labels-to-issues.yml
vendored
Normal file
30
.github/workflows/add-labels-to-issues.yml
vendored
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
name: Add Label to Issues
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
add-label:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Add label to open issues in "test1" repository
|
||||||
|
run: |
|
||||||
|
REPO="TheBasedmint/test1"
|
||||||
|
LABEL="Marketplace"
|
||||||
|
|
||||||
|
# Fetch open issues
|
||||||
|
for issue in $(curl -s -H "Authorization: Bearer ${{ secrets.SYNC_LABELS2 }}" \
|
||||||
|
-H "Accept: application/vnd.github.v3+json" \
|
||||||
|
"https://api.github.com/repos/$REPO/issues?state=open" | jq -r '.[].number'); do
|
||||||
|
|
||||||
|
# Apply label to each open issue
|
||||||
|
curl -X POST -H "Authorization: Bearer ${{ secrets.SYNC_LABELS2 }}" \
|
||||||
|
-H "Accept: application/vnd.github.v3+json" \
|
||||||
|
-d "{\"labels\": [\"$LABEL\"]}" \
|
||||||
|
"https://api.github.com/repos/$REPO/issues/$issue/labels"
|
||||||
|
done
|
||||||
0
.github/workflows/vacuum.py
vendored
Normal file
0
.github/workflows/vacuum.py
vendored
Normal file
Loading…
x
Reference in New Issue
Block a user