Chuyển tới nội dung chính

{/* Trang này được tạo tự động từ SKILL.md của kỹ năng bởi website/scripts/generate-skill-docs.py. Chỉnh sửa nguồn SKILL.md, không phải trang này. */}

Vấn đề về GitHub

Tạo, phân loại, gắn nhãn, gán sự cố GitHub thông qua gh hoặc REST.

Siêu dữ liệu kỹ năng

NguồnĐi kèm (được cài đặt theo mặc định)
Đường dẫn

skills/GitHub/GitHub-issues ` | | Phiên bản |

1.1.0 ` | | Tác giả | Đại lý Hermes | | Giấy phép | MIT | | Nền tảng | Linux, macOS, Windows | | Thẻ |

GitHub

, `Issues

, `Project-Management

, `Bug-Tracking

, Triage | | Kỹ năng liên quan | XPROTECTX28XPROTECTX, XPROTECTX29XPROTECTX |

Tham khảo: đầy đủ SKILL.md

thông tin

Sau đây là định nghĩa kỹ năng đầy đủ mà Hermes tải khi kỹ năng này được kích hoạt. Đây là những gì tác nhân coi là hướng dẫn khi kỹ năng được kích hoạt.

Quản lý vấn đề GitHub

Tạo, tìm kiếm, phân loại và quản lý các sự cố GitHub. Mỗi phần hiển thị gh trước tiên, sau đó là dự phòng `curl

.

