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

feat: add accounts commands #3257

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

feat: add accounts commands #3257

wants to merge 17 commits into from

Conversation

k80bowman
Copy link
Contributor

@k80bowman k80bowman commented Mar 17, 2025

Work item

This PR moves the commands from heroku/heroku-accounts to the CLI core, migrates them to TypeScript and oclif/core v2, updates and adds descriptions and error text, and adds tests.

These commands made use of functionality from heroku-cli-utils that is implemented differently in heroku-cli/command and oclif. Because of this, the migrated commands may be implemented a little differently than the originals. The overall functionality should be roughly the same and should accomplish the same tasks.

Testing

  1. Check out this branch and run yarn && yarn build
  2. Sign into a Heroku account
  3. Run ./bin/run accounts:add ACCOUNT_NAME (the account name can be whatever makes sense to you)
  4. Run ./bin/run accounts and verify that your new account is listed
  5. Sign into a different Heroku account (I used a testing account, just be sure to sign out when you are done)
  6. Run ./bin/run accounts:add ACCOUNT_NAME using a different account name
  7. Run ./bin/run accounts and verify that both accounts are now listed
  8. Run ./bin/run accounts:current and verify that the account you are currently logged into is listed
  9. Run ./bin/run accounts:set ACCOUNT_NAME using the name of the account you are not currently logged into
  10. Run ./bin/run accounts:current and verify that it lists the account you set
  11. Run ./bin/run accounts:remove ACCOUNT_NAME using the name of the account you are not currently logged into
  12. Run ./bin/run accounts and verify that only one account is now listed

}

if (current() === name) {
ux.error(`${name} is the current account`)

Choose a reason for hiding this comment

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

Is this error when a logged in user tries to remove themselves from the cache? @k80bowman

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this error is when a user tries to remove the account they are currently logged into from the cache.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@claire-riley @eablack should we update this error message to read something like ${name} is the current account. It cannot be removed.?

@k80bowman k80bowman temporarily deployed to AcceptanceTests March 18, 2025 21:24 — with GitHub Actions Inactive
@k80bowman k80bowman temporarily deployed to AcceptanceTests March 19, 2025 13:29 — with GitHub Actions Inactive
@k80bowman k80bowman temporarily deployed to AcceptanceTests March 19, 2025 13:35 — with GitHub Actions Inactive
@k80bowman k80bowman temporarily deployed to AcceptanceTests March 19, 2025 14:10 — with GitHub Actions Inactive
@k80bowman k80bowman temporarily deployed to AcceptanceTests March 19, 2025 14:10 — with GitHub Actions Inactive
@k80bowman k80bowman marked this pull request as ready for review March 19, 2025 14:10
@k80bowman k80bowman requested a review from a team as a code owner March 19, 2025 14:10
@k80bowman k80bowman temporarily deployed to AcceptanceTests March 20, 2025 17:24 — with GitHub Actions Inactive
@k80bowman k80bowman temporarily deployed to AcceptanceTests March 20, 2025 17:41 — with GitHub Actions Inactive
@k80bowman k80bowman dismissed justinwilaby’s stale review March 20, 2025 18:38

Requested work will be handled in a separate PR.

@k80bowman k80bowman temporarily deployed to AcceptanceTests March 20, 2025 20:42 — with GitHub Actions Inactive
@k80bowman k80bowman temporarily deployed to AcceptanceTests March 20, 2025 20:42 — with GitHub Actions Inactive
Copy link
Contributor

@eablack eablack left a comment

Choose a reason for hiding this comment

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

Code looks good. Had some clarifying questions. I noticed we resolved some suggestions from cx without applying them, was that intentional?

async run() {
const accounts = list()
if (accounts.length === 0) {
ux.error('No accounts found in cache.')
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed this was new error text (it's a very good sanity check, btw). And it looks like cx reviewed it, but we resolved the conversation without change. Was that intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Claire let me know that I'd missed this one, it's been updated. I must have resolved it by accident.

async run() {
const {args} = await this.parse(Add)
const {name} = args
const logInMessage = 'You must be logged in to run this command.'
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't actually encounter this message when i'm not logged in:
Screenshot 2025-03-20 at 1 44 54 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you. I will check on this.

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 should be fixed now. Instead of an error message you should be prompted to log in.

import * as Heroku from '@heroku-cli/schema'
import {add, list} from '../../lib/accounts/accounts'

export default class Add extends Command {
Copy link
Contributor

Choose a reason for hiding this comment

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

In the plugin, there's an sso flag that is required to facilitate login for an sso user, and I don't see that here. Actually, I don't see us performing the login in the new command.. did we change the behavior here? Like, with the plugin, if a user is not logged in, we're starting the login for them I think. Here, I think we are just telling them they need to log in. Is that right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I made that behavior change here. The actual login command has several flags that I did not want to reintroduce here, beyond just sso. We could do this a different way and start the login process here, but I thought it would be better to keep this command focused on adding an account.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I could get rid of the {retry: false} in the API call and it would prompt the user to login. I'm not sure why I added that, but it's not necessary. I'm going to remove it and then I can remove some of the error logic as well. If you're not logged in, it should prompt you to log in the way most of the rest of our commands do.

if (account) {
ux.styledHeader(`Current account is ${account}`)
} else {
ux.error(`You haven't set an account. Run ${color.cmd('heroku login')} to confirm you're logged in to Heroku.`)
Copy link
Contributor

Choose a reason for hiding this comment

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

This error message is possibly misleading. So, if I'm logged in and run this command I'll get this command, suggesting I need to run heroku login. But the problem isn't that I need to log in, it's that I need to run accounts:add.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will check on this, thank you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@claire-riley could we remove the portion of the message about logging in and have it just say You haven't set an account.? The error appears both when the user isn't logged and when the user has not added any accounts.

Choose a reason for hiding this comment

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

@k80bowman would it be possible to suggest both commands? If we only have "You haven't set an account." I think as a user I'd feel at a dead end.

What is the response that accounts:add gives if user isn't logged in?

}

if (current() === name) {
ux.error(`${name} is the current account.`)
Copy link
Contributor

Choose a reason for hiding this comment

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

I had the same thought as claire when I tested this scenario.

Copy link
Contributor Author

@k80bowman k80bowman Mar 21, 2025

Choose a reason for hiding this comment

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

Ah another one I missed. Sorry, I will check on this.

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.

4 participants