kup-cli 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ English | [中文](README.zh.md)
2
+
1
3
  # Kup
2
4
 
3
5
  <img src="https://user-images.githubusercontent.com/1231359/171321963-e8e73bdf-f9c8-435b-9707-318e92f1805a.png" width="150" height="80" align="right" alt="Kup logo">
@@ -6,134 +8,136 @@
6
8
  >
7
9
  > 这款命令行工具可以把本地的 Markdown 文件同步到 GitHub issue。
8
10
 
9
- ## 谁需要它
11
+ ## Who Is It For
10
12
 
11
- * 利用 GitHub issue 写博客的作者们,可以方便地在本地编辑原稿,并随时发布新博文或更新已有博文。
12
- * 通过 GitHub issue 发布文档的开源软件作者们,可以把代码仓库中的文档更新到指定 issue。
13
- * 其它需要频繁更新 GitHub issue 的人。
13
+ * Bloggers who publish with GitHub issues and want to edit drafts locally, then publish new posts or update existing ones at any time.
14
+ * Open-source authors who publish documentation through GitHub issues and want to sync docs from the repository to specific issues.
15
+ * Anyone else who needs to update GitHub issues frequently.
14
16
 
15
17
 
16
- ## 安装
18
+ ## Installation
17
19
 
18
- 需要全局安装,以便随时在命令行调用:
20
+ Install it globally so you can call it from the command line at any time:
19
21
 
20
22
  ```sh
21
- npm i -g kup-cli
23
+ npm install -g kup-cli
22
24
  ```
23
25
 
24
- (当 Kup 发布新版时,可以再次运行这行命令升级已安装的版本。)
26
+ (When a new version of Kup is released, run the same command again to upgrade.)
25
27
 
26
28
 
27
- ## 使用方法
29
+ ## Usage
28
30
 
29
- ### 发布新 issue
31
+ ### Publish a New Issue
30
32
 
31
33
  ```sh
32
34
  kup ./path/to/file.md --repo foo/bar
33
35
  ```
34
36
 
35
- Kup 会把 `file.md` 文件的内容发布为 `foo/bar` 仓库的一个新 issue,发布成功后会告知新 issue 的编号。
37
+ Kup will publish the content of `file.md` as a new issue in the `foo/bar` repository, and report the new issue number after it succeeds.
36
38
 
37
- ### 更新已有 issue
39
+ ### Update an Existing Issue
38
40
 
39
41
  ```sh
40
42
  kup ./path/to/file.md --repo foo/bar --id 123
41
43
  ```
42
44
 
43
- Kup 会把 `file.md` 文件的内容更新到 `foo/bar` 仓库的编号为 `123` issue。
45
+ Kup will update issue `123` in the `foo/bar` repository with the content of `file.md`.
44
46
 
45
- ### 准备工作
47
+ ### Preparation
46
48
 
47
- 操作 GitHub issue 是需要权限认证的,因此你需要向 Kup 提供 GitHub token,以便 Kup 调用 GitHub API
49
+ Updating GitHub issues requires authentication, so you need to provide a GitHub token for Kup to call the GitHub API.
48
50
 
