rafaelmardojai / forge-sparks

Get git forges notifications
MIT License
61 stars 7 forks source link

GH access token needs additional permissions for private repos #10

Closed Siilwyn closed 10 months ago

Siilwyn commented 11 months ago

Hi, first of thank you for making this! As of some time last week the app isn't showing new notifications anymore, while they do get in the GitHub notifications page. I've tried regenerating the access token and removing the account to re-add it.

This is on Fedora 38, running it from the terminal with flatpak run --allow=devel com.mardojai.ForgeSparks does log:

Gjs-Message: 15:18:25.883: JS LOG: Forge Sparks: com.mardojai.ForgeSparks
Gjs-Message: 15:18:25.883: JS LOG: Version: 0.1.1
Gjs-Message: 15:18:26.537: JS LOG: https://api.github.com/notifications response resulted in 200
Gjs-Message: 15:18:26.909: JS LOG: Error: Invalid value 'undefined' for property url in object initializer.
Siilwyn commented 11 months ago

Update, I actually just received a notification in Sparks from one of my own repos. Maybe it has to do with the repos I'm working with being private? :thought_balloon:

rafaelmardojai commented 11 months ago

Update, I actually just received a notification in Sparks from one of my own repos. Maybe it has to do with the repos I'm working with being private? 💭

Maybe. The issue seems to be referencing this line: https://github.com/rafaelmardojai/forge-sparks/blob/801dbd6e4dad5b3a055a25611ec67eaa99fd9d40/src/forges/github.js#L95

Meaning that the _getSubjectInfo function is falling to get an url for some type of notification that you're getting.

In the meantime I need to figure out how to debug your issue. In github what kind of notifications are you getting? Like issues, pull requests, discussions, etc.

Siilwyn commented 11 months ago

All of them are pull request related, most are pull request review requests and some pull request comments.

rafaelmardojai commented 11 months ago

