freeCodeCamp / classroom

BSD 3-Clause "New" or "Revised" License
144 stars 121 forks source link

Install gh CLI in .devcontainer to checkout GitHub pull requests #411

Closed lloydchang closed 1 year ago

lloydchang commented 1 year ago

Describe the issue Install gh CLI in .devcontainer to checkout GitHub pull requests.

For example, to check out GitHub pull request #402

To Reproduce

  1. gh repo set-default
  2. ? Which repository should be the default? freeCodeCamp/classroom
  3. gh pr checkout 402

Without gh CLI, the above commands will fail with:

bash: gh: command not found

Expected behavior

@lloydchang ➜ /workspace (ddb2943) $ gh repo set-default
This command sets the default remote repository to use when querying the
GitHub API for the locally cloned repository.

gh uses the default repository for things like:

 - viewing and creating pull requests
 - viewing and creating issues
 - viewing and creating releases
 - working with Actions
 - adding repository and environment secrets
? Which repository should be the default? freeCodeCamp/classroom
✓ Set freeCodeCamp/classroom as the default repository for the current directory
@lloydchang ➜ /workspace (ddb2943) $ gh pr checkout 402
remote: Enumerating objects: 23, done.
remote: Counting objects: 100% (23/23), done.
remote: Compressing objects: 100% (19/19), done.
remote: Total 23 (delta 4), reused 20 (delta 4), pack-reused 0
Unpacking objects: 100% (23/23), 8.56 KiB | 797.00 KiB/s, done.
From https://github.com/freeCodeCamp/classroom
 * [new ref]         refs/pull/402/head -> bugfix-amend-incorrect-dashboard-rendering
M       .env.sample
M       util/api_proccesor.js
Previous HEAD position was ddb2943 chore(deps): pin dependencies (#358)
Switched to branch 'bugfix-amend-incorrect-dashboard-rendering'
@lloydchang ➜ /workspace (bugfix-amend-incorrect-dashboard-rendering) $ 

Implementation details for a new pull request to close this GitHub issue

Add the snippet from https://github.com/cli/cli/blob/trunk/docs/install_linux.md#debian-ubuntu-linux-raspberry-pi-os-apt

type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y)
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt update \
&& sudo apt install gh -y

to the top part of https://github.com/freeCodeCamp/classroom/blob/main/.devcontainer/postCreateCommand.sh

Komal914 commented 1 year ago

Hi, I can take over this issue. Please assign me @lloydchang

lloydchang commented 1 year ago

Cross-posted at https://codedayorg.slack.com/archives/C05E350DQH4/p1690876446239419?thread_ts=1690867554.654849


@Komal914

I guess your question(?)

is this is available, I am interested in working on it

is probably intended for me as the reporter of that issue, so I’m chiming in to respond.

It’s unavailable in the sense that #411

https://github.com/freeCodeCamp/classroom/pull/411

says:

@lloydchang lloydchang linked a pull request yesterday that will close this issue build(.devcontainer): add gh CLI #412

which means I already implemented it as a pull request for it in #412

https://github.com/freeCodeCamp/classroom/pull/412

Practically, I needed a way to checkout different GitHub pull requests.

gh CLI is probably the best way to checkout different GitHub pull requests in a Developer Container in GitHub Codespaces.

It’s available in the sense that if you want to iterate through #411 and #412 independently as a learning exercise, you can do that by first, setting up your GitHub Codespaces if you haven’t already done so.

There’s not much problem solving in #411 and #412 from a software engineering perspective.

411 is a trivial change to implement via #412 since it’s copying and pasting from GitHub’s documentation into a shell script used by a Development Container in GitHub Codespaces.

lloydchang commented 1 year ago

Please contact @GuillermoFloresV if you have further questions about this. Thanks!

lloydchang commented 1 year ago

Done by https://github.com/freeCodeCamp/classroom/pull/396