It is currently February 22nd, 2020, 6:54 am

Get string from WebParser for use in 2nd WebParser

Help with creating, editing & fixing problems with skins
OfficerHalf
Posts: 3
Joined: January 6th, 2020, 4:52 pm

Get string from WebParser for use in 2nd WebParser

Post by OfficerHalf »

Okay, so I'm writing a skin that's an Azure DevOps status dashboard. Shows open PRs assigned to me, last build status, last release status, etc.

I'm stuck getting that last one; the rest API for devops allows you to list releases, but that doesn't get you all the detailed info on a release, only the broad stuff. From that call, you can get the release id and make a 2nd call with that ID.

Code: Select all

; Release Status
; Get overall release list first, to get ID of release
[ReleaseList]
Measure=WebParser
URL=https://vsrm.#CoreServer#/#Organization#/#Project#/_apis/release/releases?$top=1&definitionId=#ReleaseDefinition#&api-version=5.1
Header=Content-Type: application/json
Header2=Authorization: Basic #AccessToken#
RegExp=(?siU)"id":(.*),.*

; Should just be int of release id
[ReleaseId]
Measure=WebParser
URL=[ReleaseList]
StringIndex=1

; Use release id to get detailed info
; Get status of only the specified release environment
[ReleaseStatus]
Measure=WebParser
URL=https://vsrm.#CoreServer#/#Organization#/#Project#/_apis/release/releases/[ReleaseId]?api-version=5.1
Header=Content-Type: application/json
Header2=Authorization: Basic #AccessToken#
Debug=2
RegExp=(?siU)"environments".*"name":"#ReleaseEnvironment#".*"status":"(.*)",

[MeasureReleaseStatus]
Measure=WebParser
URL=[ReleaseStatus]
StringIndex=1
I don't even see the [ReleaseStatus] call being made in fiddler, just the [ReleaseList] call. WebParserDump.txt is never created. If I swap out the [ReleaseId] section substitution for the actual release Id it works.

How can I use the value of the first WebParser in a 2nd? Maybe something with dynamic variables? Wasn't able to get that working either. Bear with me, I'm new to this. :D

My backup plan is just to chuck all this code and write it as a plugin instead, since C# is what I do day to day, but I figured I'd at least give this a shot first.
User avatar
balala
Rainmeter Sage
Posts: 9741
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Get string from WebParser for use in 2nd WebParser

Post by balala »

OfficerHalf wrote:
January 6th, 2020, 8:13 pm
I don't even see the [ReleaseStatus] call being made in fiddler, just the [ReleaseList] call. WebParserDump.txt is never created. If I swap out the [ReleaseId] section substitution for the actual release Id it works.

How can I use the value of the first WebParser in a 2nd? Maybe something with dynamic variables? Wasn't able to get that working either. Bear with me, I'm new to this. :D
If I'm not wrong the site in cause requires logon. Am I right? Because if I am, probably the skin / measures won't work, because WebParser measures can't parse information from sites requiring logon (second paragraph here).
So first question: is a logon required in order to get the desired information?
However to use what you're asking for requires to prefix the name of the [ReleaseId] measure with the & character, this way: URL=https://vsrm.#CoreServer#/#Organization#/#Project#/_apis/release/releases/[&ReleaseId]?api-version=5.1 (last paragraph of the same link as above). Besides this, don't forget to set on the dynamic variables, through a DynamicVariables=1 option.
OfficerHalf
Posts: 3
Joined: January 6th, 2020, 4:52 pm

Re: Get string from WebParser for use in 2nd WebParser

Post by OfficerHalf »