Điều kiện tiên quyết

  • Đã xác thực bằng GitHub (xem kỹ năng `GitHub-auth

)

  • Bên trong repo git có điều khiển từ xa GitHub hoặc chỉ định rõ ràng repo

Thiết lập

if command -v gh &>/dev/null && gh auth status &>/dev/null; then
AUTH="gh"
else
AUTH="git"
if [ -z "$GitHub_TOKEN" ]; then
if [ -f ~/.Hermes/.env ] && grep -q "^GitHub_TOKEN=" ~/.Hermes/.env; then
GitHub_TOKEN=$(grep "^GitHub_TOKEN=" ~/.Hermes/.env | head -1 | cut -d= -f2 | tr -d '\n\r')
elif grep -q "GitHub.com" ~/.git-credentials 2>/dev/null; then
GitHub_TOKEN=$(grep "GitHub.com" ~/.git-credentials 2>/dev/null | head -1 | sed 's|https://[^:]*:\([^@]*\)@.*|\1|')
fi
fi
fi

REMOTE_URL=$(git remote get-url origin)
OWNER_REPO=$(echo "$REMOTE_URL" | sed -E 's|.*GitHub\.com[:/]||; s|\.git$||')
OWNER=$(echo "$OWNER_REPO" | cut -d/ -f1)
REPO=$(echo "$OWNER_REPO" | cut -d/ -f2)

`

---

## 1. Vấn đề khi xem`**Với gh:**

`bash
gh issue list
gh issue list --state open --label "bug"
gh issue list --assignee @me
gh issue list --search "authentication error" --state all
gh issue view 42

`
``**Với độ cong:**

`bash

# List open issues
curl -s \
-H "Authorization: token $GitHub_TOKEN" \
"https://API.GitHub.com/repos/$OWNER/$REPO/issues?state=open&per_page=20" \
| Python3 -c "
import sys, JSON
for i in JSON.load(sys.stdin):
if 'pull_request' not in i: # GitHub API returns PRs in /issues too
labels = ', '.join(l['name'] for l in i['labels'])
print(f\"#\{i['number']:5} \{i['state']:6} \{labels:30} \{i['title']}\")"

# Filter by label
curl -s \
-H "Authorization: token $GitHub_TOKEN" \
"https://API.GitHub.com/repos/$OWNER/$REPO/issues?state=open&labels=bug&per_page=20" \
| Python3 -c "
import sys, JSON
for i in JSON.load(sys.stdin):
if 'pull_request' not in i:
print(f\"#\{i['number']} \{i['title']}\")"

# View a specific issue
curl -s \
-H "Authorization: token $GitHub_TOKEN" \
https://API.GitHub.com/repos/$OWNER/$REPO/issues/42 \
| Python3 -c "
import sys, JSON
i = JSON.load(sys.stdin)
labels = ', '.join(l['name'] for l in i['labels'])
assignees = ', '.join(a['login'] for a in i['assignees'])
print(f\"#\{i['number']}: \{i['title']}\")
print(f\"State: \{i['state']} Labels: \{labels} Assignees: \{assignees}\")
print(f\"Author: \{i['user']['login']} Created: \{i['created_at']}\")
print(f\"\n\{i['body']}\")"

# Search issues
curl -s \
-H "Authorization: token $GitHub_TOKEN" \
"https://API.GitHub.com/search/issues?q=authentication+error+repo:$OWNER/$REPO" \
| Python3 -c "
import sys, JSON
for i in JSON.load(sys.stdin)['items']:
print(f\"#\{i['number']} \{i['state']:6} \{i['title']}\")"

`

## 2. Tạo vấn đề`**Với gh:**

``` bash
gh issue create \

--title "Login redirect ignores ?next= parameter" \
--body "## Description
After logging in, users always land on /dashboard.

## Steps to Reproduce
1. Navigate to /settings while logged out
2. Get redirected to /login?next=/settings
3. Log in
4. Actual: redirected to /dashboard (should go to /settings)

## Expected Behavior
Respect the ?next= query parameter." \
--label "bug,backend" \
--assignee "username"

`
``**Với độ cong:**

``` bash
curl -s -X POST \

-H "Authorization: token $GitHub_TOKEN" \
https://API.GitHub.com/repos/$OWNER/$REPO/issues \
-d '{
"title": "Login redirect ignores ?next= parameter",
"body": "## Description\nAfter logging in, users always land on /dashboard.\n\n## Steps to Reproduce\n1. Navigate to /settings while logged out\n2. Get redirected to /login?next=/settings\n3. Log in\n4. Actual: redirected to /dashboard\n\n## Expected Behavior\nRespect the ?next= query parameter.",
"labels": ["bug", "backend"],
"assignees": ["username"]
}'

`

### Mẫu báo cáo lỗi

`
## Bug Description
<What's happening>

## Steps to Reproduce
1. <step>
2. <step>

## Expected Behavior
<What should happen

## Actual Behavior
<What actually happens>

## Environment
- OS: <os>
- Version: <version>

`

### Mẫu yêu cầu tính năng

`
## Feature Description
<What you want>

## Motivation
<Why this would be useful

## Proposed Solution
<How it could work>

## Alternatives Considered
<Other approaches>

`

## 3. Quản lý vấn đề

### Thêm/Xóa Nhãn`**Với gh:**

``` bash
gh issue edit 42 --add-label "priority:high,bug"
gh issue edit 42 --remove-label "needs-triage"

`
``**Với độ cong:**

`bash

# Add labels
curl -s -X POST \
-H "Authorization: token $GitHub_TOKEN" \
https://API.GitHub.com/repos/$OWNER/$REPO/issues/42/labels \
-d '\{"labels": ["priority:high", "bug"]}'

# Remove a label
curl -s -X DELETE \
-H "Authorization: token $GitHub_TOKEN" \
https://API.GitHub.com/repos/$OWNER/$REPO/issues/42/labels/needs-triage

# List available labels in the repo
curl -s \
-H "Authorization: token $GitHub_TOKEN" \
https://API.GitHub.com/repos/$OWNER/$REPO/labels \
| Python3 -c "
import sys, JSON
for l in JSON.load(sys.stdin):
print(f\" \{l['name']:30} \{l.get('description', '')}\")"

`

### Bài tập`**Với gh:**

``` bash
gh issue edit 42 --add-assignee username
gh issue edit 42 --add-assignee @me

`
``**Với độ cong:**

`bash
curl -s -X POST \

-H "Authorization: token $GitHub_TOKEN" \
https://API.GitHub.com/repos/$OWNER/$REPO/issues/42/assignees \
-d '\{"assignees": ["username"]}'

`

### Bình luận`**Với gh:**

``` bash
gh issue comment 42 --body "Investigated — root cause is in auth middleware. Working on a fix."

`
``**Với độ cong:**

`bash
curl -s -X POST \

-H "Authorization: token $GitHub_TOKEN" \
https://API.GitHub.com/repos/$OWNER/$REPO/issues/42/comments \
-d '\{"body": "Investigated — root cause is in auth middleware. Working on a fix."}'

`

### Đóng và mở lại`**Với gh:**

``` bash
gh issue close 42
gh issue close 42 --reason "not planned"
gh issue reopen 42

`
``**Với độ cong:**

`bash

# Close
curl -s -X PATCH \
-H "Authorization: token $GitHub_TOKEN" \
https://API.GitHub.com/repos/$OWNER/$REPO/issues/42 \
-d '\{"state": "closed", "state_reason": "completed"}'

# Reopen
curl -s -X PATCH \
-H "Authorization: token $GitHub_TOKEN" \
https://API.GitHub.com/repos/$OWNER/$REPO/issues/42 \
-d '\{"state": "open"}'

`

### Liên kết các vấn đề với PR

Các vấn đề sẽ tự động được đóng lại khi PR kết hợp với các từ khóa phù hợp trong nội dung:

`
Closes #42
Fixes #42
Resolves #42

`
``Để tạo một nhánh từ một vấn đề:

**Với gh:**

``` bash
gh issue develop 42 --checkout

`
``**Với git (tương đương thủ công):**

`bash
git checkout main && git pull origin main
git checkout -b fix/issue-42-login-redirect

`

## 4. Quy trình xử lý sự cố

Khi được yêu cầu phân loại vấn đề:
1. **Liệt kê các vấn đề chưa được xử lý:**

`bash

# With gh
gh issue list --label "needs-triage" --state open

# With curl
curl -s \
-H "Authorization: token $GitHub_TOKEN" \
"https://API.GitHub.com/repos/$OWNER/$REPO/issues?labels=needs-triage&state=open" \
| Python3 -c "
import sys, JSON
for i in JSON.load(sys.stdin):
if 'pull_request' not in i:
print(f\"#\{i['number']} \{i['title']}\")"

`

2. **Đọc và phân loại** từng vấn đề (xem chi tiết, hiểu lỗi/tính năng)
3. **Áp dụng nhãn và mức độ ưu tiên** (xem Quản lý vấn đề ở trên)
4. **Chỉ định** nếu chủ sở hữu rõ ràng
5. **Nhận xét kèm theo ghi chú phân loại** nếu cần

## 5. Hoạt động hàng loạt

Đối với các hoạt động hàng loạt, hãy kết hợp lệnh gọi API với tập lệnh shell:

**Với gh:**

``` bash

# Close all issues with a specific label
gh issue list --label "wontfix" --JSON number --jq '.[].number' | \
xargs -I \{} gh issue close \{} --reason "not planned"

`
``**Với độ cong:**

``` bash

# List issue numbers with a label, then close each
curl -s \
-H "Authorization: token $GitHub_TOKEN" \
"https://API.GitHub.com/repos/$OWNER/$REPO/issues?labels=wontfix&state=open" \
| Python3 -c "import sys,JSON; [print(i['number']) for i in JSON.load(sys.stdin)]" \
| while read num; do
curl -s -X PATCH \
-H "Authorization: token $GitHub_TOKEN" \
https://API.GitHub.com/repos/$OWNER/$REPO/issues/$num \
-d '\{"state": "closed", "state_reason": "not_planned"}'
echo "Closed #$num"
done

`

## Bảng tham khảo nhanh

| Hành động | gh | điểm cuối cuộn tròn |
|--------|------|--------------|
| Liệt kê các vấn đề |

gh issue list
` |
`GET /repos/\{o}/\{r}/issues
` |
| Xem vấn đề |

gh issue view N
` |
`GET /repos/\{o}/\{r}/issues/N
` |
| Tạo vấn đề |

gh issue create ...
` |
`POST /repos/\{o}/\{r}/issues
` |
| Thêm nhãn |

gh issue edit N --add-label ...
` |
`POST /repos/\{o}/\{r}/issues/N/labels
` |
| Chỉ định |

gh issue edit N --add-assignee ...
` |
`POST /repos/\{o}/\{r}/issues/N/assignees
` |
| Bình luận |

gh issue comment N --body ...
` |
`POST /repos/\{o}/\{r}/issues/N/comments
` |
| Đóng |

gh issue close N
` |
`PATCH /repos/\{o}/\{r}/issues/N
` |
| Tìm kiếm |

gh issue list --search "..."
` |
`GET /search/issues?q=...
` |