Skip to content

Conversation

@loadre
Copy link
Contributor

@loadre loadre commented Jan 31, 2025

closes #23

@loadre loadre marked this pull request as draft January 31, 2025 03:11
@loadre loadre marked this pull request as ready for review January 31, 2025 03:17
@chshersh chshersh self-requested a review January 31, 2025 13:08
@chshersh chshersh added type: feature New feature request component: UI Issues related to changing UI component: GH Issues related to GitHub API and interaction with it type: refactoring Improving the code quality w/o changing functionality and removed type: feature New feature request labels Jan 31, 2025
Copy link
Owner

@chshersh chshersh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff! I see that you've put care into writing this code and did lots of good refactorings.

I left a few suggestions to improve the code even further but the general idea is correct 🙂

lib/gh/client.ml Outdated
~url:github_api_url ()
in
match response with
| Error (_code, msg) -> Ok (Printf.sprintf "Error: %s" msg)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add one more constructor Curl_error of { code: int; msg: string } to error and return it here.

I don't think it should affect much of the rest code.


(** Query all open issues *)
val issues : owner:string -> repo:string -> t list
val issues : owner:string -> repo:string -> (t list, Client.error) result
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

This is a nice change of type signature!

Comment on lines +1 to +12
type t = {
pull_requests : Gh.Pr.t list lazy_t;
error : Gh.Client.error option;
}

let make ~owner ~repo =
let pull_requests, error =
match Gh.Pr.pull_requests ~owner ~repo with
| Ok issues -> (lazy issues, None)
| Error err -> (lazy [], Some err)
in
{ pull_requests; error }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for creating this as a separate file! This was the plan anyway 🙂

let issues =
match issues_tab.error with
| None -> fmt_issues ~selected:issues_tab.offset issues_tab.issues
| Some No_github_token -> Doc.str "\u{26A0} GITHUB_TOKEN not found"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, what is this symbol? 👀 Do you have a screenshot?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, let's make the message more helpful. Let's do something like:

\u{26A0} GITHUB_TOKEN not found. Make sure it's configured in your environment.

If you don't have a token, visit the following page to create one:
  • https://github.com/settings/tokens

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
I don't have nerd fonts installed on my machine, but it's supposed to be a warning sign like the one in terminal size warning.

Comment on lines 87 to 92
let issues =
match issues_tab.error with
| None -> fmt_issues ~selected:issues_tab.offset issues_tab.issues
| Some No_github_token -> Doc.str "\u{26A0} GITHUB_TOKEN not found"
in
Doc.(vertical [ fmt_filters issues_tab.filter; str ""; issues ])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rewrite this view a bit differently: don't display issue selector at all if there're errors.

So, the idea is to pattern match on the error and if it's None, use the previous formatting, otherwise, use the new doc.

@loadre loadre requested a review from chshersh January 31, 2025 16:04
Copy link
Owner

@chshersh chshersh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

There's some duplication, but it can be handled separately.

Looks like the formatted is not happy. Once it's fixed, I'm happy to merge 👍🏻

@loadre loadre requested a review from chshersh January 31, 2025 18:17
@chshersh chshersh merged commit 8e96af0 into chshersh:main Jan 31, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: GH Issues related to GitHub API and interaction with it component: UI Issues related to changing UI type: refactoring Improving the code quality w/o changing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle missing GITHUB_TOKEN

2 participants