balala wrote:
January 6th, 2020, 8:32 pm
If I'm not wrong the site in cause requires logon. Am I right? Because if I am, probably the skin / measures won't work, because WebParser measures can't parse information from sites requiring logon (second paragraph here).
So first question: is a logon required in order to get the desired information?
Sort of. It requires auth, but will take a static access token, so it's not an actual login process. Thats what Header2 is. It's working with two other measures just fine. In this case I've configured the access token to be valid for a full year so it shouldn't be an issue any time soon.
balala wrote:
January 6th, 2020, 8:32 pm
However to use what you're asking for requires to prefix the name of the [ReleaseId] measure with the & character, this way: URL=https://vsrm.#CoreServer#/#Organization#/#Project#/_apis/release/releases/[&ReleaseId]?api-version=5.1 (last paragraph of the same link as above). Besides this, don't forget to set on the dynamic variables, through a DynamicVariables=1 option.
I tried this actually.

Code: Select all

; Use release id to get detailed info
; Get status of only the specified release environment
[ReleaseStatus]
Measure=WebParser
URL=https://vsrm.#CoreServer#/#Organization#/#Project#/_apis/release/releases/[&ReleaseId]?api-version=5.1
Header=Content-Type: application/json
Header2=Authorization: Basic #AccessToken#
Debug=2
RegExp=(?siU)"environments".*"name":"#ReleaseEnvironment#".*"status":"(.*)",
DynamicVariables=1
In fiddler I see a call, but it lacks any parameter at all where [&ReleaseId] is. However, combining that with UpdateRate=1 (just to force it to update) worked. I replaced that with a [!CommandMeasure ReleaseStatus Update] on the FinishAction of the first WebParser.

I'd tried all these things separately but couldn't quite get the perfect combination I guess. Thanks! Here's what seems to be working:

Code: Select all

; Release Status
; Get overall release list first, to get ID of release
[ReleaseList]
Measure=WebParser
URL=https://vsrm.#CoreServer#/#Organization#/#Project#/_apis/release/releases?$top=1&definitionId=#ReleaseDefinition#&api-version=5.1
Header=Content-Type: application/json
Header2=Authorization: Basic #AccessToken#
RegExp=(?siU)"id":(.*),.*
FinishAction=[!CommandMeasure ReleaseStatus Update]

; Should just be int of release id
[ReleaseId]
Measure=WebParser
URL=[ReleaseList]
StringIndex=1

; Use release id to get detailed info
; Get status of only the specified release environment
[ReleaseStatus]
Measure=WebParser
URL=https://vsrm.#CoreServer#/#Organization#/#Project#/_apis/release/releases/[&ReleaseId]?api-version=5.1
Header=Content-Type: application/json
Header2=Authorization: Basic #AccessToken#
Debug=2
RegExp=(?siU)"environments".*"name":"#ReleaseEnvironment#".*"status":"(.*)",
DynamicVariables=1

[MeasureReleaseStatus]
Measure=WebParser
URL=[ReleaseStatus]
StringIndex=1
Would it make sense to set a very large UpdateRate on the 2nd call since it should only be called when the first one updates?
User avatar
balala
Rainmeter Sage
Posts: 9741
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Get string from WebParser for use in 2nd WebParser

Post by balala »

OfficerHalf wrote:
January 6th, 2020, 9:03 pm
In fiddler I see a call, but it lacks any parameter at all where [&ReleaseId] is. However, combining that with UpdateRate=1 (just to force it to update) worked. I replaced that with a [!CommandMeasure ReleaseStatus Update] on the FinishAction of the first WebParser.
Yes, the explanation is that when the first parent measure [ReleaseList] gets the value (and through it, [ReleaseId] gets its value same time, being a child measure of the first one), the second parent measure ([ReleaseStatus]) should be updated, because if you update it before the moment when the previous measures got their values, it fails, not having a valid URL yet. This update is done by the posted FinishAction option.
Congratulations you figured this out, good job, especially if you are a new user. :thumbup:
OfficerHalf wrote:
January 6th, 2020, 9:03 pm
Would it make sense to set a very large UpdateRate on the 2nd call since it should only be called when the first one updates?
Definitely. For instance if you set the UpdateRate to 86400, you get one update per day.