Repository: VirtusLab/git-machete

Issue:
Does `/pulls` endpoint for a public GitHub repository really require authentication?
As @mkondratek reported:

I've tried to use `create-pr` with that result:

```sh
mikko@mikko-MS-7C91:~/IdeaProjects/git-machete-intellij-plugin$ git machete github create-pr
Fetching origin...
Creating a PR from hook-executors-improvements to develop...Given endpoint: https://api.github.com/repos/VirtusLab/git-machete-intellij-plugin/pulls, not found in GitHub or you don't have the permission to access it (expired token?).
```

I have no token (generated and) set so that's the reason. After that - works.

_Originally posted by @mkondratek in https://github.com/VirtusLab/git-machete/issues/493#issuecomment-1113174706_

---

My addition: note that https://api.github.com/repos/VirtusLab/git-machete-intellij-plugin/pulls can be readily accessed from browser and returns legit results. Let's check why this error happens when accessing GitHub API from git-machete CLI. If this can't be circumvented (e.g. for private repos), let's at least improve the error message (since it doesn't even clearly state that the token might be missing, only mentions expiry) :thinking:

Discussion:
codecov-commenter: # [Codecov](https://codecov.io/gh/VirtusLab/git-machete/pull/534?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VirtusLab) Report
> Merging [#534](https://codecov.io/gh/VirtusLab/git-machete/pull/534?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VirtusLab) (63d06d3) into [develop](https://codecov.io/gh/VirtusLab/git-machete/commit/7bcd0232c5617f4f52b1865625661512b028548d?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VirtusLab) (7bcd023) will **increase** coverage by `0.03%`.
> The diff coverage is `100.00%`.

```diff
@@             Coverage Diff             @@
##           develop     #534      +/-   ##
===========================================
+ Coverage    66.65%   66.68%   +0.03%     
===========================================
  Files           10       10              
  Lines         2864     2864              
  Branches       696      696              
===========================================
+ Hits          1909     1910       +1     
+ Misses         691      690       -1     
  Partials       264      264              
```


| [Impacted Files](https://codecov.io/gh/VirtusLab/git-machete/pull/534?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VirtusLab) | Coverage Δ | |
|---|---|---|
| [git\_machete/github.py](https://codecov.io/gh/VirtusLab/git-machete/pull/534/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VirtusLab#diff-Z2l0X21hY2hldGUvZ2l0aHViLnB5) | `71.60% <ø> (+0.61%)` | :arrow_up: |
| [git\_machete/client.py](https://codecov.io/gh/VirtusLab/git-machete/pull/534/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VirtusLab#diff-Z2l0X21hY2hldGUvY2xpZW50LnB5) | `61.97% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/VirtusLab/git-machete/pull/534?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VirtusLab).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VirtusLab)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/VirtusLab/git-machete/pull/534?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VirtusLab). Last update [7bcd023...63d06d3](https://codecov.io/gh/VirtusLab/git-machete/pull/534?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VirtusLab). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VirtusLab).


Patch:
diff --git a/git_machete/client.py b/git_machete/client.py
index d063583..19ef0c4 100644
--- a/git_machete/client.py
+++ b/git_machete/client.py
@@ -2109,7 +2109,7 @@ class MacheteClient:
         description_path = self.__git.get_main_git_subpath('info', 'description')
         description: str = utils.slurp_file_or_empty(description_path)
 
-        ok_str = ' <green><b>OK</b></green>'
+        ok_str = ' <green>-> <b>OK</b></green>'
         print(fmt(f'Creating a {"draft " if opt_draft else ""}PR from `{head}` to `{base}`...'), end='', flush=True)
         pr: GitHubPullRequest = create_pull_request(org, repo, head=head, base=base, title=commits[0].subject,
                                                     description=description, draft=opt_draft)
diff --git a/git_machete/github.py b/git_machete/github.py
index f8dc8c4..49f089b 100644
--- a/git_machete/github.py
+++ b/git_machete/github.py
@@ -181,8 +181,9 @@ def __fire_github_api_request(method: str, path: str, token: Optional[str], requ
                                  'Visit `https://github.com/settings/tokens` to generate a new one.')
         elif err.code == http.HTTPStatus.NOT_FOUND:
             raise MacheteException(
-                f'Given endpoint: {url}, not found in GitHub or you don\'t have'
-                f' the permission to access it (expired token?).')  # TODO (#164): make dedicated exception here
+                f'`{method} {url}` request ended up in 404 response from GitHub. A valid GitHub API token is required.\n'
+                f'Provide a GitHub API token with `repo` access via one of the: {get_github_token_possible_providers()} '
+                'Visit `https://github.com/settings/tokens` to generate a new one.')  # TODO (#164): make dedicated exception here
         else:
             first_line = fmt(f'GitHub API returned {err.code} HTTP status with error message: `{err.reason}`\n')
             raise MacheteException(first_line + "Please open an issue regarding this topic under link: https://github.com/VirtusLab/git-machete/issues/new")


Test patch:
diff --git a/tests/test_github.py b/tests/test_github.py
index 90fe555..d8fce10 100644
--- a/tests/test_github.py
+++ b/tests/test_github.py
@@ -454,7 +454,7 @@ class TestGithub:
 
         expected_msg = ("Fetching origin...\n"
                         "Warn: Base branch for this PR (`feature/api_handling`) is not found on remote, pushing...\n"
-                        "Creating a PR from `feature/api_exception_handling` to `feature/api_handling`... OK, see www.github.com\n")
+                        "Creating a PR from `feature/api_exception_handling` to `feature/api_handling`... -> OK, see www.github.com\n")
         assert_command(['github', 'create-pr'], expected_msg, strip_indentation=False)
         assert_command(
             ['status'],