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

Add command to list environments #889

Merged
merged 2 commits into from
May 19, 2023
Merged

Add command to list environments #889

merged 2 commits into from
May 19, 2023

Conversation

graygilmore
Copy link
Contributor

@graygilmore graygilmore commented May 15, 2023

WHY are these changes introduced?

We're introducing the ability for developers to specify an environment to use variables from (#883) but they'd need to open the admin to see which branches are assigned to which environments in order to do so.

WHAT is this pull request doing?

Introduces a new env list command that will list all of the environments on the linked Hydrogen storefront that have a branch.

➜  demo-store git:(list-environments) ✗ h2 env list

Name        Branch   URL
──────────  ───────  ──────────────────────────────────────
Production  main     https://example.com
Staging     staging  https://staging-123.myshopify.dev
Queen       queen    https://queen-456.myshopify.dev
Preview     -        -

HOW to test your changes?

  1. Pull the branch and navigate to the cli directory
  2. Run npm run build
  3. Navigate to the demo store directory cd ../../templates/demo-store
  4. Run h2 env list (note: if h2 is unavailable run npx shopify hydrogen shortcut first) to see a list of your environments
    • You should be prompted to provide a shop
    • You should then be prompted to authenticate with that shop
    • You should be prompted that you need to link to a storefront
  5. Confirm that the correct list of environments is shown

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if this PR contains user-facing or noteworthy changes
  • I've added tests to cover my changes
  • I've added or updated the documentation

@graygilmore graygilmore marked this pull request as ready for review May 15, 2023 20:25
@graygilmore graygilmore requested a review from frandiox May 15, 2023 20:25
Copy link
Contributor

@frandiox frandiox left a comment

Choose a reason for hiding this comment

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

Looks good!

packages/cli/src/lib/missing-link.ts Outdated Show resolved Hide resolved
packages/cli/src/commands/hydrogen/env/list.ts Outdated Show resolved Hide resolved
}

const rows = hydrogenStorefront.environments
.filter(({type}) => type !== 'PREVIEW')
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to filter out preview types? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a great question! I'm filtering it because it looks a little odd in the table because it doesn't have a branch or URL:

Name        Branch              URL
──────────  ──────────────────  ────────────────────────────────────────
Production  main                https://example.com
Staging     staging             https://staging-123.myshopify.dev
Preview

So it looks like it's dangling off the side. Maybe if I added something instead of empty strings?

Name        Branch              URL
──────────  ──────────────────  ────────────────────────────────────────
Production  main                https://example.com
Staging     staging             https://staging-123.myshopify.dev
Preview     -                   -

Actually that kind of looks good!

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I see. But what would be the "branch" that we need to specify in this case in --branch? I guess we just omit it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly, Preview is the default. Right now environment names aren't unique so if you had multiple Staging branches there'd be no way to differentiate between them. Branches are unique on environments which is why we're using that field and making Preview default.

@graygilmore
Copy link
Contributor Author

Force Push Patch Notes

  • Combined renderMissingLink and renderMissingStorefront into a single file called render-errors.ts
  • Stopped filtering out the Preview environment but made sure it always comes last in the list
  • Added a comment around the production URL logic

@graygilmore
Copy link
Contributor Author

Force Push Patch Notes

  • Rebased with 2023-04 to fix merge conflict

@graygilmore
Copy link
Contributor Author

Force Push Patch Notes

  • Rebased with 2023-04 to fix failing test

@graygilmore
Copy link
Contributor Author

Force Push Patch Notes

  • Rebased with 2023-04 to fix merge conflicts
    • Most notable is that the first commit's changes move from pull.ts to pull-environment-variables.ts as that's where the logic moved to in a previously merged PR

@graygilmore graygilmore merged commit 1a9f402 into 2023-04 May 19, 2023
@graygilmore graygilmore deleted the list-environments branch May 19, 2023 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants