How to do it...

  1. After Azure has created the new Function App, you will then be able to create an Azure Function. All that we are going to do is to create an Azure Function that will be triggered whenever something happens on a GitHub repository. Click on the Create your own custom function link.
According to the Microsoft Azure site, the following are supported when writing Azure Functions: JavaScript, C#, F#, and scripting options such as Python, PHP, Bash, Batch, and PowerShell.
  1. You will now see that you are given a choice between several templates. Choose C# from the Language selection and API & Webhooks from the Scenario selection and then select the GitHubWebHook-CSharp template. Azure will now ask you to give your function a name. I called mine GithubAzureFunctionWebHook. Click on the Create button to create the function.
  1. When your function is created, you will see that it has added some default code for you in the online code editor.
        using System.Net;

public static async Task<HttpResponseMessage> Run
(HttpRequestMessage req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");

// Get request body
dynamic data = await req.Content.ReadAsAsync<object>();

// Extract github comment from request body
string gitHubComment = data?.comment?.body;

return req.CreateResponse(HttpStatusCode.OK, "From Github:" +
gitHubComment);
}
  1. Preceding the return statement, add the following line of code: log.Info($"Message from GitHub: {gitHubComment}");. This is so that we will see what was sent from GitHub.
  2. Your code should now look as follows. Note that there are two links that allow you to get the function URL and the GitHub secret. Click on those links and copy the values of each to Notepad. Click on the Save and run button.
Your Azure Function URL should be something like: https://funccredits.azurewebsites.net/api/GithubAzureFunctionWebHook
  1. Head on over to GitHub at https://github.com/. If you don't have an account, create one and create a repository (GitHub is free for open source projects). Go to the repository you created, and click on the Settings tab. To the left, you will see a link called Webhooks. Click on that link.
  1. You will now see a button to the right called Add webhook. Click on that button.
  1. Add the Azure Function URL you copied earlier to the Payload URL field. Change the Content type to application/json and add the GitHub secret you copied earlier to the Secret field. Select Send me everything and click on the Add webhook button.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.167.183