How do I validate code in Azure DevOps PRs? - azure-devops

I'm working on a localization project where we are attempting to move all of our project's static strings to resource kvp files, which are generated from a 3rd party service. As a safeguard against missing translations, when a PR is made I would like to check that said resource files have a corresponding kvp for each key in the source code.
I understand from this documentation you can set up a web hook to call an Azure Function that can in turn set the status of the PR that triggered it. However, I am having difficulty in accessing the actual code of the source branch. It seems that all that is sent to the Azure Function is metadata about the PR itself.
Is there a way to use this functionality to validate the source code, or is there another method of running custom validation on an Azure DevOps PR?
Thanks!

From Ian Kemp's solution in the comments:
As the API documentation states, the PR endpoint returns an object containing various fields. The pull request will contain a sourceRefName which is a reference to the branch that the PR was made from. You can use that together with this answer to get the other file(s) you're interested in.

Related

An assertion on the test case file - Webdriverio

I need some help, I'm starting with this automation stuff, I like it but I'm still learning, recently I create a test case that basically is, going to a certain page and click on a button to upgrade the account on an specific sale, so I did that but when I got my PR reviewed and devops ask me if I can add an assertion.
So, this code is on the spec file not on the page objects file, so the devops mean I have to create the code on the page object file and then call it on the spec file???? any tip would be great and thanks!
You can do it either way. You can write the assertion in the spec file, or write the assertion in the page objects file and call it from the specs file. If the latter is your framework's code convention, you may want to do it that way for consistency, but either way should work.

Any way to get a link to a GitHub action's latest result?

GitHub's Actions feature recently started letting users generate badges, to showcase the status of their tests. For example, if I have a set of tests that run on my repo's dev branch from a file named .github/test_dev.yml, I can access that build's status by adding /badge.svg to the end of the test's URL.
https://github.com/<username>/<repo_name>/actions/workflows/test_dev.yml/badge.svg
That's great from the standpoint of keeping your project readme up to date with the status of the project, but the next logical step would be to also add a link to the badge that points to the latest testing outcome.
Unfortunately, even though you can access all the tests of a particular action as follows:
https://github.com/<username>/<repo_name>/actions/workflows/test_dev.yml
The test runs themselves seem to be behind a unique ID under actions/runs/.
https://github.com/<username>/<repo_name>/actions/runs/1234567890
Is there any way to construct a URL that just points to the latest test? Something like:
https://github.com/<username>/<repo_name>/actions/workflows/test_dev.yml?result=latest
I poked through GitHub's documentation, but even though there's some documentation surrounding the generation of those badge SVG's, I couldn't find anything about linking directly to the action that actually generated that SVG.
you can use this to get the id in a yaml file:
https://github.com/<username>/<repo_name>/actions/runs/${{ github.run_id }}

VSTS Extension - Release definition data, environment ids

I am developing web extension for VSTS. I am using vss sdk of Microsoft.
I got some issue.
You can see on the image that there is new line - App insights Settings
This pop up appears on clicking on 3 dots near every release definition on page of list of all releases.
This button navigates user to some environment of some specific release.
Example of link:
https://ozcodedev.visualstudio.com/OzCode/_releaseProgress?releaseId=372&_a=release-environment-logs&environmentId=850
The problem that I do not know how to fetch list of releases and environments for building this link.
How can I get them on page All release pipelines.
Through the GUI it is not possible to get all the release ids and the environment ids for each step. However this is possible through the VSTS APIS. You could use the release endpoint to and iterate to obtain your release id
https://{accountName}.vsrm.visualstudio.com/{project}/_apis/release/releases?api-version=4.1-preview.6
Once you have the release id you can use it like so
https://{accountName}.vsrm.visualstudio.com/{project}/_apis/release/releases/{releaseId}?api-version=4.1-preview.6
Within the returned JSON you can follow iterate the path environment[n].id to obtain the environment id.
You can then construct the link using this information.
Hope that helps
Ok. So after working 2 days on this issue I found solution.
1.It is possible to fetch data that I wanted on Client Side. For this I used Microsoft's library vss-web-extension-sdk. Install it - npm install vss-web-extension-sd --save.
2.Add relevant scopes to your vss-extension.json. In my case the problem was - that I needed data that relates to managing of VSTS user releases. So after Including "vso.release_manage" to my scopes array I stopped to got 401 Unauthorized error because access token was changed according to new scopes.
https://learn.microsoft.com/en-us/vsts/extend/develop/manifest?view=vsts#scopes
In this documentation you can check which scope controls which resources that can be accessed by your extension.
You can use our ts/js clients to get whatever you want for your experience.
We have extensive documentation available here. Let me know if you are blocked anywhere.

Determine current process template via TypeScript code

I am working on VSTS/TFS extension development work.I am trying to determine the name of current process template (whether Agile, CMMI, Scrum) via TypeScript code.
My requirement is updating workitem (bug, issue .etc.) status according to certain conditions. For same I need to identify prevalent process template name of the project. Reason is same workitem type in different templates have different status.
I am referring vsts-node-API to achieve this task. But I still couldn't figure out the way to fulfill this.
references:
https://github.com/Microsoft/vsts-node-api
https://www.visualstudio.com/en-us/docs/integrate/api/wit/templates
The response of rest api Get a team project can return "processTemplate" parameter:
GET https://{instance}/DefaultCollection/_apis/projects/{project}?api-version={version}[&includeCapabilities={boolean}&includeHistory={boolean}]

Enforcing policies from Atlassian Stash Repository merge request check plugin

I need help on how to successfully create a RepositoryMergeRequestCheck
As part of our merge workflow, we need to ensure some policies about some files. Policies includes among others:
File naming conventions of individual files
File naming conventions between multiple files (for example, correlative-named files)
Inspection of files to enforce or disallow usage of statements or functions
I want to be able to check for this policies on a repository merge request check so I’m building a plugin for Astlassian Stash
I have tried the following approaches:
Using the RepositoryMergeRequestCheckContext parameter of RepositoryMergeRequestCheck.check()
Since the method signature is:
#Override
public void check(RepositoryMergeRequestCheckContext context)
The first thing I tried using was the context parameter. I can say context.getMergeRequest().getPullRequest().getFromRef().getRepository()
Now I get a Repository instance and I’m not sure how to extract commit info from it.
Calling Git directly: Since this check was originally developed as a git hook script, calling git from the SDK made sense to me. It led me to this situation:
String result = gitScm.getCommandBuilderFactory().builder().lsTree().build(…).call();
Where gitScm gets dependency injected in the plugin’s constructor.
Notice the build parameter? It expects a CommandOutputHandler<T> in this case T is string, but that’s an interface, and I’m not sure how to get an instance that implements that interface or how to create one.
REST API
REST API looks the easiest of them but it still doesn’t help with the third requirement of inspecting file’s source code and also, spawning web requests from the merge request check that is itself a web request from stash doesn’t seem to be a good idea from the performance side.
What path should I follow or how can I do it?
I started writing you a response, and then realised that I'd already answered this on Answers (which was what I was going to suggest as well).
https://answers.atlassian.com/questions/182943/enforcing-policies-from-repository-merge-request-check-plugin
Cheers,
Charles