Last active
April 4, 2016 19:02
-
-
Save guitarrapc/69ea2b31d83e2a2443e489797054eea5 to your computer and use it in GitHub Desktop.
Azure Functions Sample to load nuget package, Octokit.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "Newtonsoft.Json" | |
using System; | |
using System.Linq; | |
using System.Net; | |
using System.Net.Http; | |
using System.Threading.Tasks; | |
using Newtonsoft.Json; | |
using System.Reflection; | |
using Octokit; | |
public static async Task<object> Run(HttpRequestMessage req, TraceWriter log) | |
{ | |
log.Verbose($"Webhook was triggered!"); | |
string jsonContent = await req.Content.ReadAsStringAsync(); | |
dynamic data = JsonConvert.DeserializeObject(jsonContent); | |
if (data.owner == null || data.repository == null) { | |
return req.CreateResponse(HttpStatusCode.BadRequest, new { | |
error = "Please pass owner/repository properties in the input object" | |
}); | |
} | |
log.Verbose(typeof(Octokit.GitHubClient).Assembly.FullName); | |
string owner = data.owner; | |
string repository = data.repository; | |
var client = new GitHubClient(new ProductHeaderValue("AzureFunctions")); | |
var issues = await client.Repository.Commit.GetAll(owner, repository); | |
var commits = issues.Select(x => x.Commit.Tree.Sha).ToArray(); | |
return req.CreateResponse(HttpStatusCode.OK, new { | |
CommitSha = commits, | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment