Skip to content

Fix for Cloning gitlab URL chooses GitHub repository with same name - #4362

Closed
JordanMussi wants to merge 13 commits into
desktop:masterfrom
JordanMussi:gh-4154
Closed

JordanMussi wants to merge 13 commits into
desktop:masterfrom
JordanMussi:gh-4154

Conversation

@JordanMussi

Copy link
Copy Markdown
Contributor

Fixes #4154

I have also added some unit tests for the findAccountForRemoteURL method and would like some feedback:

  • Should I be using the repository given as an example in Cloning gitlab URL results in GitHub repository being cloned. #4154 (https://gitlab.com/inkscape/inkscape.git/https://github.com/inkscape/inkscape.git) or use one provided by the desktop team?
    const account = await findAccountForRemoteURL(
    'https://gitlab.com/inkscape/inkscape.git',
    accounts
    )
  • How should I test that the correct GitHub account is selected for a repository?
    // TODO check authenticated account is used
    /* it('finds the account for GitHub owner/name repository', async () => {
    const account = await findAccountForRemoteURL('desktop/repo-fixture', accounts)
    expect(account).not.to.equal(null)
    expect(account!.login).to.equal('joan')
    }) */
    This is what I want to do but since the credentials are being faked the call to canAccessRepository returns false so the account is ignored and the "anonymous" account is returned instead.

Also there is a discrepancy between how an account is identified for a parsed GitHub URL (https://github.com/inkscape/inkscape.git) and an owner/name (inkscape/inkscape).
For the former canAccessRepository is not called, so the first GitHub account found is returned.

const parsedURL = parseRemote(urlOrRepositoryAlias)
if (parsedURL) {
const account =
allAccounts.find(a => {
const htmlURL = getHTMLURL(a.endpoint)
const parsedEndpoint = URL.parse(htmlURL)
return parsedURL.hostname === parsedEndpoint.hostname
}) || null
// If we find an account whose hostname matches the URL to be cloned, it's
// always gonna be our best bet for success. We're not gonna do better.
if (account) {
return account
}
}

Whereas canAccessRepository is called when identifying from owner/name.
for (const account of sortedAccounts) {
const canAccess = await canAccessRepository(account, owner, name)
if (canAccess) {
return account
}
}

Except for those queries this is good to go 🙃

@JordanMussi

JordanMussi commented Mar 29, 2018 •

Copy link
Copy Markdown
Contributor Author

Hmm not sure why Travis is failing this test, it works for me and the other two CIs...

it('finds the anonymous account for public GitHub owner/name repository', async () => {
const account = await findAccountForRemoteURL('inkscape/inkscape', [])
expect(account).not.to.equal(null)
expect(account!).to.eql(Account.anonymous())
})

 1 failing
  1) findAccountForRemoteURL
       finds the anonymous account for public GitHub owner/name repository:
      AssertionError: expected null to not equal null
      + expected - actual
      at it (/home/travis/build/desktop/desktop/app/test/unit/find-account-test.ts:48:28)
      at <anonymous>

@iAmWillShepherd iAmWillShepherd added ready-for-review Pull Requests that are ready to be reviewed by the maintainers and removed ready-for-review Pull Requests that are ready to be reviewed by the maintainers labels Apr 2, 2018
@JordanMussi

Copy link
Copy Markdown
Contributor Author

I'm a bit stumped by these tests... When doing it manually in the app I am getting the results which I expect but with the tests I'm getting odd results.

The builds for 1138c31 gives finds the account for GitHub owner/name repository failing and the other tests passing. But after moving the test down in 4c60ca2, the builds pass that test that test except for Travis which fails that test and finds the anonymous account for public GitHub owner/name repository.

I can't see any way that the order of the tests would impact their results so any help would be appreciated.

@shiftkey

shiftkey commented Apr 8, 2018

Copy link
Copy Markdown
Member

@JordanMussi I've added some tracing to those tests - I couldn't trigger the same error on my Ubuntu VM, and I'm not sure what Linux-specific thing you might have tripped with these changes...

@JordanMussi

Copy link
Copy Markdown
Contributor Author

@shiftkey I'm running the tests locally on Windows. Is there any reason there might be discrepancies caused by the order of the tests in the file? (See the builds of my previous commits to this branch)

Please could you also address some of the points I raised in the first post? 😃

@shiftkey shiftkey changed the title Fixes #4154 Cloning gitlab URL results in GitHub repository being cloned Fix for Cloning gitlab URL chooses GitHub repository with same name Apr 15, 2018
@shiftkey

Copy link
Copy Markdown
Member

Is there any reason there might be discrepancies caused by the order of the tests in the file? (See the builds of my previous commits to this branch)

Not that I'm aware of - Mocha tests should be run in the order they're declared in the file.

Should I be using the repository given as an example in #4154

This seems fine.

How should I test that the correct GitHub account is selected for a repository?

My gut feeling at this point is that canAccessRepository is behaviour that we want to control in the test runner, so aren't relying on the real GitHub API for some of these tests. That probably means extracting that function out - if you think that's the right approach, I'm happy to work through figuring out the next steps.

For the former canAccessRepository is not called, so the first GitHub account found is returned.
...
Whereas canAccessRepository is called when identifying from owner/name.

If you've given a full URL we'll look for an existing account associated with that host. I think the latter check is there to confirm that owner/name does match a real repository on GitHub (or GitHub Enterprise). Unless you've got concerns about that behaviour, I'm happy to leave that as-is.

@denitsa-md

denitsa-md commented Jun 29, 2018 •

Copy link
Copy Markdown

@JordanMussi Any idea when this will be merged? :)

Comment thread wallaby.js Outdated
@@ -0,0 +1,17 @@
module.exports = function (wallaby) {

This comment was marked as spam.

This comment was marked as spam.

@JordanMussi

Copy link
Copy Markdown
Contributor Author

@denitsa-cm we just need to figure out how to properly test this before merging :)

As long as @shiftkey is fine with the strange problem I was having with the tests which then started passing only after adding console.log statements then it's just about testing the correct account is returned.

@shiftkey shiftkey self-assigned this Jul 6, 2018
@shiftkey

shiftkey commented Jul 6, 2018

Copy link
Copy Markdown
Member

As long as @shiftkey is fine with the strange problem I was having with the tests which then started passing only after adding console.log statements then it's just about testing the correct account is returned.

I'm not, and I'm assigning myself back to this to dig into it more. The tests are great here, and I might get them reviewed and merged separately to figuring out what we're doing with this fix.

@shiftkey

Copy link
Copy Markdown
Member

Alright, I went a slightly different path with #5200 but I think that addresses all the outstanding issues here.

I'm going to close this out in favour of that, but feel free to 👀 it over and add your feedback there.

Thanks again @JordanMussi for the time spent here!

@shiftkey shiftkey closed this Jul 19, 2018
@lock lock Bot locked as resolved and limited conversation to collaborators Sep 17, 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants