Skip to content

Commit 1efa104

Browse files
committed
🐛fix bug
1 parent 0ba6113 commit 1efa104

File tree

3 files changed

+40
-37
lines changed

3 files changed

+40
-37
lines changed

.github/workflows/generate_readme.yml

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,48 +12,36 @@ on:
1212
paths:
1313
- main.py
1414

15-
env:
16-
GITHUB_NAME: superleeyom
17-
GITHUB_EMAIL: [email protected]
18-
1915
jobs:
2016
sync:
2117
name: Generate README
2218
runs-on: ubuntu-latest
2319
steps:
2420
- name: Checkout
25-
uses: actions/checkout@v2
21+
uses: actions/checkout@v3
2622
- name: Set up Python
27-
uses: actions/setup-python@v1
23+
uses: actions/setup-python@v4
2824
with:
2925
python-version: 3.8
30-
31-
- name: Configure pip cache
32-
uses: actions/cache@v1
33-
id: pip-cache
34-
with:
35-
path: venv
36-
key: pip-1-${{ hashFiles('**/requirements.txt') }}
37-
restore-keys: |
38-
pip-
26+
cache: pip
27+
cache-dependency-path: "requirements.txt"
3928

4029
- name: Install dependencies
4130
run: |
4231
python -m pip install --upgrade pip
4332
python -m venv venv
4433
source venv/bin/activate
4534
pip install -r requirements.txt
46-
if: steps.pip-cache.outputs.cache-hit != 'true'
4735
4836
- name: Generate new md
4937
run: |
5038
source venv/bin/activate
5139
python main.py ${{ secrets.G_T }} ${{ github.repository }} --issue_number '${{ github.event.issue.number }}'
52-
53-
- name: update readme
40+
41+
- name: Push README
5442
run: |
55-
git config --local user.email "${{ env.GITHUB_EMAIL }}"
56-
git config --local user.name "${{ env.GITHUB_EMAIL }}"
57-
git add .
58-
git commit -a -m '🎉update readme' || echo "nothing to commit"
59-
git push || echo "nothing to push"
43+
git config --local user.email "[email protected]"
44+
git config --local user.name "GitHub Action"
45+
git add backup/*.md
46+
git commit -a -m 'update new blog' || echo "nothing to commit"
47+
git push || echo "nothing to push"

main.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# -*- coding: utf-8 -*-
22
import argparse
33
import os
4+
import re
45

5-
from marko.ext.gfm import gfm as marko
6-
from github import Github
6+
import markdown
77
from feedgen.feed import FeedGenerator
8+
from github import Github
89
from lxml.etree import CDATA
910

1011
MD_HEAD = """**<p align="center">[Leeyom's Blog](https://blog.leeyom.top)</p>**
@@ -41,10 +42,10 @@ def _valid_xml_char_ordinal(c):
4142
codepoint = ord(c)
4243
# conditions ordered by presumed frequency
4344
return (
44-
0x20 <= codepoint <= 0xD7FF
45-
or codepoint in (0x9, 0xA, 0xD)
46-
or 0xE000 <= codepoint <= 0xFFFD
47-
or 0x10000 <= codepoint <= 0x10FFFF
45+
0x20 <= codepoint <= 0xD7FF
46+
or codepoint in (0x9, 0xA, 0xD)
47+
or 0xE000 <= codepoint <= 0xFFFD
48+
or 0x10000 <= codepoint <= 0x10FFFF
4849
)
4950

5051

@@ -133,20 +134,33 @@ def add_md_recent(repo, md, me, limit=5):
133134
count += 1
134135
if count >= limit:
135136
break
136-
except:
137-
return
137+
except Exception as e:
138+
print(str(e))
138139

139140

140141
def add_md_header(md, repo_name):
141142
with open(md, "w", encoding="utf-8") as md:
142143
md.write(MD_HEAD.format(repo_name=repo_name))
144+
md.write("\n")
143145

144146

145147
def add_md_label(repo, md, me):
146148
labels = get_repo_labels(repo)
149+
150+
# sort lables by description info if it exists, otherwise sort by name,
151+
# for example, we can let the description start with a number (1#Java, 2#Docker, 3#K8s, etc.)
152+
labels = sorted(
153+
labels,
154+
key=lambda x: (
155+
x.description is None,
156+
x.description == "",
157+
x.description,
158+
x.name,
159+
),
160+
)
161+
147162
with open(md, "a+", encoding="utf-8") as md:
148163
for label in labels:
149-
150164
# we don't need add top label again
151165
if label.name in IGNORE_LABELS:
152166
continue
@@ -231,16 +245,16 @@ def main(token, repo_name, issue_number=None, dir_name=BACKUP_DIR):
231245

232246
def save_issue(issue, me, dir_name=BACKUP_DIR):
233247
md_name = os.path.join(
234-
dir_name, f"{issue.number}_{issue.title.replace(' ', '.')}.md"
248+
dir_name, f"{issue.number}_{issue.title.replace('/', '-').replace(' ', '.')}.md"
235249
)
236250
with open(md_name, "w") as f:
237251
f.write(f"# [{issue.title}]({issue.html_url})\n\n")
238-
f.write(issue.body)
252+
f.write(issue.body or "")
239253
if issue.comments:
240254
for c in issue.get_comments():
241255
if is_me(c, me):
242256
f.write("\n\n---\n\n")
243-
f.write(c.body)
257+
f.write(c.body or "")
244258

245259

246260
if __name__ == "__main__":

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
PyGithub
1+
PyGithub==1.59.1
22
feedgen
3-
marko
3+
marko
4+
markdown

0 commit comments

Comments
 (0)