reposync/issue_sync/add_gitee_issue.py

40 lines
1.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import requests
# 你的Gitee用户名或用于认证的token
# 注意出于安全考虑通常不建议在代码中硬编码密码而是使用token
# 你的仓库信息
owner = 'xumingyang21'
repo = 'reposyncer2'
# 创建issue的标题和内容
issue_title = '这是一个issue标题准备删除'
issue_body = '这是一个issue的详细描述'
# Gitee创建issue的API URL
url = f"https://gitee.com/api/v5/repos/{owner}/issues"
# 构造请求头
token = 'f2be2313581c1fde50b16bf35bb655c5'
headers = {'Authorization': f'token {token}'}
# 发送POST请求
data = {
"access_token":token,
"owner":owner,
"repo":repo,
"title": issue_title,
"body": issue_body
}
response = requests.post(url, headers=headers, json=data)
# 打印响应
print(response.text)
# 检查响应状态码
if response.status_code == 201:
# 注意:这里假设响应体中包含一个'number'字段作为issue的ID但实际上Gitee可能返回不同的结构
# 你需要根据实际的响应结构来调整以下代码
issue_info = response.json()
print(f'Issue created with ID: {issue_info["number"]}')
else:
print(f"创建issue失败状态码{response.status_code},错误信息:{response.text}")