Skip to content

Instantly share code, notes, and snippets.

using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.IdentityModel.JsonWebTokens;
using Nito.AsyncEx;
namespace YourProject
{
public interface IAtlassianOAuthCredentialsManager
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
namespace YourProject
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Atlassian.Jira;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.Extensions.DependencyInjection;
function Remove-AzDServiceHook {
[CmdletBinding(DefaultParameterSetName = "ProjectName")]
param(
[Parameter(ParameterSetName = "ProjectId", ValueFromPipelineByPropertyName = $true)]
[Parameter(ParameterSetName = "ProjectName", ValueFromPipelineByPropertyName = $true)]
[ValidateSet($null, "git.push","git.pullrequest.created","git.pullrequest.updated","build.complete")]
[string] $EventType = $null,
[Parameter(ParameterSetName = "ProjectId", ValueFromPipelineByPropertyName = $true)]
[Parameter(ParameterSetName = "ProjectName", ValueFromPipelineByPropertyName = $true)]
[string] $ToUrl = $null,
function Update-AzDServiceHook {
param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[Microsoft.VisualStudio.Services.ServiceHooks.WebApi.Subscription] $Subscription,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[switch] $Enable,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[switch] $Disable
)
if($Enable) {
function New-AzDServiceHook {
[CmdletBinding(DefaultParameterSetName = "ProjectName")]
param(
[Parameter(Mandatory = $true, ParameterSetName = "ProjectId", ValueFromPipelineByPropertyName = $true)]
[string] $ProjectId,
[Parameter(Mandatory = $true, ParameterSetName = "ProjectName", ValueFromPipelineByPropertyName = $true)]
[string] $ProjectName,
[Parameter(Mandatory = $true, ParameterSetName = "ProjectId", ValueFromPipelineByPropertyName = $true)]
[Parameter(Mandatory = $true, ParameterSetName = "ProjectName", ValueFromPipelineByPropertyName = $true)]
[ValidateSet("git.push","git.pullrequest.created","git.pullrequest.updated","build.complete")]
function Get-AzDServiceHook {
[CmdletBinding(DefaultParameterSetName = "ProjectName")]
param(
[Parameter(ParameterSetName = "ProjectName", ValueFromPipelineByPropertyName = $true)]
[string] $ProjectName = $null,
[Parameter(ParameterSetName = "ProjectId", ValueFromPipelineByPropertyName = $true)]
[string] $ProjectId = $null,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[ValidateSet("git.push","git.pullrequest.created","git.pullrequest.updated","build.complete")]
[string] $EventType = $null,
# see https://docs.microsoft.com/en-us/azure/devops/integrate/concepts/dotnet-client-libraries?view=azure-devops
# for links to some of the nuget packages which contain these (this code was written against version 15.131.1)
Add-Type -Path "C:\YourPath\Newtonsoft.Json.dll"
Add-Type -Path "C:\YourPath\Microsoft.TeamFoundation.Client.dll"
Add-Type -Path "C:\YourPath\System.Net.Http.Formatting.dll"
Add-Type -Path "C:\YourPath\Microsoft.VisualStudio.Services.Common.dll"
Add-Type -Path "C:\YourPath\Microsoft.VisualStudio.WebApi.dll"
Add-Type -Path "C:\YourPath\Microsoft.VisualStudio.Services.ServiceHooks.dll"
$pat = "your-personal-access-token"
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace YourNamespace
{
[ApiController]
[Route("[controller]")]
public class YourController : ControllerBase
{
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.AspNetCore.Http;
namespace YourNamespace
{
// https://stackoverflow.com/questions/42686363/view-post-request-body-in-application-insights
public class TrackRequestBodyInitializer : ITelemetryInitializer
{