seagle0128 / doom-modeline

A fancy and fast mode-line inspired by minimalism design.
https://seagle0128.github.io/doom-modeline/
GNU General Public License v3.0
1.29k stars 159 forks source link

[Bug] GitHub notifications are not showing #643

Closed grolongo closed 1 year ago

grolongo commented 1 year ago

Thank you for the bug report

Bug description

Hello,

I'm trying to use the GitHub notification option in the mode-line but nothing happens.

I have Magit installed with Forge and my token is setup correctly in .authinfo.gpg
Everything works fine with Magit, I can interact with my repos without problems.

I double checked to make sure that async and ghub packages are installed and they are.

What's odd is I don't have any messages or errors letting me know that there is an issue or something,
so I have no idea if it's a misconfiguration or a bug.
I created an issue on a test repo with another account to push a notification, but nothing.

Did I miss something?

Steps to reproduce

This is my trivial doom-modeline configuration, note that I'm NOT using Doom Emacs, just vanilla+doom-modeline.

(use-package doom-modeline
  :ensure t
  :custom
  (doom-modeline-github t)
  (doom-modeline-github-interval (* 1 60))
  (doom-modeline-icon nil)
  :config (doom-modeline-mode 1))

I changed the interval timer to one minute just for testing.
I also tried with doom-modeline-icon t just in case but nothing.

Expected behavior

I should receive notifications or at least an error message if something is wrong or misconfigured from my side.

OS

MacOS

Emacs Version

28 (gccemacs)

Emacs Configurations

Emacs 28.2 (vanilla)

Error callstack

No response

Anything else

No response

seagle0128 commented 1 year ago

Please make sure notifications is enabled in your personal token.

image
grolongo commented 1 year ago

Hi @seagle0128,

Indeed, I didn't have notifications ticked in the token settings, now fixed:

img

But still, it seems I'm not able to get notifications.
Do I need to write a specific username or anything in my ~/.emacs.d/authinfo.gpg?
This is the line I have which works with Magit Forge: machine api.github.com login grolongo^forge password ghp_myGITHUBtokenAbCdEfGhIjLmNoP

do I need to change anything? thanks for the help.

seagle0128 commented 1 year ago

Try adding this snippet and upgrade to the latest.

machine api.github.com login grolongo^ghub password ghp_myGITHUBtokenAbCdEfGhIjLmNoP

grolongo commented 1 year ago

I updated to latest commit and changed login to grolongo^ghub.
I can now see the icon in the mode-line.
Left-click opens up the browser with the github.com page showing my pending notification(s), but I don't think it does any fetching at all in Emacs.
I don't see any numbers next to the icon in the mode-line, despite creating multiple issues, comments, on a test repo right now.
Also when I right-click the icon, it echoes "Fetching GitHub notifications..." and then nothing.
And it looks it does that only when I manually right-click it, not automatically with doom-modeline-github-interval.

For info I'm testing all this on both macOS and Windows, if that's of any importance.

seagle0128 commented 1 year ago

The ghub returns errors while fetching nofitications. See https://github.com/magit/ghub/issues/162.

seagle0128 commented 1 year ago

Please try the latest version. I tested and worked well. Closing it.

benthamite commented 11 months ago

I didn’t know whether to create a new issue for this since I’m experiencing the problem as @grolongo. I have async and ghub installed, a personal token that includes notifications permissions,

image

and a working Magit/Forge configuration that is able to get notifications without a problem.

image

Yet the value of doom-modeline--github-notification-number is 0, even after right-clicking on the GitHub icon and seeing the “Fetching GitHub notifications...” message.

Is there anything I can do to help diagnose the issue?

seagle0128 commented 11 months ago

@benthamite I tested just now, and it worked for me. According to the tests by the author of ghub, the codes were correct. You can check the results with this snippet on your env.

      (when (require 'ghub nil t)
          (with-timeout (10)
            (ignore-errors
              (when-let* ((username (ghub--username ghub-default-host))
                          (token (or (ghub--token ghub-default-host username 'forge t)
                                     (ghub--token ghub-default-host username 'ghub t))))
                (ghub-get "/notifications"
                          '((notifications . t))
                          :host ghub-default-host
                          :username username
                          :auth token
                          :unpaginate t
                          :noerror t)))))
benthamite commented 11 months ago

Thanks for the reply.

The snippet does indeed work correctly. I see that the code is part of doom-modeline--github-fetch-notifications:

(defun doom-modeline--github-fetch-notifications ()
  "Fetch GitHub notifications."
  (when (and doom-modeline-github
             (require 'async nil t))
    (async-start
     `(lambda ()
        ,(async-inject-variables
          "\\`\\(load-path\\|auth-sources\\|doom-modeline-before-github-fetch-notification-hook\\)\\'")
        (run-hooks 'doom-modeline-before-github-fetch-notification-hook)
        (when (require 'ghub nil t)
          (with-timeout (10)
            (ignore-errors
              (when-let* ((username (ghub--username ghub-default-host))
                          (token (or (ghub--token ghub-default-host username 'forge t)
                                     (ghub--token ghub-default-host username 'ghub t))))
                (ghub-get "/notifications"
                          '((notifications . t))
                          :host ghub-default-host
                          :username username
                          :auth token
                          :unpaginate t
                          :noerror t))))))
     (lambda (result)
       (message "")                     ; suppress message
       (setq doom-modeline--github-notification-number (length result))))))

However, when I evaluate the function itself, it does not work. The when condition evaluates to t, so the issue must originate in something related to the asynchronous process. And when I hard-code my username and token, it does work. Yet evaluating

(ghub--username ghub-default-host)
(ghub--token ghub-default-host (ghub--username ghub-default-host) 'forge t)

in a scratch buffer returns my credentials correctly (and, as mentioned previously, forge authenticates without a problem). So the issue seems to be caused by the special environment created by async-start.

Perhaps the problem is that I use pass to manage my secrets? Though the value of auth-sources is '(password-store macos-keychain-internet macos-keychain-generic) and this variable is correctly injected by async-inject-variables, so the special environment should have access to it. So I don't really understand what's going on.

benthamite commented 11 months ago

I solved the issue: it was a matter of calling auth-source-pass-enable from within the async-start environment, via the doom-modeline-before-github-fetch-notification-hook, like this:

(add-hook 'doom-modeline-before-github-fetch-notification-hook #'auth-source-pass-enable)

Would you like me to prepare a pull request to slightly expand the docstring of doom-modeline-github to note this and also that the token must include “notifications” permissions?

seagle0128 commented 11 months ago

Would you like me to prepare a pull request to slightly expand the docstring of doom-modeline-github to note this and also that the token must include “notifications” permissions?

Of course. Please move forward. I'm glad you dig out the root cause and prepare a PR for other users. Thanks in advance!