49
- 1. GitHub 的 “[Personal access tokens](https://github.com/settings/tokens) 页面生成一个新 token,权限范围需要选中 repo”。(详细说明参见 [这篇文档](https://github.com/cssmagic/kup/issues/17)。)
51
+ 1. Create a new token on GitHub's "[Personal access tokens](https://github.com/settings/tokens)" page, and make sure the `repo` scope is selected. (See [this document](https://github.com/cssmagic/kup/issues/17) for details.)
50
52
 
51
- 2. 把获取到的 token 写入环境变量:
53
+ 2. Put the token into an environment variable:
52
54
 
53
- ```sh
54
- export GITHUB_TOKEN=ghp_**********
55
- ```
55
+ ```sh
56
+ export GITHUB_TOKEN=ghp_**********
57
+ ```
56
58
 
57
- 如果 Kup 未能从环境变量获取 token,会在命令行向你询问。
59
+ If Kup cannot read a token from the environment, it will prompt you for one in the terminal.
58
60
 
59
61
 
60
- ## 命令行参数
62
+ ## Command-Line Options
61
63
 
62
- 参数 | 短名 | 值类型 | 含义 | 备注
64
+ Option | Short | Value Type | Description | Notes
63
65
  ---|---|---|---|---
64
- `--repo` | `-r` | 字符串 | 指定 GitHub 仓库
65
- `--id` | `-i` | 整数 | 指定 issue 的编号 | <li>指定编号表示更新已有 issue<li>未指定编号则表示发布新 issue
66
- `--version` | `-v` | - | 显示版本号
67
- `--help` | `-h` | - | 显示帮助信息
66
+ `--repo` | `-r` | string | Specify the GitHub repository
67
+ `--id` | `-i` | integer | Specify the issue number | <ul><li>Providing a number means updating an existing issue<li>Omitting it means publishing a new issue</ul>
68
+ `--version` | `-v` | - | Show the version number
69
+ `--help` | `-h` | - | Show help information
68
70
 
69
71
 
70
- ## 进阶
72
+ ## Advanced
71
73
 
72
- ### 如何更方便地指定 `repo` 参数?
74
+ ### How can I specify the `repo` option more conveniently?
73
75
 
74
- 有以下方式可以指定 `repo` 参数,优先级递减:
76
+ Kup can determine the `repo` option in the following order of priority:
75
77
 
76
- 1. 调用命令行时指定的 `--repo` 参数。
77
- 1. Markdown 文件内的 [元数据](https://github.com/cssmagic/kup/issues/1) 的 `repo` 字段。
78
- 1. 当前项目的 `package.json` 文件内的 `kup.repo` 字段。Kup 会从当前目录向上逐级寻找 `package.json` 文件。
79
- 1. 如果没有 `kup.repo` 字段,则 Kup 会尝试根据 `repository` 字段来猜测仓库名(在使用前会向用户确认)。
78
+ 1. The `--repo` option passed on the command line.
79
+ 1. The `repo` field in the Markdown file's [metadata](https://github.com/cssmagic/kup/issues/1).
80
+ 1. The `kup.repo` field in the current project's `package.json`. Kup starts from the Markdown file's directory and searches upward for a `package.json` file.
81
+ 1. If `kup.repo` is not present in `package.json`, Kup will try to infer the repository name from the `repository` field and ask for confirmation before using it.
82
+ 1. If that still fails, Kup will continue searching for `.git/config` in the current or parent directories, then try to infer the repository name from the `url` field of `remote "origin"` and ask for confirmation before using it.
80
83
 
81
- 如果整个项目的同步目标都是同一个仓库,则建议采用 `kup.repo` 字段统一指定 `repo` 参数。
84
+ If the entire project syncs to the same repository, it is usually best to configure `kup.repo` in `package.json`.
82
85
 
83
- ### 如何更方便地指定 `id` 参数?
86
+ ### How can I specify the `id` option more conveniently?
84
87
 
85
- 有以下方式可以指定 `id` 参数,优先级递减:
88
+ Kup can determine the `id` option in the following order of priority:
86
89
 
87
- 1. 调用命令行时指定的 `--id` 参数。
88
- 1. Markdown 文件内的元数据的 `id` 字段。
90
+ 1. The `--id` option passed on the command line.
91
+ 1. The `id` field in the Markdown file's metadata.
89
92
 
90
- 当一个文件发布成功后,建议立即把 id 写入它的元数据。
93
+ After a file is successfully published as an issue, Kup immediately writes the `id` back into its metadata.
91
94
 
92
- ### Issue 的标题是怎么确定的?
95
+ ### How is the issue title determined?
93
96
 
94
- Kup 通过以下线索来确定 issue 的标题,优先级递减:
97
+ Kup determines the issue title using the following hints, in descending priority:
95
98
 
96
- 1. Markdown 文件内的元数据的 `title` 字段。
97
- 1. Markdown 正文的第一个标记如果是一级标题(`# Title` 格式),则取它的内容(在这种情况下,这个一级标题在同步时会从内容中排除)。
99
+ 1. The `title` field in the Markdown file's metadata.
100
+ 1. If the first Markdown block is an H1 heading (in `# Title` form), Kup uses its text as the title. In this case, that H1 heading is excluded from the synced content.
98
101
 
99
- 如果通过以上方式无法确定 issue 标题,Kup 会怎么处理?
102
+ What happens if Kup still cannot determine the issue title?
100
103
 
101
- * 如果是在发布新 issue,则 Kup 会自己生成一个标题。
102
- * 如果是在更新已有 issue,则 Kup 会忽略标题(也就是说,不会修改已有标题)。
104
+ * When publishing a new issue, Kup generates a title automatically.
105
+ * When updating an existing issue, Kup ignores the title, which means the existing title will not be changed.
103
106
 
104
- ### 如何为 issue 指定 label?
107
+ ### How do I assign labels to an issue?
105
108
 
106
- 不论是在写博客,还是在发表 issue,你常常都会有打标签的需求。于是 Kup 也实现了这个功能。
109
+ Whether you are blogging or publishing regular issues, labels are often useful, so Kup supports them as well.
107
110
 
108
- 你需要在 Markdown 文件的元数据中添加 `tags` 字段,指定一个或多个 label。这些 label 不需要事先在 GitHub 仓库里创建好——如果你指定了不存在的 label,会在发布 issue 时自动创建。
111
+ Add a `tags` field to the Markdown file's metadata and specify one or more labels. These labels do not need to exist in the GitHub repository beforehand. If a label does not already exist, it will be created automatically when the issue is published.
109
112
 
110
- 如果元数据中没有 `tags` 字段,Kup 会怎么处理?
113
+ What happens if there is no `tags` field in the metadata?
111
114
 
112
- * 如果是在发布新 issue,则 Kup 不会为 issue 设置任何 label。
113
- * 如果是在更新已有 issue 时,Kup 会忽略标签(也就是说,不会修改已有标签)。
115
+ * When publishing a new issue, Kup will not assign any labels.
116
+ * When updating an existing issue, Kup ignores labels, which means the existing labels will not be changed.
114
117
 
115
- 在更新已有 issue 时,如果元数据指定的标签与 issue 现有标签不一致,则前者会完全替代后者。
118
+ When updating an existing issue, if the labels specified in the metadata differ from the issue's current labels, the new set completely replaces the old one.
116
119
 
117
- ## 文档
120
+ ## Documentation
118
121
 
119
- * [Markdown 文件内的元数据示例](https://github.com/cssmagic/kup/issues/1)
120
- * [如何为 Kup 生成合适的 GitHub token](https://github.com/cssmagic/kup/issues/17)
122
+ * [Metadata examples for Markdown files](https://github.com/cssmagic/kup/issues/1)
123
+ * [How to generate an appropriate GitHub token for Kup](https://github.com/cssmagic/kup/issues/17)
121
124
 
122
125
 
123
- ## 其它
126
+ ## Other
124
127
 
125
- ### 开发计划
128
+ ### Roadmap
126
129
 
127
- 请参考 [本项目的 issue](https://github.com/cssmagic/kup/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc)。欢迎提出你的需求,或参与 RFC 讨论。
130
+ * See [the issue list for this project](https://github.com/cssmagic/kup/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc) for current plans.
131
+ * Feature requests and RFC discussions are welcome.
128
132
 
129
- ### 关于名字
133
+ ### About the Name
130
134
 
131
- * Kup 取自 “皮卡” 的英文词 pickup,喻意是 “轻便地运载”。
132
- * Kup 是变形金刚人物 “杯子” 的英文名。
135
+ * Kup comes from the English word "pickup", suggesting lightweight transport.
136
+ * Kup is also a character in *Transformers*.
133
137
 
134
- ### 关于 Logo
138
+ ### About the Logo
135
139
 
136
- * 作者 [Fasil](https://freeicons.io/profile/722),由 [freeicons.io](https://freeicons.io/icon/e-commerce-icons/pickup-truck-icon-26893) 免费提供。
140
+ * The logo was created by [Fasil](https://freeicons.io/profile/722) and provided for free via [freeicons.io](https://freeicons.io/icon/e-commerce-icons/pickup-truck-icon-26893).
137
141
 
138
142
  ***
139
143
 
@@ -141,6 +145,6 @@ Kup 通过以下线索来确定 issue 的标题,优先级递减:
141
145
 
142
146
  > Any code contributed to this project is considered authorized for commercial use by the project authors and their affiliated companies and distributed under this project's license.
143
147
  >
144
- > 任何贡献到本项目的代码,均视为授权本项目作者及其名下公司用于商业用途、并按本项目协议分发。
148
+ > 任何贡献到本项目的代码,均视为授权本项目作者及其关联公司用于商业用途,并可按本项目协议进行分发。
145
149
 
146
150
  MIT
package/README.zh.md ADDED
@@ -0,0 +1,150 @@
1
+ [English](README.md) | 中文
2
+
3
+ # Kup
4
+
5
+ <img src="https://user-images.githubusercontent.com/1231359/171321963-e8e73bdf-f9c8-435b-9707-318e92f1805a.png" width="150" height="80" align="right" alt="Kup logo">
6
+
7
+ > A CLI tool to sync local Markdown files to GitHub issues.
8
+ >
9
+ > 这款命令行工具可以把本地的 Markdown 文件同步到 GitHub issue。
10
+
11
+ ## 谁需要它
12
+
13
+ * 利用 GitHub issue 写博客的作者们,可以方便地在本地编辑原稿,并随时发布新博文或更新已有博文。
14
+ * 通过 GitHub issue 发布文档的开源软件作者们,可以把代码仓库中的文档更新到指定 issue。
15
+ * 其它需要频繁更新 GitHub issue 的人。
16
+
17
+
18
+ ## 安装
19
+
20
+ 需要全局安装,以便随时在命令行调用:
21
+
22
+ ```sh
23
+ npm install -g kup-cli
24
+ ```
25
+
26
+ (当 Kup 发布新版时,可以再次运行这行命令升级已安装的版本。)
27
+
28
+
29
+ ## 使用方法
30
+
31
+ ### 发布新 issue
32
+
33
+ ```sh
34
+ kup ./path/to/file.md --repo foo/bar
35
+ ```
36
+
37
+ Kup 会把 `file.md` 文件的内容发布为 `foo/bar` 仓库的一个新 issue,发布成功后会告知新 issue 的编号。
38
+
39
+ ### 更新已有 issue
40
+
41
+ ```sh
42
+ kup ./path/to/file.md --repo foo/bar --id 123
43
+ ```
44
+
45
+ Kup 会把 `file.md` 文件的内容更新到 `foo/bar` 仓库的编号为 `123` 的 issue。
46
+
47
+ ### 准备工作
48
+
49
+ 操作 GitHub issue 是需要权限认证的,因此你需要向 Kup 提供 GitHub token,以便 Kup 调用 GitHub API。
50
+
51
+ 1. 在 GitHub 的 “[Personal access tokens](https://github.com/settings/tokens)” 页面生成一个新 token,权限范围需要选中 “repo”。(详细说明参见 [这篇文档](https://github.com/cssmagic/kup/issues/17)。)
52
+
53
+ 2. 把获取到的 token 写入环境变量:
54
+
55
+ ```sh
56
+ export GITHUB_TOKEN=ghp_**********
57
+ ```
58
+
59
+ 如果 Kup 未能从环境变量获取 token,会在命令行向你询问。
60
+
61
+
62
+ ## 命令行参数
63
+
64
+ 参数 | 短名 | 值类型 | 含义 | 备注
65
+ ---|---|---|---|---
66
+ `--repo` | `-r` | 字符串 | 指定 GitHub 仓库
67
+ `--id` | `-i` | 整数 | 指定 issue 的编号 | <ul><li>指定编号表示更新已有 issue<li>未指定编号则表示发布新 issue</ul>
68
+ `--version` | `-v` | - | 显示版本号
69
+ `--help` | `-h` | - | 显示帮助信息
70
+
71
+
72
+ ## 进阶
73
+
74
+ ### 如何更方便地指定 `repo` 参数?
75
+
76
+ 有以下方式可以指定 `repo` 参数,优先级递减:
77
+
78
+ 1. 调用命令行时指定的 `--repo` 参数。
79
+ 1. Markdown 文件内的 [元数据](https://github.com/cssmagic/kup/issues/1) 的 `repo` 字段。
80
+ 1. 当前项目的 `package.json` 文件内的 `kup.repo` 字段。Kup 会以 Markdown 文件所在目录为起点逐级向上寻找 `package.json` 文件。
81
+ 1. 如果 `package.json` 文件内没有 `kup.repo` 字段,则 Kup 会尝试根据 `repository` 字段来猜测仓库名(在使用前会向用户确认)。
82
+ 1. 如果以上方式都没有成功,则 Kup 会继续查找同级或上级目录中的 `.git/config` 文件,并尝试根据其中 `remote "origin"` 的 `url` 字段来猜测仓库名(在使用前会向用户确认)。
83
+
84
+ 如果整个项目的同步目标都是同一个仓库,通常建议在 `package.json` 里统一配置 `kup.repo`。
85
+
86
+ ### 如何更方便地指定 `id` 参数?
87
+
88
+ 有以下方式可以指定 `id` 参数,优先级递减:
89
+
90
+ 1. 调用命令行时指定的 `--id` 参数。
91
+ 1. Markdown 文件内的元数据的 `id` 字段。
92
+
93
+ 当一个文件成功发布为 issue 后,Kup 会立即把 `id` 写入它的元数据中。
94
+
95
+ ### Issue 的标题是如何确定的?
96
+
97
+ Kup 会通过以下线索来确定 issue 的标题,优先级递减:
98
+
99
+ 1. Markdown 文件内的元数据的 `title` 字段。
100
+ 1. Markdown 正文的第一个标记如果是一级标题(`# Title` 格式),则取它的内容(在这种情况下,这个一级标题在同步时会从内容中排除)。
101
+
102
+ 如果通过以上方式无法确定 issue 标题,Kup 会怎么处理?
103
+
104
+ * 如果是在发布新 issue,则 Kup 会自己生成一个标题。
105
+ * 如果是在更新已有 issue,则 Kup 会忽略标题(也就是说,不会修改已有标题)。
106
+
107
+ ### 如何为 issue 指定 label?
108
+
109
+ 不论是在写博客,还是在发表 issue,你常常都会有打标签的需求。因此 Kup 也实现了这个功能。
110
+
111
+ 你需要在 Markdown 文件的元数据中添加 `tags` 字段,指定一个或多个 label。这些 label 不需要事先在 GitHub 仓库里创建好——如果你指定了不存在的 label,会在发布 issue 时自动创建。
112
+
113
+ 如果元数据中没有 `tags` 字段,Kup 会怎么处理?
114
+
115
+ * 如果是在发布新 issue,则 Kup 不会为 issue 设置任何 label。
116
+ * 如果是在更新已有 issue 时,Kup 会忽略标签(也就是说,不会修改已有标签)。
117
+
118
+ 在更新已有 issue 时,如果元数据指定的标签与 issue 现有标签不一致,则前者会完全替代后者。
119
+
120
+ ## 文档
121
+
122
+ * [Markdown 文件内的元数据示例](https://github.com/cssmagic/kup/issues/1)
123
+ * [如何为 Kup 生成合适的 GitHub token](https://github.com/cssmagic/kup/issues/17)
124
+
125
+
126
+ ## 其它
127
+
128
+ ### 开发计划
129
+
130
+ * 请参考 [本项目的 issue 列表](https://github.com/cssmagic/kup/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc) 来了解当前规划。
131
+ * 欢迎提交需求,或参与 RFC 讨论。
132
+
133
+ ### 关于名字
134
+
135
+ * Kup 取自 “皮卡” 的英文词 pickup,喻意是 “轻便地运载”。
136
+ * Kup 是变形金刚人物 “杯子” 的英文名。
137
+
138
+ ### 关于 Logo
139
+
140
+ * Logo 由 [Fasil](https://freeicons.io/profile/722) 创作,并通过 [freeicons.io](https://freeicons.io/icon/e-commerce-icons/pickup-truck-icon-26893) 免费提供。
141
+
142
+ ***
143
+
144
+ ## License
145
+
146
+ > Any code contributed to this project is considered authorized for commercial use by the project authors and their affiliated companies and distributed under this project's license.
147
+ >
148
+ > 任何贡献到本项目的代码,均视为授权本项目作者及其关联公司用于商业用途,并可按本项目协议进行分发。
149
+
150
+ MIT
package/lib/main.js CHANGED
@@ -56,7 +56,7 @@ async function main(argv) {
56
56
  {
57
57
  name: 'useGuessedRepo',
58
58
  type: 'confirm',
59
- message: `Kup guessed the GitHub repo "${ repoResult.repo }" from package.json#repository, use it?`,
59
+ message: `Kup guessed the GitHub repo "${ repoResult.repo }" from ${ getRepoSourceLabel(repoResult.source) }, use it?`,
60
60
  default: true,
61
61
  },
62
62
  ])
@@ -91,6 +91,17 @@ async function main(argv) {
91
91
  }
92
92
  }
93
93
 
94
+ function getRepoSourceLabel(source = '') {
95
+ switch (source) {
96
+ case 'package.repository':
97
+ return 'package.json#repository'
98
+ case 'git.origin':
99
+ return '.git/config remote "origin"'
100
+ default:
101
+ return 'an inferred source'
102
+ }
103
+ }
104
+
94
105
  export {
95
106
  main,
96
107
  }
package/lib/repo.js CHANGED
@@ -1,3 +1,4 @@
1
+ import fs from 'fs/promises'
1
2
  import { findUp } from 'find-up'
2
3
  import path from 'path'
3
4
 
@@ -6,38 +7,44 @@ import { validateRepo } from './validate.js'
6
7
 
7
8
  async function getRepo(sourceFile = '') {
8
9
  const json = await _getPkg(sourceFile)
9
- if (!json) {
10
- return {
11
- repo: '',
12
- source: '',
13
- needsConfirm: false,
10
+
11
+ if (json) {
12
+ const packageRepo = _getRepoFromPkgKup(json)
13
+ if (packageRepo.repo) {
14
+ return {
15
+ repo: packageRepo.repo,
16
+ source: 'package',
17
+ needsConfirm: false,
18
+ }
14
19
  }
15
- }
16
20
 
17
- const packageRepo = _getRepoFromPkgKup(json)
18
- if (packageRepo.hasRepoField) {
19
- return {
20
- repo: packageRepo.repo,
21
- source: packageRepo.repo ? 'package' : '',
22
- needsConfirm: false,
21
+ if (!packageRepo.hasKupRepoField) {
22
+ const guessedRepo = _getRepoFromPkgRepo(json)
23
+ if (guessedRepo) {
24
+ return {
25
+ repo: guessedRepo,
26
+ source: 'package.repository',
27
+ needsConfirm: true,
28
+ }
29
+ }
23
30
  }
24
31
  }
25
32
 
26
- const guessedRepo = _getRepoFromPkgRepo(json)
33
+ const guessedRepo = await _getRepoFromGit(sourceFile)
27
34
  return {
28
35
  repo: guessedRepo,
29
- source: guessedRepo ? 'package.repository' : '',
36
+ source: guessedRepo ? 'git.origin' : '',
30
37
  needsConfirm: !!guessedRepo,
31
38
  }
32
39
  }
33
40
 
34
41
  function _getRepoFromPkgKup(json) {
35
- const hasRepoField = !!json?.kup && Object.prototype.hasOwnProperty.call(json.kup, 'repo')
42
+ const hasKupRepoField = !!json?.kup && Object.prototype.hasOwnProperty.call(json.kup, 'repo')
36
43
  const repo = json?.kup?.repo
37
44
  const result = validateRepo(repo)
38
45
  return {
39
46
  repo: result.status ? repo : '',
40
- hasRepoField,
47
+ hasKupRepoField,
41
48
  }
42
49
  }
43
50
  function _getRepoFromPkgRepo(json) {
@@ -54,8 +61,18 @@ function _getRepoFromPkgRepo(json) {
54
61
 
55
62
  return ''
56
63
  }
57
- async function _getRepoFromGit() {
58
- // TODO
64
+ async function _getRepoFromGit(sourceFile = '') {
65
+ const configFile = await _getGitConfigFile(sourceFile)
66
+ if (!configFile) return ''
67
+
68
+ let config = ''
69
+ try {
70
+ config = await readTextFile(configFile)
71
+ } catch {
72
+ return ''
73
+ }
74
+
75
+ return _getRepoFromGitConfig(config)
59
76
  }
60
77
 
61
78
  async function _getPkg(sourceFile = '') {
@@ -81,6 +98,58 @@ async function _getPkg(sourceFile = '') {
81
98
  return json
82
99
  }
83
100
 
101
+ async function _getGitConfigFile(sourceFile = '') {
102
+ let cwd = sourceFile ? path.resolve(path.dirname(sourceFile)) : process.cwd()
103
+ while (true) {
104
+ const gitPath = path.join(cwd, '.git')
105
+
106
+ try {
107
+ const stats = await fs.stat(gitPath)
108
+ if (stats.isDirectory()) {
109
+ const configFile = path.join(gitPath, 'config')
110
+ try {
111
+ await fs.access(configFile)
112
+ return configFile
113
+ } catch {
114
+ return ''
115
+ }
116
+ }
117
+ return ''
118
+ } catch {
119
+ const parent = path.dirname(cwd)
120
+ if (parent === cwd) return ''
121
+ cwd = parent
122
+ }
123
+ }
124
+ }
125
+
126
+ function _getRepoFromGitConfig(config) {
127
+ if (typeof config !== 'string' || !config.trim()) return ''
128
+
129
+ const lines = config.split(/\r?\n/)
130
+ let inOriginRemote = false
131
+ for (const line of lines) {
132
+ const trimmed = line.trim()
133
+ if (!trimmed || trimmed.startsWith('#') || trimmed.startsWith(';')) continue
134
+
135
+ const sectionMatched = /^\[\s*(.*?)\s*\]$/.exec(trimmed)
136
+ if (sectionMatched) {
137
+ inOriginRemote = /^remote\s+"origin"$/i.test(sectionMatched[1])
138
+ continue
139
+ }
140
+ if (!inOriginRemote) continue
141
+
142
+ const entryMatched = /^([A-Za-z][\w-]*)\s*=\s*(.*?)\s*$/.exec(trimmed)
143
+ if (!entryMatched) continue
144
+
145
+ const key = entryMatched[1].toLowerCase()
146
+ const value = entryMatched[2]
147
+ if (key === 'url') return normalizeRepositoryToRepo(value)
148
+ }
149
+
150
+ return ''
151
+ }
152
+
84
153
  function normalizeRepositoryToRepo(repository) {
85
154
  if (typeof repository !== 'string') return ''
86
155
 
@@ -111,6 +180,7 @@ export {
111
180
  getRepo,
112
181
  _getRepoFromPkgKup as __getRepoFromPkgKup,
113
182
  _getRepoFromPkgRepo as __getRepoFromPkgRepo,
114
- // __getRepoFromGit: _getRepoFromGit,
183
+ _getRepoFromGit as __getRepoFromGit,
184
+ _getRepoFromGitConfig as __getRepoFromGitConfig,
115
185
  normalizeRepositoryToRepo as __normalizeRepositoryToRepo,
116
186
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kup-cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "A CLI tool to sync local Markdown files to GitHub issues.",
5
5
  "type": "module",
6
6
  "bin": {