# AutoPR
Fix issues with AI-generated pull requests, powered by ChatGPT
## Usage
1、把 AutoPR 设置到项目中
创建 .github/workflows/autopr.yml, 模板:https://github.com/irgolic/AutoPR-template/blob/main/.github/workflows/autopr.yml
里面设置一下openai key
2、创建一个label,名称 AutoPR
3、new 一个 issue,包含清晰的问题和步骤描述。
4、增加 AutoPR 标签到这个 issue
自动触发 action,创建 autopr/issue-# 分支,并发起 pull request
5、人工 Review 代码,合并代码
## 源码分析
采用 github action 方式自动化pull request。 触发条件:
```
on:
issues:
types: [labeled]
```
标签为 AutoPR,则继续执行,否则exit:
```
curl -s -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/${{ github.repository }}/collaborators/${{ github.event.sender.login }}" | jq -r '.message'
```
继续执行,采用的是 docker 容器方式:
```
docker://ghcr.io/irgolic/autopr:latest
```
执行 :
```
python -m autopr.gh_actions_entrypoint
```
执行 main方法,先切换到 autopr/issue-# 分支, commit,然后 push,发起pull request
```
main(
repo_path=repo_path,
event=event,
commit_service=commit_service,
publish_service=publish_service,
settings=settings,
)
```
```
```
## 💎 Examples
Well-written issues often lead to better results.
- [Create a dice rolling bot](https://github.com/irgolic/AutoPR-template/pull/21)
- [Create a 'Tech Jargon Generator'](https://github.com/irgolic/AutoPR-template/pull/13)
- [Create a user-friendly weather app](https://github.com/irgolic/AutoPR-template/pull/15)
- [Write three programming interview challenges](https://github.com/irgolic/AutoPR-template/pull/11)
- [Replace `GPT2FastTokenizer` with `tiktoken`](https://github.com/irgolic/AutoPR/pull/44)