Giter Site home page Giter Site logo

Comments (4)

T-Hugs avatar T-Hugs commented on August 18, 2024

I like (1). It's not exposed now, but it's definitely something we could do. It might even be worth it to break it into its own project and make it a dependency of tfx-cli. Thanks.

from tfs-cli.

bryanmacfarlane avatar bryanmacfarlane commented on August 18, 2024

One complication - there's a proposal on the table to port this to core CLR (C#) and we are maintaining tfx "api" and compat via the cmd line args. So consumers shouldn't notice the internal impl. If we did this, it would be a problem.

what we could do is move the cred provider/storage stuff over to classes in vso-node-api. would that work?

from tfs-cli.

kasajian avatar kasajian commented on August 18, 2024

bryan, i do like the idea of splitting off the credential store, but i wanted to also let you know that since i posted that, I came up with a method that allows me to pull out the information like so:

var fs = require('fs');
var userhome = process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'];
var cred = fs.readFileSync(userhome + '/.tfx/http__gitsourceserver8080_tfs_Netaphor/.allusers').toString().split(':')
var id=cred[1];
var pw=cred[2];

Then we can issue a curl command straight from node:

var exec = require('child_process').exec;
var postbody =  JSON.stringify({
    query:
    "SELECT [System.Id] FROM WorkItemLinks WHERE ([Source].[System.TeamProject] = @project  AND  [Source].[System.Id] = 2308) And ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward') ORDER BY [System.Id], [Microsoft.VSTS.Common.BacklogPriority] mode(Recursive)"
});

var crypto = require('crypto');
var tempfilename = 'postdata_'+crypto.randomBytes(4).readUInt32LE(0)+'.json';
fs.writeFileSync(tempfilename, postbody);

var curl_command = 'curl -u ' + id + ':' + pw + ' -X POST -H "Content-Type: application/json" -d @' + tempfilename + ' http://gitsourceserver:8080/tfs/Netaphor/SiteAudit/_apis/wit/wiql?api-version=1.0';

var child = exec(curl_command, function(err, stdout, stderr) {
    fs.unlinkSync(tempfilename);
    if (err) {
        console.log('Error: ' + stderr);
    } else {
        console.log('Output is: ' + stdout);
    }
});

So you're wondering why would we use curl and exec from Node when Node is a perfectly proper client to make REST calls. The reason is because we wanted our node client code to have a somewhat uniform interface, since we will also shell out to call tfx like so:

var exec = require('child_process').exec;

var tfx_command = `tfx workitem query --project SiteAudit --json --query "select [Microsoft.VSTS.Common.BacklogPriority], [System.State], [System.IterationPath], [System.WorkItemType], [System.Title], [System.Tags] from WorkItems where [System.State] <> 'Done' and [System.State] <> 'Removed' and [System.AssignedTo] = @me order by [Microsoft.VSTS.Common.BacklogPriority]"`;

var child = exec(tfx_command, function(err, stdout, stderr) {
    if (err) {
        console.log('Error: ' + stderr);
    } else {
//        console.log('Output is: ' + stdout);
        var o = JSON.parse(stdout);
        console.log('count: ' + o.length);
        for (var i = 0; i < o.length; i++) {
            console.log('  id: ' + o[i].id);
            console.log('  WorkItemType: ' + o[i].fields['System.WorkItemType']);
            console.log('  IterationPath: ' + o[i].fields['System.IterationPath']);
            console.log('  Title: ' + o[i].fields['System.Title']);
            console.log('  State: ' + o[i].fields['System.State']);
            console.log('  Microsoft.VSTS.Common.BacklogPriority: ' + o[i].fields['Microsoft.VSTS.Common.BacklogPriority']);
            console.log();
        }
    }
});

from tfs-cli.

kasajian avatar kasajian commented on August 18, 2024

What would be nice is to have a way to a command called "direct" or "rest" or something, where one can specify enough parameters to make a REST call. This way, when TFS has new APIs, they are immediately usable from this tool.

The user of tfx.cmd need to specify:

  • get or post
  • api end point. they don't have to specify the version or project/collection
  • standard parameters to specify project/colleciton
  • Right now, I'd say just assume "?version=1.0" is always appended.

So why not use REST directly? Because this tool provides:

  1. cred store
  2. uniform API for project/collection
  3. uniform output format support.

from tfs-cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.