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

Auto-increment default names for PRs #334

Merged
merged 8 commits into from
Oct 11, 2018

Conversation

devonhollowood
Copy link
Contributor

Fix #306

I thought that the easiest way to go about this was to adjust default_experiment_name(), and to just have it automatically try new names in case of a clash until it finds one that works. This makes the assumption that there won't be too too many experiments for a given PR, since experiment N will make N calls to the database, which is only really okay if N is small. Let me know if you'd like me to do something smarter here, or to adjust a different area of the code instead.

@pietroalbini
Copy link
Member

Thanks for the PR!

Unfortunately there is a bug with your implementation: you always generate a new name for the experiment, but the new name should only be generated for the run command. Other commands should only return the latest one.

As for the n+1 queries, it shouldn't really be a problem (I don't expect to have more than 5 runs for a single PR). If you still want to avoid that you could select the count of experiments pointing to the same PR (checking the API URL in the database).

Example of the bug

schermata del 2018-10-05 21 12 54

@devonhollowood
Copy link
Contributor Author

Ah, that makes sense. I'll take another shot at this tonight then.

@devonhollowood
Copy link
Contributor Author

Okay, I think it should work now. If not, I'll try to catch you on Discord to discuss some more.

Let me know if you want me to squash these commits or anything.

@pietroalbini
Copy link
Member

There are still a few quirks in the implementation: if a second run is created and then edited, the edit command uses the first run's name.

Example of the bug

screenshot_2018-10-08_21-54-21


The way I'd like to see this implemented is the following:

  • If the command creates a new experiment (run) always store the name in the database
    • If the user provides a custom name store that
    • Otherwise just generate a new one with the logic you wrote
  • If the command changes an existing experiment:
    • If the user provided a custom name use that and store it in the database
    • Otherwise look for a saved name in the database
    • If no saved name is present don't generate a new name, instead return an error

If you have any doubt just ping me on Discord!

Also, don't auto-increment user-supplied names
if name_supplied {
name
} else {
let new_name = auto_increment_experiment_name(&data.db, &name)?;
Copy link
Member

Choose a reason for hiding this comment

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

By passing as argument the previously stored name this is generating weird results, like last-name-1-1-1 (like pr-123-1-1-1-1).

@@ -15,7 +15,17 @@ pub fn ping(data: &Data, issue: &Issue) -> Result<()> {
}

pub fn run(host: &str, data: &Data, issue: &Issue, args: RunArgs) -> Result<()> {
let name = get_name(&data.db, issue, args.name)?;
let name = {
let name_supplied = args.name.is_some();
Copy link
Member

Choose a reason for hiding this comment

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

This can be factored out as a standalone function, so it's easily testable.

@devonhollowood
Copy link
Contributor Author

I think that commit addresses the issues you brought up and behaves as specified; let me know if I missed something.

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 works great now, thanks! I left a small comment, and then this can be merged.

name = format!("pr-{}-{}", issue.number, idx);
idx = idx
.checked_add(1)
.expect("too many similarly-named pull requests");
Copy link
Member

Choose a reason for hiding this comment

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

Can you avoid panicking here? I'd prefer for the server not to crash if someone creates way too many experiments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@pietroalbini
Copy link
Member

Thanks!

@bors r+

@bors
Copy link
Contributor

bors commented Oct 11, 2018

📌 Commit b763389 has been approved by pietroalbini

@bors
Copy link
Contributor

bors commented Oct 11, 2018

⌛ Testing commit b763389 with merge d2e54c1...

bors added a commit that referenced this pull request Oct 11, 2018
…etroalbini

Auto-increment default names for PRs

Fix #306

I thought that the easiest way to go about this was to adjust `default_experiment_name()`, and to just have it automatically try new names in case of a clash until it finds one that works. This makes the assumption that there won't be too too many experiments for a given PR, since experiment `N` will make N calls to the database, which is only really okay if N is small. Let me know if you'd like me to do something smarter here, or to adjust a different area of the code instead.
@bors
Copy link
Contributor

bors commented Oct 11, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: pietroalbini
Pushing d2e54c1 to master...

@bors bors merged commit b763389 into rust-lang:master Oct 11, 2018
@pietroalbini
Copy link
Member

Changes deployed.

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.

3 participants