Skip to content

Commit

Permalink
feat: Add script to create GitHub issues from stra
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] committed Mar 23, 2024
1 parent b28a2a1 commit 12d90a2
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions scripts/jobs/create_issues_from_strategy_doc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import json
import os
import re
import time

import requests


def read_strategy_md(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
return file.read()

def parse_tasks(markdown_content):
tasks = []
task_pattern = re.compile(r'###\s(.+)\n+([\s\S]+?)(?=\n###|$)')
matches = task_pattern.findall(markdown_content)
for match in matches:
tasks.append({'title': match[0], 'body': match[1].strip()})
return tasks

def create_github_issue(title, body, token, repo):
url = f"https://api.github.com/repos/{repo}/issues"
headers = {
"Authorization": f"token {token}",
"Accept": "application/vnd.github.v3+json"
}
data = {
"title": title,
"body": body
}
response = requests.post(url, headers=headers, data=json.dumps(data))
if response.status_code == 201:
print(f"Issue '{title}' created successfully.")
elif response.status_code == 429:
print("Rate limit exceeded. Waiting 60 seconds before retrying...")
time.sleep(60)
create_github_issue(title, body, token, repo)
elif response.status_code == 401:
raise Exception("Authentication failed. Check your GitHub token.")
else:
raise Exception(f"Failed to create issue '{title}': {response.content}")

def main():
file_path = "docs/treaty/strategy.md"
repo = "FDA-AI/FDAi"
token = os.getenv("GITHUB_TOKEN")
if not token:
raise Exception("GitHub token not found. Set the GITHUB_TOKEN environment variable.")

try:
markdown_content = read_strategy_md(file_path)
tasks = parse_tasks(markdown_content)
for task in tasks:
create_github_issue(task['title'], task['body'], token, repo)
except FileNotFoundError:
print(f"File {file_path} not found.")
except Exception as e:
print(f"Error: {str(e)}")

if __name__ == "__main__":
main()

0 comments on commit 12d90a2

Please sign in to comment.