mattduck/gh2md
GitHub: mattduck/gh2md
将 GitHub 仓库的 issue、pull request 及评论导出为可读 Markdown 文件的命令行工具。
Stars: 315 | Forks: 49
# gh2md
|PyPI|
将 GitHub 仓库的 issue 和 pull request 导出为易读的 Markdown
文件。你可以选择为仓库创建单个文件,或者创建一个目录并为每个
issue 生成一个文件。有关如何按 issue 类型和状态进行过滤,请参阅使用说明。
目前还有许多其他项目可以处理 GitHub issue 导出
(例如:`offline-issues `_),但我
找不到一个能将所有 issue、评论和元数据写入同一个
易读文件中的工具。
## 导出示例
- `examples 目录 `_ 中的基础导出。
- `每个文件包含一个 issue 的示例目录 `_
- gh2md `自身 issue 的单文件导出 <./issues.md>`_。
默认行为是导出所有 issue 和 PR。
## 用法
运行 ``paulirish/git-open`` 的导出,从环境变量中获取 token,并排除已关闭的 PR:::
```
export GITHUB_ACCESS_TOKEN=myAPItoken
gh2md paulirish/git-open git-open.md --no-closed-prs
```
运行 ``shezadkhan137/required`` 的导出,从文件中获取 token,并排除已关闭的 issue:::
```
echo myAPItoken > ~/.config/gh2md/token
gh2md shezadkhan137/required required.md --no-closed-issues
```
运行公共仓库 ``sarabander/sicp`` 的导出,不使用身份验证且每个 issue 单独生成一个文件:::
```
gh2md sarabander/sicp sicp-issues --multiple-files --no-closed-prs
```
运行 GitHub Enterprise Server 或自定义 GitHub 实例的导出:::
```
export GITHUB_API_URL=https://github.example.com/api/graphql
export GITHUB_ACCESS_TOKEN=myAPItoken
gh2md owner/repo-name output.md
```
完整帮助信息:::
```
usage: gh2md [-h] [--multiple-files] [-I] [--no-prs] [--no-closed-prs]
[--no-issues] [--no-closed-issues]
[--file-extension FILE_EXTENSION]
repo output_path
Export Github repository issues, pull requests and comments to markdown files:
https://github.com/mattduck/gh2md
Example: gh2md mattduck/gh2md my_issues.md
Credentials are resolved in the following order:
- A `GITHUB_ACCESS_TOKEN` environment variable.
- An API token stored in ~/.config/gh2md/token or ~/.github-token.
You can override the GitHub API endpoint by setting the `GITHUB_API_URL` environment
variable. This defaults to "https://api.github.com/graphql" and requires no change when using github.com.
To access private repositories, you'll need a token with the full "repo" oauth
scope.
By default, all issues and pull requests will be fetched. You can disable these
using the --no... flags, eg. --no-closed-prs, or --no-prs.
positional arguments:
repo Github repo to export, in format "owner/repo_name".
output_path Path to write exported issues.
optional arguments:
-h, --help show this help message and exit
--multiple-files Instead of one file, treat the given path as a
directory, and create one file per issue, using a
format '{created_at}.{issue_number}.{issue_type}.{issu
e_state}{file_extension}'.
-I, --idempotent Remove non-deterministic values like timestamps. Two
runs of gh2md will always produce the same result, as
long as the Github data has not changed.
--no-prs Don't include pull requests in the export.
--no-closed-prs Don't include closed pull requests in the export.
--no-issues Don't include issues in the export.
--no-closed-issues Don't include closed issues in the export.
--file-extension FILE_EXTENSION
File extension for output files. Default is '.md'.
```
## 安装
你可以使用 ``pip install gh2md``,或者使用 ``pipx install gh2md`` 安装到独立环境中。或者,克隆本仓库并运行 ``make install``。
## 身份验证
``gh2md`` 需要一个 GitHub 访问 token 来验证请求。要读取你的
私有仓库,你需要提供一个具有完整 **repo** oauth 权限的个人访问 token。
**无法使用用户名和密码进行身份验证**。GitHub 过去
支持这种方式,但在 2020 年已被停用。
## 支持私有 GitHub 服务器
``gh2md`` 支持 GitHub Enterprise Server 实例,允许你覆盖
API 端点 URL。请将 ``GITHUB_API_URL`` 环境变量指向
你的 GitHub Enterprise Server GraphQL API 端点。
配合 GitHub Enterprise Server 使用:::
```
export GITHUB_API_URL=https://github.example.com/api/graphql
export GITHUB_ACCESS_TOKEN=myAPItoken
gh2md owner/repo-name output.md
```
如果未指定 ``GITHUB_API_URL``,则默认为 ``https://api.github.com/graphql``。
## GitHub 工作流:将 issue 作为 Markdown 文件备份到你的仓库中
`@0ut0fcontrol `_ 贡献了一个 GitHub 工作流,
该工作流使用 ``gh2md`` 每晚导出到 ``issues.md``,并将其推送回
你的仓库。你可以 `在此处
`_ 找到相关讨论和工作流代码。
你可以在 `gh2md` 仓库中查看过往的导出示例,
导出文件位于 `issues.md <./issues.md>`_。
.. |PyPI| image:: https://img.shields.io/pypi/v/gh2md.svg
:target: https://pypi.python.org/pypi/gh2md
标签:Blue Team, Markdown, 备份, 威胁情报, 导出工具, 开发者工具, 逆向工具