NotePlan / NotePlan/plugins

`noteplan-cli plugin:create` fails because of "missing" .gitconfig, and using different email addresses

未关闭
#271 1 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
JavaScript
星标
204
派生
82
平均合并
22 小时 27 分钟
30 天内合并 PR
3

描述

Describe the bug

I wanted to explore plugin development for fun but ran into a issues

noteplan-cli plugin:create
(node:72118) UnhandledPromiseRejectionWarning: Error: [git-user-local]: cannot find .gitconfig file on the system`

And additionally

(node:96392) UnhandledPromiseRejectionWarning: Error: Couldn't find username for `my.email@domain.com`

(with my.email@domain.com being a placeholder for my actual one)

noteplan-cli implicitly relies on the existence of the $HOME/.gitconfig in two places [3], [4], to then use the extracted email to lookup the Github username. It fails when it can't find the .gitconfig and it fails if it can't find a username.

As far as I can see that username is used at [5] to greet the user and at [6] as a default as plugin author.
Basically

This approach creates some issues for my setup

Technical issue
In my opinion the used git-user-local module has two issues:

  • The file resolution of the used module is not really correct (at least in my case). See [1] It looks under a given path, defaulting to $HOME for a .gitconfig.
  • Furthermore it parses the config file as an ini file, ignoring gitconfig constructs like include and includeIf which in my opinion are often used to switch out usernames and email addresses based on the current working directory.

My git config lives at $HOME/.config/git/config as it makes dot files managment a bit easier and makes my $HOME a lot cleaner. As outlined at [2] that location is a valid "second user-specific configuration file".

"Email" issue
I use different email addresses for projects using the git config includeIf future to switch out my email address and defaulting to my work address when I am not in any git repository. That means noteplan-cli tries to find the Github account based on my work email address which doesn't work.

"Organizational" issue
I might want to just locally experiment on a plugin without having a Github account. Since I think it's only used for [3], and [4] I don't see the hard requirement on it. A fallback on just asking for a name at [4] might be enough.

"Offline" issue
Furthermore I can't create a plugin when I am not online.

Workaround
I can work around it by symlinking ln -s $HOME/.config/git/config $HOME/.gitconfig by I would rather avoid that.

Additionally I have to change my default email address in $HOME/.config/git/config

Solutions space
I wanted to ask what a good approach would be to make it more friendly to different git config structures and "offline" usage. I see these options

  1. Instead of using the git-user-local module call git directly git config --global user.email from within node.
  2. Allow to pass a parameter to noteplan-cli
  3. Don't fail on missing git email address or Github username. Ask when it's needed

I personally would prefer a combination of 1 (addressing the technical downsides of git-user-local and 3 for the email and offline issue.

[1] https://github.com/LasaleFamine/git-user-local/blob/master/src/index.js#L8
[2] https://git-scm.com/docs/git-config#Documentation/git-config.txt-XDGCONFIGHOMEgitconfig
[3] https://github.com/NotePlan/plugins/blob/760d4e746b9d9706607ad08bda3cdf1375cc6f39/src/commands/support/plugin-create.js#L22
[4] https://github.com/NotePlan/plugins/blob/760d4e746b9d9706607ad08bda3cdf1375cc6f39/src/commands/PluginCreate.js#L60
[5] https://github.com/NotePlan/plugins/blob/760d4e746b9d9706607ad08bda3cdf1375cc6f39/src/commands/support/plugin-create.js#L25
[6] https://github.com/NotePlan/plugins/blob/760d4e746b9d9706607ad08bda3cdf1375cc6f39/src/commands/support/plugin-create.js#L44

To Reproduce
Have your git config in a XDG_CONFIG_HOME compatible location, or be offline, or don't have a Github account (at this point). Try to create plugin.

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 src/commands/support/plugin-create.js 和 src/commands/PluginCreate.js 开始,然后在使用 XDG Git 配置、没有 GitHub 账户或没有网络访问的情况下复现 noteplan-cli plugin:create。在实现和测试所选方案之前,先定义缺少 Git 配置、项目特定的电子邮件地址、不可用的 GitHub 用户名以及离线使用时的预期行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
git, github, javascript, node.js
领域
cli, developer-experience
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。