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
Extend setVariable to allow 'output' variables to be created #691
Conversation
Great work @johnnyreilly . I would have implemented it and raised a PR myself, but I hadn't yet read the contribution guidelines. |
Note that if you define the output variable in the task json, you don't need to pass the isoutput=true. |
That's fascinating @jessehouwing - is that documented anywhere do you know? |
Not that I know of. |
@johnnyreilly . One review comment I have is that the call to Personally, I'm not a big fan of boolean parameters - especially after reading Clean Code by Robert Martin (Uncle Bob) many years ago and being enlightened! My suggestion would be to use a new enum (I propose a new VariableScope enum with I've deliberately not changed the existing |
Hey @chris-codeflow!
Yeah I agree - my main motivation was to make a backwards compatible change. I'm not generally a fan of enums in TypeScript (something the TypeScript team is in agreement with) as they're not standard JS. An alternative approach might be an explicit Ultimately I don't feel to strongly about the approach as long as there is a way. 🤞 we'll have some interaction from the project owners on this PR soon! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution, this generally LGTM.
As far as the boolean flag vs enum goes, I agree with the original choice made by @johnnyreilly to use a boolean. As mentioned, enums are a little weird for TS; more importantly though, that's the pattern this library has followed - I'd rather not introduce a one-off difference in style.
@johnnyreilly could you do a few things so we can get this in and published:
- could you bump the minor version of the package.json/package-lock.json
- Would you mind applying these same changes/open a pr targeting the releases/3.x branch? Right now we're maintaining both the
2.x
and (preview)3.x
versions of this library, and I want to make sure this change gets into the 3.x version before it goes out of preview
Thanks @damccorm! I've just tested |
Thanks @johnnyreilly and @damccorm for the feedback on the boolean vs enum type decision; I am only just starting out with TypeScript, so it's good to know that enums are not a great choice in TypeScript. I suggested using a boolean when I raised the suggestion, so I was challenging my own suggestion when I commented on the type to use. As an aside, what is a good alternative to a boolean in TypeScript, integers with constants? |
Hey @chris-codeflow, So if I was designing a function which took a number of inputs (as VS Code actually offers this in the form of the "Convert parameters to destructured object" helper. eg export function setVariable({ name, val, secret = false, isOutput = false }: { name: string, val: string, secret?: boolean, isOutput?: boolean}): void {
// ...
} Where usage would look like this: setVariable({ name: 'foo', val: 'bar', isOutput: true }); |
Thanks @johnnyreilly . I've seen that pattern in other projects I've contributed to; it's much cleaner (in my opinion) as you can see in the calling code the option being set, which is far more readable than having to look at the method signature. |
By the way, it looks like you're based in Horsham? Small world! My Gran lived there all her life. West Sussex forever ❤️ |
Sorry the delayed response. I moved to Horsham in 2001. I was born in Croydon and was brought up in Worcester Park. |
This PR resolves #688 by extending the
setVariable
functionality to support output variables.As suggested by @chris-codeflow, this is as simple as adding the
isOutput=true
property to thetask.setvariable
logging command.The change is backwards compatible - it does not change the signature of
setVariable
. Rather it adds a new final parameter namedisOutput
. Whentrue
the command generated will featureisOutput=true
.Consider:
This would generate the following:
##vso[task.setvariable variable=foo;isOutput=true;]bar
Tests
I've added a couple of tests. However it's been a little difficult since I'm unable to run tests on my Ubuntu laptop. I have a sense that this may not be Linux related, I think this project may depend upon node 6 which is no longer supported. This is the error encountered why I typed "npm run test":