-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
43 lines (35 loc) · 1.29 KB
/
script.py
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
import os
from dotenv import load_dotenv
import requests
load_dotenv()
def get_github_token():
token = os.getenv("GITHUB_TOKEN")
if not token:
raise ValueError("GitHub token not found in environment variables. Please set GITHUB_TOKEN.")
return token
def create_github_issue(repo_owner, repo_name, title, body):
url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/issues"
headers = {
"Authorization": f"Bearer {get_github_token()}",
"Accept": "application/vnd.github.v3+json"
}
data = {
"title": title,
"body": body
}
response = requests.post(url, headers=headers, json=data)
if response.status_code == 201:
print(f"Issue created successfully: {response.json()['html_url']}")
else:
print(f"Failed to create issue. Status code: {response.status_code}, Response: {response.text}")
def main(file_path, repo_owner, repo_name):
with open(file_path, 'r') as file:
for line in file:
trimmed_line = line.strip()
if trimmed_line:
create_github_issue(repo_owner, repo_name, trimmed_line, "")
if __name__ == "__main__":
file_path = "tasks.txt"
repo_owner = "BaseMax"
repo_name = "AutoCreateGitHubIssuesManage"
main(file_path, repo_owner, repo_name)