forked from VeriSphereVSP/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_issues_from_csv.py
More file actions
127 lines (98 loc) · 4.02 KB
/
create_issues_from_csv.py
File metadata and controls
127 lines (98 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python3
"""
create_issues_from_csv.py
Creates GitHub issues from a CSV file and forces a labeled event so that
bounty.yaml appends the issue row to the Google Sheet.
Place this file in: verisphere/docs/create_issues_from_csv.py
Run with:
GITHUB_TOKEN=ghp_xxx python3 create_issues_from_csv.py mytasks.csv
"""
import os
import csv
import sys
import time
import requests
# ----------------------------------------------------------
# CONFIG
# ----------------------------------------------------------
REPO = "VeriSphereVSP/docs"
TOKEN = os.environ.get("GITHUB_TOKEN")
if not TOKEN:
raise SystemExit("ERROR: GITHUB_TOKEN environment variable is not set.")
ISSUES_API = f"https://api.github.com/repos/{REPO}/issues"
HEADERS = {
"Authorization": f"Bearer {TOKEN}",
"Accept": "application/vnd.github+json",
}
# ----------------------------------------------------------
# UTIL — Check if the issue already exists
# ----------------------------------------------------------
def github_issue_exists(title: str) -> bool:
"""Return True if an issue with this title already exists."""
resp = requests.get(ISSUES_API, headers=HEADERS, params={"state": "all", "per_page": 100})
if resp.status_code != 200:
print("⚠️ Could not fetch existing issues:", resp.text[:200])
return False
for issue in resp.json():
if issue.get("title", "").strip() == title.strip():
print(f"⚠️ Issue already exists → {issue['html_url']}")
return True
return False
# ----------------------------------------------------------
# UTIL — Force labeled webhook to fire so bounty.yaml runs
# ----------------------------------------------------------
def force_labeled_event(issue_number: int, labels: list[str]):
"""
To ensure our Google Sheet workflow runs, we PATCH the issue
with its existing labels, forcing GitHub to emit a "labeled" event.
"""
url = f"{ISSUES_API}/{issue_number}"
resp = requests.patch(url, headers=HEADERS, json={"labels": labels})
if resp.status_code >= 300:
print("❌ Failed to trigger labeled event:", resp.status_code, resp.text[:300])
else:
print("🔄 Labeled event triggered successfully.")
# ----------------------------------------------------------
# MAIN
# ----------------------------------------------------------
def main():
# CSV argument
csv_path = sys.argv[1] if len(sys.argv) > 1 else "verisphere_mvp_tasks.csv"
print("📄 Using CSV:", csv_path)
# Load CSV
try:
f = open(csv_path, newline="", encoding="utf-8")
except FileNotFoundError:
raise SystemExit(f"ERROR: CSV file not found: {csv_path}")
with f:
reader = csv.DictReader(f)
for row in reader:
title = (row.get("Title") or "").strip()
body = (row.get("Body") or "").strip()
labels_raw = (row.get("Labels") or "").split(",")
if not title:
print("⚠️ Skipping row with empty title")
continue
# Normalize labels
labels = [l.strip() for l in labels_raw if l.strip()]
if "bounty" not in [l.lower() for l in labels]:
labels.append("bounty")
print(f"\n🛠 Preparing issue: {title}")
# Skip duplicates
if github_issue_exists(title):
continue
# Create issue
payload = {"title": title, "body": body, "labels": labels}
resp = requests.post(ISSUES_API, headers=HEADERS, json=payload)
if resp.status_code >= 300:
print("❌ Error creating issue:", resp.status_code, resp.text[:300])
continue
issue = resp.json()
issue_number = issue["number"]
issue_url = issue["html_url"]
print(f"✅ Created issue: {issue_url}")
# Force GitHub to emit a labeled event so bounty.yaml runs
time.sleep(1)
force_labeled_event(issue_number, labels)
if __name__ == "__main__":
main()