Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hackday: gh repo garden #1049

Merged
merged 24 commits into from Sep 15, 2020
Merged

hackday: gh repo garden #1049

merged 24 commits into from Sep 15, 2020

Conversation

vilmibm
Copy link
Contributor

@vilmibm vilmibm commented May 29, 2020

For this hackday I wanted to create something interactive that was unique to a given repository. As
a big fan of games like Angband I decided to make a repository a top down thing that can be explored. I wanted to convey a sense of people coming together to make something that they couldn't do on their own, so I chose to render a repo's commits as a garden of colorful flowers. The color of each flower is the first 6 characters of a commit's SHA interpreted as a hex code; the character of each flower is the first letter of a commiter's GitHub handle.

garden5

In addition to the commit flowers, there's:

  • a border of trees
  • a randomly placed stream
  • a sign saying the name of the repo

Considerations

  • The flowers are placed randomly but the random seed is based on the repo name; that means that two people looking at the garden for the same repo will see the same layout but each repo's layout is different.
  • This takes advantage of modern terminals' support for 24 bit color. I added utils.RGB(r,g,b,s)
    which can output text of any RGB color. I used this to more accurately convert SHAs to color and
    also to make a gradient fill for the stream.
  • Like my last hack day project, I did not introduce any new third party libraries
  • This uses the GitHub API to get commits. I started out using git log which is nice and fast
    but this meant you couldn't generate a garden for an arbitrary repository; it also meant that
    getting the GitHub handle for a committer was challenging. Using the API is a little slow but I'm
    happier with the results.

Future directions

I'd like to render a much larger space that can be panned around while the user moves. Given a
larger space, I'd render more about a given repository: projects as monuments, closed issues as
graves, contributors as wandering NPCs, etc.

I'd also like to animate it when the user is standing still. Right now it only redraws when the user
moves. I want the stream to twinkle and the grass to move in the wind.

@vilmibm vilmibm marked this pull request as ready for review June 25, 2020 16:05
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

I would love to see this merged! I'm sorry for the late review.

Since this is likely something that we would ship once and avoid refactoring too much, I think it would be beneficial if it was in its own package. Would you be open to moving the implementation to under pkg/cmd/repo/garden/ and for it to use a raw HTTP client directly (like api command does) rather than adding an extra method to the api package? It might be a nice pairing project for us; let me know!

@leereilly
Copy link
Contributor

SHA-mazing! 😍

If you're looking for an excuse to demo this, and/or watch a whole bunch of talks from fellow Roguelike developers and players, the Roguelike Celebration (usually hosted at GitHub HQ) might still be looking for presenters. I know the organizers well if you'd like an intro!

Check out the videos from yesteryear on YouTube.

@vilmibm
Copy link
Contributor Author

vilmibm commented Aug 12, 2020

@leereilly oh awesome! Thanks for suggesting that! I've watched videos from that event in the past.

This is a humble little thing and I don't think I could spin it into a talk of any significant length. It might be suitable for a lightning talk; alternatively I can submit next time around once it's more fleshed out.

@vilmibm vilmibm added the hack label Aug 19, 2020
@vilmibm vilmibm added this to Backlog 🗒 in The GitHub CLI via automation Aug 19, 2020
@vilmibm vilmibm moved this from Backlog 🗒 to In progress 🚧 in The GitHub CLI Aug 19, 2020
@vilmibm
Copy link
Contributor Author

vilmibm commented Aug 25, 2020

@mislav sorry, I totally missed your review 🤦 I've removed the additional method from api.client and isolated this command entirely in its own package in the new command format.

@vilmibm vilmibm requested review from mislav and removed request for probablycorey August 25, 2020 21:46
@vilmibm vilmibm moved this from In progress 🚧 to Needs review 🤔 in The GitHub CLI Aug 25, 2020
@vilmibm
Copy link
Contributor Author

vilmibm commented Aug 27, 2020

ok, this works fine on macos now 👍

Co-authored-by: Lee Reilly <lee@github.com>
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Couple of minor points before this ships

pkg/cmd/repo/garden/http.go Outdated Show resolved Hide resolved
// TODO fix arrow keys

func isLeft(b []byte) bool {
return bytes.EqualFold(b, []byte("a")) || bytes.EqualFold(b, []byte("q")) || bytes.EqualFold(b, []byte("h"))
Copy link
Contributor

Choose a reason for hiding this comment

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

If q is Left now, how do we exit the garden?

Copy link
Contributor

@leereilly leereilly Sep 9, 2020

Choose a reason for hiding this comment

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

The only way I can exit (on macOS at least) seems to be CTRL C.
That seems acceptable / consistent with gh credits? Q doesn't work for me there either FWIW.

lines = append(lines, "( <3 press ctrl-c to quit <3 )")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just switching to ctrl+c for quitting seems ok to me

Copy link
Contributor

@mislav mislav Sep 11, 2020

Choose a reason for hiding this comment

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

Sure! I was simply asking about q since it was documented as an exit technique for the garden.

Ctrl-C works, but does not print the nice exit message:

You turn and walk away from the wildflower garden…

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After testing this for a while I was unhappy about losing q; I ended up just making the arrow keys work, finally, so that is an option for anyone who doesn't want WADS or vi keys.

pkg/cmd/repo/garden/garden.go Outdated Show resolved Hide resolved
pkg/cmd/repo/garden/garden.go Show resolved Hide resolved
@vilmibm vilmibm requested a review from mislav September 14, 2020 21:00
@vilmibm
Copy link
Contributor Author

vilmibm commented Sep 14, 2020

  • flickering is fixed; only redrawing what needs to be redrawn, now
  • added support for arrow keys. since this is in, i took out azerty support so we could have "q" back for quitting
  • GHES supported

The GitHub CLI automation moved this from Needs review 🤔 to Needs to be merged 🎉 Sep 15, 2020
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Fantastic! Works like a charm.

One final optimization might be to cap max commits fetched. With a fairly medium terminal size of 150×50, 7,500 commits would need to be fetched, resulting in 75 HTTP requests each taking 500–600ms. When I maximize my terminal window, it wants to fetch 26,394 commits. For projects that actually have that many commits, this would result in long loading times.

I understand that this isn't a mission-critical command that should be fine-tuned for performance, but I'm thinking that at least there should be some guard mechanism in place to prevent the command from seeming like it's stuck or exhausting the viewer's API rate limit.


page := 1
paginating := true
fmt.Println("gathering commits; this could take a minute...")
Copy link
Contributor

Choose a reason for hiding this comment

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

Protip: you can now use opts.IO.StartProgressIndicator() + opts.IO.StopProgressIndicator() to get the spinner rendering 👌

@vilmibm
Copy link
Contributor Author

vilmibm commented Sep 15, 2020

I understand that this isn't a mission-critical command that should be fine-tuned for performance, but I'm thinking that at least there should be some guard mechanism in place to prevent the command from seeming like it's stuck or exhausting the viewer's API rate limit.

good point; I was definitely over requesting during the hackathon and never circled back and capped it. For now I just halved the product of terminal height/width to make it a little better since we were never going to make use of all the commits anyway.

@vilmibm vilmibm merged commit 9f486ef into trunk Sep 15, 2020
The GitHub CLI automation moved this from Needs to be merged 🎉 to Pending Release 🥚 Sep 15, 2020
@vilmibm vilmibm deleted the garden branch September 15, 2020 14:59
@github-actions github-actions bot moved this from Pending Release 🥚 to Done 💤 in The GitHub CLI Sep 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
The GitHub CLI
  
Done 💤
Development

Successfully merging this pull request may close these issues.

None yet

3 participants