Skip to content
This repository was archived by the owner on Nov 13, 2022. It is now read-only.

Conversation

@nellshamrell
Copy link
Collaborator

This adds in the ability to get a list of apps associated with a Heroku account. I will be adding in several more Heroku specific commands in the next pull request.

Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>

wip

Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>

wip

Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>

wip

Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>

wip - make each app an instance of the HerokuApp struct

Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>

working command to get list of Heroku apps associated with a Heroku token

Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>

refactors heroku get apps command

Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>

corrects formatting

Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>

refactors finding environmental variable values into a config struct

Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>

implements and references default config

Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>

correct formatting

Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>

further refactoring

Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
…zation code

Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
…rization functions

Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
@nellshamrell
Copy link
Collaborator Author

I've refactored the code to only create a Config once, then pass it to the various commands. The way to do this in the Serenity framework is through writing to the data field of the context for the command.

It currently takes three lines of code to extract the config from the data field in each of the command files that need it: (currently this is used in the code for the ping command and the heroku commands.

let ctx_clone = ctx.clone();
let data = ctx_clone.data.read();
let config = data.get::<Config>().expect("Expected **config");**

This does feel a little repetitive. I tried extracting those three lines into a function in config.rs, but it felt like I was swimming upstream with ownership when doing so.

Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
@nellshamrell
Copy link
Collaborator Author

@smarnach @pietroalbini - thank you so much for the feedback, I've done quite a bit of refactoring to incorporate it in :)

1 similar comment
@nellshamrell
Copy link
Collaborator Author

@smarnach @pietroalbini - thank you so much for the feedback, I've done quite a bit of refactoring to incorporate it in :)

@smarnach
Copy link
Contributor

smarnach commented Mar 6, 2020

One solution for the Config object is to wrap it in an Arc. This allows you to sneak a shared reference out without holding on to the read lock for the context – see smarnach@30dda80 for a quick implementation attempt. This also makes it easy to wrap the config extraction in a function.

Why do you have a config module nested inside the config module, by the way? I think one level of config would feel enough. :)

Copy link
Member

@pietroalbini pietroalbini left a comment

Choose a reason for hiding this comment

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

The refactored code looks much better! Left a few minor comments, and once those and the previous ones are fixed I feel we can merge!

match response {
Ok((_headers, _status, json)) => {
if let Some(mut json) = json {
processed_app_list.append(&mut json);
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason why you don't just use the Vec in the json variable instead of moving its elements to another one?

Copy link
Collaborator Author

@nellshamrell nellshamrell Mar 6, 2020

Choose a reason for hiding this comment

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

I was having some trouble with persisting the json variable outside of the if expression (and then passing it to msg.reply). Going to see if I can find a more elegant solution.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just did a small refactor where I

Is there a better way to do this? I'm completely open to refining it further!

Copy link
Member

Choose a reason for hiding this comment

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

Personally I'd replace the match and the reply with:

msg.reply(ctx, match response {
    Ok((_, _, Some(apps))) => app_response(apps),
    Ok((_, _, None)) => "You have no Heroku apps".into(),
    Err(err) => {
        println!("Err {}", err);
        "An error occured while fetching your Heroku apps".into()
    }
})?;

Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
… do it once for the config

Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
@nellshamrell
Copy link
Collaborator Author

Why do you have a config module nested inside the config module, by the way? I think one level of config would feel enough. :)

I'm...not entirely sure. I blame it on lack of caffeine. Fixed!

Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
@nellshamrell
Copy link
Collaborator Author

One solution for the Config object is to wrap it in an Arc. This allows you to sneak a shared reference out without holding on to the read lock for the context – see smarnach/crates-io-ops-bot@30dda80 for a quick implementation attempt. This also makes it easy to wrap the config extraction in a function.

Excellent point - done!

Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
@nellshamrell
Copy link
Collaborator Author

@pietroalbini @smarnach - thank you so much for the very thoughtful review and feedback! This is Open Source at its finest!

I believe I have addressed all of your concerns - please let me know if this is good to merge!

Copy link
Member

@pietroalbini pietroalbini left a comment

Choose a reason for hiding this comment

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

This looks great! Thanks Nell!

Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
@nellshamrell nellshamrell merged commit 0f1c60a into rust-lang:master Mar 6, 2020
@smarnach
Copy link
Contributor

smarnach commented Mar 6, 2020

Regarding the Heroku client library, it looks like that library is not a good fit for us. It probably causes more problems than it solves.

I haven't looked at the code in detail, but it's completely unclear to me why a REST API client should own a Tokio event loop with all that entails. The first version of the lib was released less than a week ago, and it hardly has any documentation. It's very well possible that it is meant for a very specific use case, and it looks like that use case is quite different from ours.

From what I've seen, I believe it would be way less trouble to simply send the REST request with reqwest than trying to twist heroku_rs to fit our use case.

@nellshamrell
Copy link
Collaborator Author

@smarnach We certainly could use reqwest to send the API commands and I have that under consideration. My goal with using heroku_rs was to work with the creator (whom I have been in contact with) of it to improve it with a real world use scenario. If it is truly not fitting our needs, I am happy to send the requests using reqwest, but I want to try to work with heroku_rs for a little longer.

@smarnach
Copy link
Contributor

@nellshamrell Thanks for your reply. It's good to know you are in contact with the creator – it would indeed be nice to turn the library into something more generally useful.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants