From 12d90a2702c3619c790a93603cfe3aea14b4477d Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 23 Mar 2024 20:42:11 +0000 Subject: [PATCH 1/2] feat: Add script to create GitHub issues from stra --- .../jobs/create_issues_from_strategy_doc.py | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 scripts/jobs/create_issues_from_strategy_doc.py diff --git a/scripts/jobs/create_issues_from_strategy_doc.py b/scripts/jobs/create_issues_from_strategy_doc.py new file mode 100644 index 000000000..af8055949 --- /dev/null +++ b/scripts/jobs/create_issues_from_strategy_doc.py @@ -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() From aa8cd996dde2fb4098e40cdcd06e1a9e8c8019a1 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Sat, 23 Mar 2024 20:45:31 +0000 Subject: [PATCH 2/2] feat: Updated docs/contributing/task-management/cr --- .../task-management/create-a-task.md | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/contributing/task-management/create-a-task.md b/docs/contributing/task-management/create-a-task.md index e0e954362..8731b8f6e 100644 --- a/docs/contributing/task-management/create-a-task.md +++ b/docs/contributing/task-management/create-a-task.md @@ -15,3 +15,27 @@ dateCreated: 2022-07-27T21:36:24.019Z 3. If it already exists, click it and up-vote it as described 👉 [here](vote-on-tasks-and-sort-by-priority.md) 4. If not, click the `New issue` button 5. Describe in as much detail as possible and add any tags that you think will be helpful in filtering and sorting + +# Automating Task Creation + +To automate the creation of GitHub issues for tasks listed in the `docs/treaty/strategy.md` document, you can use the `create_issues_from_strategy_doc.py` script. This script allows for bulk creation of issues, which can save time when dealing with multiple tasks. However, it should be used with caution to avoid creating duplicate issues. + +## Prerequisites + +- **Python Installation**: Ensure you have Python installed on your system. You can download it from [python.org](https://www.python.org/downloads/). +- **Necessary Python Packages**: The script requires the `requests` package. Install it using pip: + ``` + pip install requests + ``` +- **GitHub API Token**: You need a GitHub API token with the necessary permissions to create issues in the repository. Follow the instructions on GitHub to create your token. + +## Running the Script + +1. Ensure all prerequisites are met. +2. Navigate to the directory containing the `create_issues_from_strategy_doc.py` script. +3. Run the script with the following command: + ``` + python create_issues_from_strategy_doc.py + ``` + +Remember to use this script responsibly to avoid creating duplicate issues.