Skip to content

Adds logic that determines what branch to use as the compare branch (NDDB) - #4783

Merged
nerdneha merged 54 commits into
masterfrom
making-inferences
Jun 19, 2018
Merged

nerdneha merged 54 commits into
masterfrom
making-inferences

Conversation

@iAmWillShepherd

@iAmWillShepherd iAmWillShepherd commented May 24, 2018 •

Copy link
Copy Markdown
Contributor

Fixes #4766

This PR encapsulates the logic detailed in the issue inside of a function.

Criteria to determine compare branch (in priority order)

  1. If the current branch has a PR associated with it, use the target branch of the PR (this can be a branch that exists on eitherupstream ororigin)
  2. If the repository is a fork, use the default branch on upstream (this is usually master)
  3. If the repository is hosted on GitHub, use the default branch on origin (this is usually master)
  4. Otherwise fall through to the local master branch (conventionally, the default branch is master)

Some notes up front, I'm not sure of the actual place this functions belongs, so I put it next to related functions. Since it's self contained, it shouldn't be a huge deal to move it to a better place.

  • Add function to encapsulate logic
  • Add helper function that can choose the right branch on forked repositories
  • Write some tests to exercise ☝️
  • Clean up

iAmWillShepherd added 2 commits May 24, 2018 15:08
Mutondi
Mutondi previously approved these changes May 25, 2018
@donokuda

Copy link
Copy Markdown
Contributor

If we all agree that it should return branch A instead, I'm happy to open another issue for that discussion, but I think what we have so far is a good starting off point.

I'm okay with punting on the Branch A -> Branch B scenario for now since I was under the impression that there were some technical aspects to be considered on inferring the parent branch correctly. [citation needed tho]

One thing to note is that the "default branch" doesn't necessarily mean "master". For example, the default branch could be "development" or "gh-pages" in some cases. If that's the case, then that should be the branch we compare against for the notification.

I wasn't able to tell by reading the code, but are we supporting this scenario?

@iAmWillShepherd

Copy link
Copy Markdown
Contributor Author

@donokuda, yes, that case is currently being supported. In situations where a default branch has not been set, we default to master.

@iAmWillShepherd

Copy link
Copy Markdown
Contributor Author

🥇

@nerdneha nerdneha left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So close to the finish line! Great changes

branches: ReadonlyArray<Branch>,
repository: Repository,
currentPullRequest: PullRequest | null,
currentBranch: Branch | null,

This comment was marked as spam.

This comment was marked as spam.

}

/**
* For `inferComparisonBranch` case where inferring for a pull request

This comment was marked as spam.

* @param branches The list of all branches for the repository
* @param repository The repository the branch belongs to
* @param ghRepository The github specific information for the repository
* @param currentBranch The branch we want the parent of

This comment was marked as spam.

): Promise<Branch | null> {
const defaultBranchName = ghRepository.defaultBranch

if (defaultBranchName === null) {

This comment was marked as spam.

This comment was marked as spam.

* @param branches The list of all branches for the repository
* @param ghRepository The repository the branch belongs to
*/
function _getDefaultBranchOfGithubRepo(

This comment was marked as spam.

This comment was marked as spam.

@nerdneha

Copy link
Copy Markdown
Contributor

@iAmWillShepherd should we also a unit test for the branchB returning master for now as the default branch so that, if we change functionality, we can change that test to expect branchA

@iAmWillShepherd

Copy link
Copy Markdown
Contributor Author

@iAmWillShepherd should we also a unit test for the branchB returning master for now as the default branch so that, if we change functionality, we can change that test to expect branchA

Not sure I understand this one.

Is the expectation that we return the parent branch (not sure of the proper Git terminology here)? I'll admit my current understanding of this is flaky, but I was under the impression that you can only check if a commit is a child of the tip of the current branch. Wouldn't this mean we can't reliably tell what the parent branch would be?

Can anyone in @desktop/eng provide some insight on this?

@iAmWillShepherd

Copy link
Copy Markdown
Contributor Author

💯

@nerdneha
nerdneha merged commit 0cffef1 into master Jun 19, 2018
@nerdneha
nerdneha deleted the making-inferences branch June 19, 2018 16:12
@lock lock Bot locked as resolved and limited conversation to collaborators Aug 18, 2018
@desktop desktop unlocked this conversation Sep 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review Pull Requests that are ready to be reviewed by the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants