gpt4 book ai didi

azure - 用于在 Azure DevOps 中监听事件的 Microsoft Power Automate 替代方案

转载 作者:行者123 更新时间:2023-12-03 05:38:16 26 4
gpt4 key购买 nike

目标:监听 Azure DevOps 中的事件并自动化 Azure DevOps 中的工作流程,例如关闭任务等。

努力:我正在使用 MS Power Automate 监听 Azure DevOps 中的事件,但它似乎运行得太慢(自触发后 1-2 分钟)。

需要建议:我们是否有任何 MS Power Automate 的替代方案可以缩短时间?

最佳答案

您可以尝试使用 Subscriptions 以编程方式创建订阅REST API:

https://learn.microsoft.com/en-us/azure/devops/service-hooks/create-subscription?view=azure-devops

以下示例可帮助您入门:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Mvc;

namespace Microsoft.Samples.VisualStudioOnline
{
public class ServiceHookEventController : Controller
{

// POST: /ServiceHookEvent/workitemcreated
[HttpPost]
public HttpResponseMessage WorkItemCreated(Content workItemEvent)
{
//Grabbing the title for the new workitem
var value = RetrieveFieldValue("System.field", workItemEvent.Resource.Fields);

//Acknowledge event receipt
return new HttpResponseMessage(HttpStatusCode.OK);
}

/// <summary>
/// Gets the value for a specified work item field.
/// </summary>
/// <param name="key">Key used to retrieve matching value</param>
/// <param name="fields">List of fields for a work item</param>
/// <returns></returns>
public String RetrieveFieldValue(String key, IList<FieldInfo> fields)
{
if (String.IsNullOrEmpty(key))
return String.Empty;

var result = fields.Single(s => s.Field.RefName == key);

if (result == null)
return String.Empty;

return result.Value;
}

}

public class Content
{
public String SubscriptionId { get; set; }

public int NotificationId { get; set; }

public String EventType { get; set; }

public WorkItemResource Resource { get; set; }

}

public class WorkItemResource
{
public String UpdatesUrl { get; set; }

public IList<FieldInfo> Fields { get; set;}

public int Id { get; set; }

public int Rev { get; set; }

public String Url { get; set; }

public String WebUrl { get; set; }
}

public class FieldInfo
{
public FieldDetailedInfo Field { get; set; }

public String Value { get; set; }

}

public class FieldDetailedInfo
{
public int Id { get; set; }

public String Name { get; set; }

public String RefName { get; set; }
}
}

关于azure - 用于在 Azure DevOps 中监听事件的 Microsoft Power Automate 替代方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60739338/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com