0

I have find out this called servicehooks link

But I want to do this programmatically where I have more number of projects and want to check any of that project repository has code push event happened , if yes need to check which files are pushed as a commit.

and based on that push message into my service bus queue.

any sample code for the same? looking for azure function app for above solution.

Neo
  • 15,491
  • 59
  • 215
  • 405

1 Answers1

1

You can subscribe to code push events using ADO public API: Subscription create API

You want your request to look like this:

curl -H "Content-Type: application/json;api-version=4.0" \
  -H "Authorization: Basic $(B64_TOKEN)"
  --request POST \
  --data {
    "publisherId": "tfs",
    "eventType": "git.push",
    "resourceVersion": "1.0",
    "consumerId": "webHooks",
    "consumerActionId": "httpRequest",
    "consumerInputs": {"url": $(WEBHOOK_URL)}
  }
  https://dev.azure.com/$(ORGANIZATION)/_apis/hooks/subscriptions

This will subscribe you to all code push on all your repositories of all your projects of your organization.

When you receive a code push notification (see documentation), you can extract the commit ids from the resource object (you might need to fetch the Push object using the API).

Then you can inspect which file are impacted with the Commit API.

If you want to see the file diff, there is also an undocumented API.

Martin Faucheux
  • 884
  • 9
  • 26