Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Last active April 4, 2016 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guitarrapc/69ea2b31d83e2a2443e489797054eea5 to your computer and use it in GitHub Desktop.
Save guitarrapc/69ea2b31d83e2a2443e489797054eea5 to your computer and use it in GitHub Desktop.
Azure Functions Sample to load nuget package, Octokit.
#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