Repository: pwntester/octo.nvim (lua)

Issue:
Config: ssh_aliases not capture correctly hostname with hyphen
When using the ssh_aliases configuration option, the hyphen character is not handled correctly. This causes the ssh_aliases to be ignored and the default ssh_aliases to be used instead. This issue is caused by the way the ssh_aliases configuration option is parsed. The hyphen character is not escaped properly, which causes the parser to interpret it as a command line option instead of a value. This issue can be fixed by escaping the hyphen character properly when parsing the ssh_aliases configuration option. 

If i have this config:

```lua
require 'octo'.setup {
  ssh_aliases = { ["github.com-work"] = "github.com" },
}
```

When i execute Octo ccommand, the ssh_aliases are not used and the default ssh_aliases are used instead. This throw an error:

<img src="https://richardhapb.s3.us-east-2.amazonaws.com/personal/gh/octos_hyphen.png" width="600" alt="hyphen issue" />

I will send a PR to fix this issue.

Pull request description:
### Describe what this PR does / why we need it

This change fixes the issue where the hyphen in the ssh_aliases replacement is not escaped. This causes the replacement to fail when the alias contains a hyphen.

The second change is related to issue #838, where the check for nil values are not working as expected. I have added a check for nil to author.user.

### Does this pull request fix one issue?

Fixes #836
Fixes #838

### Describe how you did it

In parse_remote_url function, I have added a `%` before the hyphen in the ssh_aliases replacement.

In write_commit_event function, I have added a check for nil to author.user.

### Describe how to verify it

Test with an ssh alias that contains a hyphen, for example github.com-work
Test with a nil value for author.user

### Special notes for reviews

Little changes

### Checklist

- [X] Passing tests and linting standards
- [X] Documentation updates in README.md and doc/octo.txt

Patch:
diff --git a/lua/octo/ui/writers.lua b/lua/octo/ui/writers.lua
index caa1ac3cc..8d9bb07be 100644
--- a/lua/octo/ui/writers.lua
+++ b/lua/octo/ui/writers.lua
@@ -1347,7 +1347,7 @@ function M.write_commit_event(bufnr, item)
       item.commit.committer.user.login,
       item.commit.committer.user.login == vim.g.octo_viewer and "OctoUserViewer" or "OctoUser",
     })
-  elseif item.commit.author ~= vim.NIL then
+  elseif item.commit.author ~= vim.NIL and item.commit.author.user ~= vim.NIL then
     table.insert(vt, {
       item.commit.author.user.login,
       item.commit.author.user.login == vim.g.octo_viewer and "OctoUserViewer" or "OctoUser",
diff --git a/lua/octo/utils.lua b/lua/octo/utils.lua
index 60ddaacb8..2d68578d5 100644
--- a/lua/octo/utils.lua
+++ b/lua/octo/utils.lua
@@ -221,6 +221,7 @@ function M.parse_remote_url(url, aliases)
   end
 
   for alias, rhost in pairs(aliases) do
+    alias = alias:gsub("%-", "%%-")
     host = host:gsub("^" .. alias .. "$", rhost, 1)
   end
   if not M.is_blank(host) and not M.is_blank(repo) then


Test patch:
diff --git a/lua/tests/plenary/utils_spec.lua b/lua/tests/plenary/utils_spec.lua
index be964c657..f2a9b7abe 100644
--- a/lua/tests/plenary/utils_spec.lua
+++ b/lua/tests/plenary/utils_spec.lua
@@ -67,3 +67,55 @@ describe("Utils escape_char(): ", function()
     eq(expected, this.escape_char(input))
   end)
 end)
+
+describe("Utils parse_remote_url(): ", function()
+  it("Should replace remote url with alias", function()
+    local ssh_aliases = {
+      ["github.com-work"] = "github.com",
+    }
+    local url = "git@github.com-work:pwntester/octo.nvim.git"
+
+    local expected = {
+      host = "github.com",
+      repo = "pwntester/octo.nvim",
+    }
+
+    eq(expected, this.parse_remote_url(url, ssh_aliases))
+  end)
+
+  it("Should replace multiple hyphens in remote url with alias", function()
+    local ssh_aliases = {
+      ["github.com-octo-work"] = "github.com",
+    }
+    local url = "git@github.com-octo-work:pwntester/octo.nvim.git"
+
+    local expected = {
+      host = "github.com",
+      repo = "pwntester/octo.nvim",
+    }
+
+    eq(expected, this.parse_remote_url(url, ssh_aliases))
+  end)
+
+  it("Should not replace remote url with alias", function()
+    local url = "git@github.com-work:pwntester/octo.nvim.git"
+    local expected = {
+      host = "github.com-work",
+      repo = "pwntester/octo.nvim",
+    }
+
+    eq(expected, this.parse_remote_url(url, {}))
+  end)
+
+  it("Should keep the original url", function()
+    local ssh_aliases = {
+      ["github.com-work"] = "github.com",
+    }
+    local url = "git@github.com:pwntester/octo.nvim.git"
+    local expected = {
+      host = "github.com",
+      repo = "pwntester/octo.nvim",
+    }
+    eq(expected, this.parse_remote_url(url, ssh_aliases))
+  end)
+end)