Can you sent me by mail (email@rafaelmardojai.com) (or here if you don't mind making it public) the output of calling this in your terminal:

curl https://api.github.com/notifications -H "Authorization: token YOUR_TOKEN_HERE"

It should print the raw JSON Forge Sparks is getting.

Siilwyn commented 11 months ago

Yes for sure, I've redacted the name just to be on the safe side: (the missing notification is returned from the api call it seems)

[
  {
    "id": "7258350380",
    "unread": true,
    "reason": "author",
    "updated_at": "2023-08-02T17:25:15Z",
    "last_read_at": "2023-08-02T17:05:19Z",
    "subject": {
      "title": "Suddenly stopped receiving new notifications",
      "url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/issues/10",
      "latest_comment_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/issues/comments/1662656052",
      "type": "Issue"
    },
    "repository": {
      "id": 566851011,
      "node_id": "R_kgDOIcl1ww",
      "name": "forge-sparks",
      "full_name": "rafaelmardojai/forge-sparks",
      "private": false,
      "owner": {
        "login": "rafaelmardojai",
        "id": 6210397,
        "node_id": "MDQ6VXNlcjYyMTAzOTc=",
        "avatar_url": "https://avatars.githubusercontent.com/u/6210397?v=4",
        "gravatar_id": "",
        "url": "https://api.github.com/users/rafaelmardojai",
        "html_url": "https://github.com/rafaelmardojai",
        "followers_url": "https://api.github.com/users/rafaelmardojai/followers",
        "following_url": "https://api.github.com/users/rafaelmardojai/following{/other_user}",
        "gists_url": "https://api.github.com/users/rafaelmardojai/gists{/gist_id}",
        "starred_url": "https://api.github.com/users/rafaelmardojai/starred{/owner}{/repo}",
        "subscriptions_url": "https://api.github.com/users/rafaelmardojai/subscriptions",
        "organizations_url": "https://api.github.com/users/rafaelmardojai/orgs",
        "repos_url": "https://api.github.com/users/rafaelmardojai/repos",
        "events_url": "https://api.github.com/users/rafaelmardojai/events{/privacy}",
        "received_events_url": "https://api.github.com/users/rafaelmardojai/received_events",
        "type": "User",
        "site_admin": false
      },
      "html_url": "https://github.com/rafaelmardojai/forge-sparks",
      "description": "Get git forges notifications",
      "fork": false,
      "url": "https://api.github.com/repos/rafaelmardojai/forge-sparks",
      "forks_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/forks",
      "keys_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/keys{/key_id}",
      "collaborators_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/collaborators{/collaborator}",
      "teams_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/teams",
      "hooks_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/hooks",
      "issue_events_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/issues/events{/number}",
      "events_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/events",
      "assignees_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/assignees{/user}",
      "branches_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/branches{/branch}",
      "tags_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/tags",
      "blobs_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/git/blobs{/sha}",
      "git_tags_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/git/tags{/sha}",
      "git_refs_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/git/refs{/sha}",
      "trees_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/git/trees{/sha}",
      "statuses_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/statuses/{sha}",
      "languages_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/languages",
      "stargazers_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/stargazers",
      "contributors_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/contributors",
      "subscribers_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/subscribers",
      "subscription_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/subscription",
      "commits_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/commits{/sha}",
      "git_commits_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/git/commits{/sha}",
      "comments_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/comments{/number}",
      "issue_comment_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/issues/comments{/number}",
      "contents_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/contents/{+path}",
      "compare_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/compare/{base}...{head}",
      "merges_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/merges",
      "archive_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/{archive_format}{/ref}",
      "downloads_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/downloads",
      "issues_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/issues{/number}",
      "pulls_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/pulls{/number}",
      "milestones_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/milestones{/number}",
      "notifications_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/notifications{?since,all,participating}",
      "labels_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/labels{/name}",
      "releases_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/releases{/id}",
      "deployments_url": "https://api.github.com/repos/rafaelmardojai/forge-sparks/deployments"
    },
    "url": "https://api.github.com/notifications/threads/7258350380",
    "subscription_url": "https://api.github.com/notifications/threads/7258350380/subscription"
  },
  {
    "id": "7259767060",
    "unread": true,
    "reason": "review_requested",
    "updated_at": "2023-08-02T15:29:51Z",
    "last_read_at": "2023-08-02T15:30:40Z",
    "subject": {
      "title": "Refactor selector",
      "url": "https://api.github.com/repos/redactedOrg/registration-funnel/pulls/351",
      "latest_comment_url": null,
      "type": "PullRequest"
    },
    "repository": {
      "id": 529175093,
      "node_id": "R_redacted",
      "name": "registration-funnel",
      "full_name": "redactedOrg/registration-funnel",
      "private": true,
      "owner": {
        "login": "redactedOrg",
        "id": 97439011,
        "node_id": "O_redacted",
        "avatar_url": "https://avatars.githubusercontent.com/u/97439011?v=4",
        "gravatar_id": "",
        "url": "https://api.github.com/users/redactedOrg",
        "html_url": "https://github.com/redactedOrg",
        "followers_url": "https://api.github.com/users/redactedOrg/followers",
        "following_url": "https://api.github.com/users/redactedOrg/following{/other_user}",
        "gists_url": "https://api.github.com/users/redactedOrg/gists{/gist_id}",
        "starred_url": "https://api.github.com/users/redactedOrg/starred{/owner}{/repo}",
        "subscriptions_url": "https://api.github.com/users/redactedOrg/subscriptions",
        "organizations_url": "https://api.github.com/users/redactedOrg/orgs",
        "repos_url": "https://api.github.com/users/redactedOrg/repos",
        "events_url": "https://api.github.com/users/redactedOrg/events{/privacy}",
        "received_events_url": "https://api.github.com/users/redactedOrg/received_events",
        "type": "Organization",
        "site_admin": false
      },
      "html_url": "https://github.com/redactedOrg/registration-funnel",
      "description": null,
      "fork": false,
      "url": "https://api.github.com/repos/redactedOrg/registration-funnel",
      "forks_url": "https://api.github.com/repos/redactedOrg/registration-funnel/forks",
      "keys_url": "https://api.github.com/repos/redactedOrg/registration-funnel/keys{/key_id}",
      "collaborators_url": "https://api.github.com/repos/redactedOrg/registration-funnel/collaborators{/collaborator}",
      "teams_url": "https://api.github.com/repos/redactedOrg/registration-funnel/teams",
      "hooks_url": "https://api.github.com/repos/redactedOrg/registration-funnel/hooks",
      "issue_events_url": "https://api.github.com/repos/redactedOrg/registration-funnel/issues/events{/number}",
      "events_url": "https://api.github.com/repos/redactedOrg/registration-funnel/events",
      "assignees_url": "https://api.github.com/repos/redactedOrg/registration-funnel/assignees{/user}",
      "branches_url": "https://api.github.com/repos/redactedOrg/registration-funnel/branches{/branch}",
      "tags_url": "https://api.github.com/repos/redactedOrg/registration-funnel/tags",
      "blobs_url": "https://api.github.com/repos/redactedOrg/registration-funnel/git/blobs{/sha}",
      "git_tags_url": "https://api.github.com/repos/redactedOrg/registration-funnel/git/tags{/sha}",
      "git_refs_url": "https://api.github.com/repos/redactedOrg/registration-funnel/git/refs{/sha}",
      "trees_url": "https://api.github.com/repos/redactedOrg/registration-funnel/git/trees{/sha}",
      "statuses_url": "https://api.github.com/repos/redactedOrg/registration-funnel/statuses/{sha}",
      "languages_url": "https://api.github.com/repos/redactedOrg/registration-funnel/languages",
      "stargazers_url": "https://api.github.com/repos/redactedOrg/registration-funnel/stargazers",
      "contributors_url": "https://api.github.com/repos/redactedOrg/registration-funnel/contributors",
      "subscribers_url": "https://api.github.com/repos/redactedOrg/registration-funnel/subscribers",
      "subscription_url": "https://api.github.com/repos/redactedOrg/registration-funnel/subscription",
      "commits_url": "https://api.github.com/repos/redactedOrg/registration-funnel/commits{/sha}",
      "git_commits_url": "https://api.github.com/repos/redactedOrg/registration-funnel/git/commits{/sha}",
      "comments_url": "https://api.github.com/repos/redactedOrg/registration-funnel/comments{/number}",
      "issue_comment_url": "https://api.github.com/repos/redactedOrg/registration-funnel/issues/comments{/number}",
      "contents_url": "https://api.github.com/repos/redactedOrg/registration-funnel/contents/{+path}",
      "compare_url": "https://api.github.com/repos/redactedOrg/registration-funnel/compare/{base}...{head}",
      "merges_url": "https://api.github.com/repos/redactedOrg/registration-funnel/merges",
      "archive_url": "https://api.github.com/repos/redactedOrg/registration-funnel/{archive_format}{/ref}",
      "downloads_url": "https://api.github.com/repos/redactedOrg/registration-funnel/downloads",
      "issues_url": "https://api.github.com/repos/redactedOrg/registration-funnel/issues{/number}",
      "pulls_url": "https://api.github.com/repos/redactedOrg/registration-funnel/pulls{/number}",
      "milestones_url": "https://api.github.com/repos/redactedOrg/registration-funnel/milestones{/number}",
      "notifications_url": "https://api.github.com/repos/redactedOrg/registration-funnel/notifications{?since,all,participating}",
      "labels_url": "https://api.github.com/repos/redactedOrg/registration-funnel/labels{/name}",
      "releases_url": "https://api.github.com/repos/redactedOrg/registration-funnel/releases{/id}",
      "deployments_url": "https://api.github.com/repos/redactedOrg/registration-funnel/deployments"
    },
    "url": "https://api.github.com/notifications/threads/7259767060",
    "subscription_url": "https://api.github.com/notifications/threads/7259767060/subscription"
  }
]
rafaelmardojai commented 11 months ago

So the "redactedOrg" notification is the one failing right?

Now can you show me the response to:

curl https://api.github.com/repos/redactedOrg/registration-funnel/pulls/351 -H "Authorization: token YOUR_TOKEN_HERE"
Siilwyn commented 11 months ago

Ah it's returning this:

{
  "message": "Not Found",
  "documentation_url": "https://docs.github.com/rest/pulls/pulls#get-a-pull-request"
}

However I figured out if I enable the full repo scope on the access token I do get a response! And the app now shows the notifications! So I guess all that's needed to fix this is document in preferences panel that full repo scope is needed?

rafaelmardojai commented 11 months ago

Right, so the problem is when Forge Sparks is trying to get more info about the subject it is not longer sung the notifications endpoint.

So I guess all that's needed to fix this is document in preferences panel that full repo scope is needed?

Yes, but the app shouldn’t fail so badly in this scenarios, the notification should be processed successfully but with less details.

rafaelmardojai commented 10 months ago

@Siilwyn pushed a fix to have a fallback url for the notification when we don't have access to the repo. And also documented the need of the full repo scope.

Would you be able to test?

Siilwyn commented 10 months ago

Yes LGTM! Cheers :tada: