Skip to content

English

Elvis Souza edited this page Feb 23, 2022 · 14 revisions

Requisites

  • SQL Server
  • .Net Core 3.1+ Application
  • Azure DevOps Account

Installation and Configuration

Package installation

PM > Install-Package AzureDevOpsTracker

Step 1 - Configuring the Startup.cs

Once the nuget is installed, update the Startup.cs OWIN file of your .net application with the code ahead:

public void ConfigureServices(IServiceCollection services)
{
    services.AddAzureDevopsStateTracker(new AzureDevopsStateTracker.Data.DataBaseConfig("[CONNECTION_STRING]"));
}

public void Configure(IApplicationBuilder app, IServiceProvider serviceProvider)
{
    app.UseAzureDevopsStateTracker(serviceProvider);
}

Step 2 - Creating the Controller

For the Azure DevOps Service Hook Integration, it is necessary that your application has/have two EndPoints to receive a POST HTTP Request with a specific Json. These endpoints will receive Workitems data when it is created or updated.

public class ExampleController : Controller
{
    private readonly IAzureDevopsTrackerService _azureDevopsTrackerService;

    public ExampleController(
        IAzureDevopsTrackerService azureDevopsTrackerService)
    {
        _azureDevopsTrackerService = azureDevopsTrackerService;
    }

    [HttpPost("workitem-updated")]
    public async Task<IActionResult> WorkItemUpdated([FromBody] UpdatedWorkItemDTO updatedWorkItemDTO)
    {
        await _azureDevopsTrackerService.Update(updatedWorkItemDTO);
        return Ok();
    }

    [HttpPost("workitem-created")]
    public async Task<IActionResult> WorkItemCreated([FromBody] CreateWorkItemDTO createWorkItemDTO)
    {
        await _azureDevopsTrackerService.Create(createWorkItemDTO);
        return Ok();
    }

    [AllowAnonymous]
    [HttpGet("release-changelog")]
    public IActionResult ReleaseChangelog()
    {
        var changeLog = _changeLogService.Release();
        if (changeLog is null) return new OkObjectResult("There's no WorkItems waiting for a ChangeLog");
           var message = _changeLogService.SendToMessengers(changeLog);
        return new OkObjectResult(message);
    }

    [AllowAnonymous]
    [HttpGet("count-items-for-release")]
    public IActionResult CountItemsForRelease()
    {
       try
       {
            var count = _changeLogService.CountItemsForRelease();
            var returnText = new StringBuilder();
            if (count == 0 || count == 1)
                returnText.Append($"{count} Item");
            else
                returnText.Append($"{count} Items");

            return new OkObjectResult(new { data = returnText.ToString() });
        }
        catch (Exception ex)
        {
            return new OkObjectResult(new { data = ex.Message });
        }
    }
}

For more informations and an example about the Azure DevOps Tracker in a Azure Function, visit our repository Azure DevOps Function Tracker.

Configuring the Azure DevOps

Creating the subscription

Step1

Configuring the service

Step2 Step3 Step4

The same steps has to be done to “WorkItem Updated”.

Configuring the ChangeLog

In Azure Devops Process Configuration Page is possible to edit the WorkItem fields. To the ChangeLog be functional, one field called exactly by "ChangeLog Description" needs to be created. Step5

When some WorkItem status change to Closed and there is some text in ChangeLog Description field, this WorkItem will be waiting for a ChangeLog. It's possible to know how many items are waiting for a ChangeLog through the method IChangeLogService.CountItemsForRelease().

In the Controller example above, the Action count-items-for-release has this responsability.

To release a ChangeLog, the method IChangeLogService.Release() must be called and, if you want to publish then in some Messenger we have support, the method IChangeLogService.SendToMessengers(changeLog) need to be called.

In the Controller example above, the Action release-changelog has this responsability.

To make it easier to use ChangeLog, we recomend to use the site https://shields.io/ to create a button that display the number of items waiting for ChangeLog and when click it the ChangeLog is released and published.

Shields.io Button example: [![Button](https://img.shields.io/badge/dynamic/json?color=%237bd1d7&style=for-the-badge&label=RELEASE%20CHANGELOG&query=%24.data&url=[YOUR API URL]/count-items-for-release)]([YOUR API URL]/release-changelog)

The result:

image

To the correct use of ChangeLog in Microsoft Teams and Discord, a Webhook needs to be created. For more informations about how to create a webhook, see:

Discord: https://support.discord.com/hc/en-us/articles/228383668-Usando-Webhooks

Microsoft Teams: https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook

Microsoft Teams ChangeLog message example: image

That’s it! Now all changes made to WorkItems will be automatically saved in the database and your team will have an automatic ChangeLog!! 🎉😍

Examples

Time by State in a Sprint:

select 
	t.State, 
	dbo.ToTime(AVG(t.TotalWorkedTime)) as AvgTime,
	dbo.ToTime(MAX(t.TotalWorkedTime)) as MaxTime,
	dbo.ToTime(MIN(t.TotalWorkedTime)) as MinorTime,
	dbo.ToTime(SUM(t.TotalWorkedTime)) as SumTime,
	AVG(t.TotalWorkedTime / 60 / 60) as AvgInHours
from WorkItems w
join TimeByStates t on t.WorkItemId = w.Id
where 1=1 
and w.IterationPath = 'Sprint 12'
and w.Type IN ('Bug', 'Task')
group by t.State

Longest Tasks and Bugs by time at Active State in a Sprint:

select 
	w.Id, 
	w.Title,
	dbo.ToTime(t.TotalWorkedTime) as TotalWorkedTime, 
	w.AssignedTo,
	t.TotalWorkedTime
from WorkItems w
join TimeByStates t on t.WorkItemId = w.Id
where w.IterationPath = 'Sprint 12'
and w.Type IN ('Bug', 'Task')
and t.TotalWorkedTime > 60
and t.State = 'Active'
order by t.TotalWorkedTime desc

Live Demo

We have a DataBase with a public user to help you test the Azure DevOps Tracker in fully working!

  • Server: tcp:sql-azure-devops-tracker.database.windows.net,1433
  • Database: sqldb-azure-devops-tracker
  • User: public_user
  • Password: @Adt123456_

Azure DevOps project link that is connected to this database: Azure Devops - TypingHard

Work in Progress

Board Status