#11 Issue closed
: A github actions example to extract issues of the repo itself
jcyang opened issue at 2020-07-16 07:42:
Thank you for your great work.
I add my github actions example here, in case someone needs it.
it backups all issues every day.
Because it only backup the issues belong to the repository that contains this workflow. It does not limit by the GitHub API rate.
# gh2md log:
...
Writing to file: issues.md
Github API rate limit: RateLimit(core=Rate(reset=2020-09-17 02:50:05, remaining=977, limit=1000))
Done.
# .github/workflows/issues2md.yml
name: Issues2Markdown
on:
push: # comment it to reduce update.
schedule:
# every day
- cron: "0 0 * * *"
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
with:
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
fetch-depth: 0 # otherwise, you will failed to push refs to dest repo
- name: Backup github issues to a markdown file.
run: |
pip3 install --user --upgrade setuptools
pip3 install --user gh2md
$HOME/.local/bin/gh2md $GITHUB_REPOSITORY issues.md --token ${{ secrets.GITHUB_TOKEN }}
git add issues.md
- name: Commit files
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git commit -m "Backup all issues into issues.md" -a
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ steps.extract_branch.outputs.branch }}
Matt Duck commented at 2020-07-16 21:24:
@0ut0fcontrol thanks for sharing this, it's super cool! I'll find somewhere sensible to publicise it - at least link to it from the README. I think I should set it up for gh2md itself.
I'm glad this is useful for you and still working OK. I haven't used it much recently, so I'm not sure if there are any problems or obvious features that would help - feel free to open issues if you do have anything.
jcyang commented at 2020-07-17 06:34:
@mattduck gh2md
works well. If I found any problems or features I will open a issues for it.
My purpose is to backup my repo with issues.
And the issues is readable even when I do not has access to github.com.
Combining gh2md
and pandoc --self-contained
served my purpose.
(I am not test other tools yet, this may not be the best way to do this.)
Here is a script to setup crontab to fetch repos and convert issues.md
to issues.html
.
#!/bin/bash
# crontab -e
# 0 1 * * * bash path_to/backup_issues/backup_issues.sh &> path_to/backup_issues/backup_issues.sh.log
# backup_issues
# ├── backup_issues.sh
# ├── repo1
# ├── repo2
# └── repo3
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
for i in $DIR/*/; do
date
cd $i
pwd
git fetch --all --verbose
git pull
test -f issues.md && pandoc --self-contained issues.md -o issues.html --metadata title=backup_issues
test -f issues.html && echo "backup issues in ${i}issues.html"
echo "#############################################################################"
done
Matt Duck commented at 2020-07-19 06:22:
@0ut0fcontrol I've added this to the repo now - worked fine first time. Thanks again!
If I get some time soon, I'll add a flag to optionally remove the timestamp message in the file - this way you'll only get a commit if the content has changed, instead of a new commit on every run due to the unique timestamp.
jcyang commented at 2020-07-19 17:30:
@mattduck Thank you.
It seems that gh2md
doesn't download closed PR.
Is it an expected behavior?
Matt Duck commented at 2020-07-19 19:59:
@0ut0fcontrol I've just fixed that. Back when I wrote this I didn't need to export closed PRs, and for some reason instead of making it configurable I just hardcoded it.
I've updated the default behaviour to fetch everything by default. You can selectively disable parts with --no-closed-prs
, --no-closed-issues
, --no-prs
or --no-issues
.
Matt Duck commented at 2020-07-19 20:02:
I'm gonna close this issue just so I know that there's no work to do on it. Will leave it pinned though.
吕立青 commented at 2020-09-16 11:44:
The workflow always has this issue, is that because I am using Chinese?
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)
jcyang commented at 2020-09-17 02:23:
@JimmyLv Yes, gh2md with python2 can not process issues with Chinese characters. Using python3 will solve this problem, see https://github.com/0ut0fcontrol/jimmylv.github.io/commit/76a967c741a2fa6fa1080c3b631228efe1205974.
I will update the example in this issue and create a PR to modify issues2md.yml
in gh2md
.
[Export of Github issue for mattduck/gh2md. Generated on 2021.06.27 at 12:04:30.]