jycouet / VSTSExtensions

MIT License
30 stars 11 forks source link

Feature Request: Non default project collections #7

Closed DavidParks8 closed 6 years ago

DavidParks8 commented 6 years ago

The company I work for has custom collections.

To achieve this, you can use the BUILD_REPOSITORY_URI environment variable.

jycouet commented 6 years ago

Hummm, I'm not sure to catch your point.

Today I use: SYSTEM_TEAMFOUNDATIONSERVERURI and add DefaultCollection So I get something like: https://xxx.visualstudio.com/DefaultCollection

On my side, I only have a DefaultCollection, so I don't know how it look like with other collections... I just looked at BUILD_REPOSITORY_URI and I have https://xxx.visualstudio.com/_git/yyy where yyy is my project name.

I didn't find DefaultCollection in env variable.

Let me know if I mist something 👍

DavidParks8 commented 6 years ago

Specifically, I'm referring to locally hosted tfs with custom collections behind a firewall. The url at my company would look more like https://tfs.internal.com/tfs/CollectionName/...the rest of the url. To that end, we have multiple collections, and sometimes multiple git repos per team project.

What url does renovate need in order to hook into vsts? I was (perhaps incorrectly) assuming that it was the git repo url.

jycouet commented 6 years ago

Yes I see.

In fact, in Renovate: https://xxx.visualstudio.com/DefaultCollection is the endpoint And in Renovate Me, I target the current repo selected in the build task (with BUILD_REPOSITORY_NAME) of the endpoint.

Do you have an env variable with the collection information? If not I would suggest that we have an option to change the collection at the task level. (I would set DefaultCollection by default)

What do you think?

DavidParks8 commented 6 years ago

From some searching, it looks to me like SYSTEM_TEAMFOUNDATIONCOLLECTIONURI actually contains the collection path when executed from tfs. In that case, appending DefaultCollection wouldn't be necessary.

DavidParks8 commented 6 years ago

It just occurred to me that git repo names might not have to be unique in a collection. They do need to be unique in a team project. How does renovate know which git repo to target if it executes at the collection scope?

jycouet commented 6 years ago

Ho, you are right!!! DefaultCollection is not mandatory!

jycouet commented 6 years ago

The first arg of renovate is the target gir repo to renovate. and I use BUILD_REPOSITORY_NAME for that.

jycouet commented 6 years ago

Done here https://github.com/jycouet/VSTSExtensions/commit/20f28c5c610eae048e6c908212dbf0522367a36a

DavidParks8 commented 6 years ago

I think the endpoint actually needs to be ${instance}${project} so that the api is scoped down to the correct git repo. You can get project from SYSTEM_TEAMPROJECT.

jycouet commented 6 years ago

Humm, I don't think so. Look here: https://github.com/jycouet/VSTSExtensions/blob/20f28c5c610eae048e6c908212dbf0522367a36a/renovateMe/buildtask/src/index.ts#L54

Where repo is your git repository and endpoint is https://xxx.visualstudio.com/


Maybe it's missing the project level! But I don't know where to put it.

DavidParks8 commented 6 years ago

Specifically, I was thinking:

const project: string | undefined = process.env["SYSTEM_TEAMPROJECT"];
if (!project) {
  throw new Error('Could not determine team project. This task may not be compatible with your build system.');
}
...

const renovateArgs: string = `${repo} --platform vsts --endpoint ${endpointAndCollection}${project} --token ${token}`; 
jycouet commented 6 years ago

This will not work (I just cheked now). Renovate is waiting in the endpoint for: https://xxx.visualstudio.com/cccCollection.

The project level is not consider in renovate. (sorry about that it was already me ^^). https://github.com/singapore/renovate/blob/14031f0f816d1402fafabad8732d1cae471f4761/lib/platform/vsts/index.js#L60 Across all the collection I check the name of repos and take the first match.

I just cheked now too, and look what I have in getRepos(). I created 2 project tmpDS and tmpDS2 and in each I have a repo named tmpDS

[{ 
   name: 'tmpDS',
   project:
     {
       name: 'tmpDS'
     }
},
{ 
   name: 'tmpDS',
   project:
     {
       name: 'tmpDS2'
     }
}]

In this case, here, I will take the first one. :(

jycouet commented 6 years ago

Not sure how to fix it. My first idea is: replace the arg repo by projectName/repoName? if no / use the previous strategy?

DavidParks8 commented 6 years ago

Have you tried to use the new url I proposed? I'm under the impression that it will still work because vsts has the same git api for both project and collection level scopes.

jycouet commented 6 years ago

Yes I just tried and it's not working :(

DavidParks8 commented 6 years ago

What's the exact error?

jycouet commented 6 years ago

The error is in the lib I used in renovate: https://github.com/Microsoft/vsts-node-api

let vsts = require('vso-node-api');

// your collection url
let collectionUrl = "https://fabrikam.visualstudio.com/defaultcollection";

// ideally from config
let token: string = "cbdeb34vzyuk5l4gxc4qfczn3lko3avfkfqyb47etahq6axpcqha"; 

let authHandler = vsts.getPersonalAccessTokenHandler(token); 
let connect = new vsts.WebApi(collectionUrl, authHandler);   
DavidParks8 commented 6 years ago

That makes sense. It isn't part of the git api. Well, in that case, I support your projectName/repoName idea.

jycouet commented 6 years ago

Ok, I'll do this asap :)

jycouet commented 6 years ago

I reopen because I need to implement here too ^^. I'll do it tonight

jycouet commented 6 years ago

Should be working now :)