forked from Ikalus1988/MisakaNet
-
Notifications
You must be signed in to change notification settings - Fork 0
107 lines (95 loc) · 3.5 KB
/
Copy pathcite-lesson.yml
File metadata and controls
107 lines (95 loc) · 3.5 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
name: 知识引用追踪
on:
issues:
types: [opened, edited]
workflow_dispatch:
jobs:
cite-lesson:
# Only run for issues with 'usage' label; skip workflow_dispatch gracefully
if: >
github.event_name == 'issues' &&
contains(github.event.issue.labels.*.name, 'usage')
runs-on: ubuntu-latest
permissions:
issues: read
contents: write
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Parse usage report and cite lessons
id: cite
uses: ./.github/actions/retry/
with:
run: |
python3 << 'PYEOF'
import json
import re
import os
import sys
from datetime import datetime
issue = json.loads(os.environ.get('ISSUE_JSON', '{}'))
body = issue.get('body', '')
node = issue.get('title', '?').replace('usage:', '').strip()
user = issue.get('user', {}).get('login', '?')
issue_url = issue.get('html_url', '')
issue_num = issue.get('number', 0)
date = datetime.utcnow().strftime('%Y-%m-%d')
# Parse used section
used_section = ''
in_used = False
for line in body.split('\n'):
if 'used' in line.lower() or '本次使用' in line:
in_used = True
continue
if in_used:
if line.strip().startswith('- '):
used_section += line + '\n'
elif line.strip() == '':
break
# Extract lesson IDs
lesson_ids = re.findall(r'([a-z0-9-]+)', used_section)
if not lesson_ids:
print("No lesson IDs found")
sys.exit(0)
# Load lessons
lessons = []
try:
with open('data/lessons.json') as f:
lessons = json.load(f)
except:
print("Could not load lessons.json")
sys.exit(0)
# Find cited lessons
cited = []
for lesson in lessons:
lid = lesson.get('id', '')
if any(oid in lid for oid in lesson_ids):
cited.append(lesson)
if not cited:
print("No matching lessons found")
sys.exit(0)
# Create citation comment
lines = [f"📚 **引用追踪 — {node}**", '', f"**贡献者:** @{user}", f"**日期:** {date}", '', '## 引用的知识', '']
for c in cited:
lines.append(f"- **{c.get('id', '?')}**: {c.get('title', '?')}")
lines.append(f" Domain: {c.get('domain', '?')} | Tags: {', '.join(c.get('tags', []))}")
lines.extend(['', '---', '> 自动引用追踪 by ci-self-heal'])
print('\n'.join(lines))
PYEOF
max_attempts: 3
backoff: exponential
backoff_base_seconds: 5
- name: Commit citation update
id: commit
uses: ./.github/actions/retry/
with:
run: |
git config user.name "misakanet-bot"
git config user.email "bot@misakanet.dev"
git add -A
git diff --cached --quiet || git commit -m "cite: update references for issue #${{ github.event.issue.number }}"
git push
max_attempts: 3
backoff: exponential
backoff_base_seconds: 5
retry_on_exit_code: "1"