microsoft / microsoft/azure-devops-go-api
Settings not included in return value from `GetCheckConfiguration`/`GetCheckConfigurationsOnResource`
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 223
- Forks
- 92
- PR merge metrics
- No merged PRs in 30d
Description
I'm attempting to retrieve the branches from a branch protection check on an environment. I can add the Expand parameter to the request. This will return (to the SDK, but not to the user) the additional information with the call, but it doesn't get included in the CheckConfiguration struct that GetCheckConfigurationsOnResource (and GetCheckConfiguration) return, so it's effectively inaccessible:
checks, err := checksClient.GetCheckConfigurationsOnResource(context.Background(), pipelineschecks.GetCheckConfigurationsOnResourceArgs{
Project: &project,
ResourceType: &resourceType,
ResourceId: &resourceID,
Expand: &pipelineschecks.CheckConfigurationExpandParameterValues.Settings,
})
// checks[0].Settings does not exist, despite the API returning it
Unfortunately, the settings property doesn't follow a set structure, so the best we can do here is map[struct]interface{}.
Examples of returned settingses
"settings": {
"displayName": "Branch control",
"definitionRef": {
"id": "<UUID>",
"name": "evaluatebranchProtection",
"version": "0.0.1"
},
"inputs": {
"allowedBranches": "refs/heads/main",
"ensureProtectionOfBranch": "false"
},
"retryInterval": 5
},
"settings": {
"approvers": [
{
"displayName": null,
"id": "<UUID>"
}
],
"executionOrder": "anyOrder",
"minRequiredApprovers": 0,
"instructions": "Please review the output of the previous step before approving",
"blockedApprovers": []
},
This change appears to be sufficient to return the desired results:
diff --git a/azuredevops/v6/pipelineschecks/models.go b/azuredevops/v6/pipelineschecks/models.go
index 324792a..417237c 100644
--- a/azuredevops/v6/pipelineschecks/models.go
+++ b/azuredevops/v6/pipelineschecks/models.go
@@ -62,6 +62,8 @@ type CheckConfiguration struct {
ModifiedOn *azuredevops.Time `json:"modifiedOn,omitempty"`
// Timeout in minutes for the check.
Timeout *int `json:"timeout,omitempty"`
+ // Settings for the check configuration.
+ Settings map[string]interface{} `json:"settings,omitempty"`
}
type CheckConfigurationData struct {
Unfortunately, the header at the top of the file suggests I should not just submit this change as a PR:
// Generated file, DO NOT EDIT
// Changes may cause incorrect behavior and will be lost if the code is regenerated.
(I'll take a moment to advocate for releasing the code that generates this library, so that the community can be helpful in fixing issues like this! 🙂 Unfortunately, without that code, my hands are kind of tied on trying to fix this and other issues.)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in azuredevops/v6/pipelineschecks/models.go and inspect CheckConfiguration plus GetCheckConfiguration and GetCheckConfigurationsOnResource. Determine where the generated model source is maintained, since the file warns that manual edits will be lost. Done means the settings returned by the API are accessible through the SDK's CheckConfiguration value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100