-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
81 lines (67 loc) · 3.25 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.TeamFoundation.SourceControl.WebApi;
using Microsoft.VisualStudio.Services.WebApi;
using System.Collections.Generic;
using System.Linq;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi;
using Microsoft.TeamFoundation.Core.WebApi;
using AzureGitAPI.Art;
namespace AzureGitAPI
{
class Program
{
const string c_collectionUri = "https://dev.azure.com/";
static void Main(string[] args)
{
IServiceProvider services = ServiceProviderBuilder.GetServiceProvider(args);
IOptions<APIKeys> options = services.GetRequiredService<IOptions<APIKeys>>();
asciiArtClass asciiArt = new asciiArtClass();
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("\n\n");
foreach (string line in asciiArt.azureArtArr)
Console.WriteLine(line);
//use the httpclient
VssCredentials creds = new VssBasicCredential(string.Empty, options.Value.PAT);
// Connect to Azure DevOps Services
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\nConnecting...");
VssConnection connection = new VssConnection(new Uri(c_collectionUri + options.Value.OrgName), creds);
ProjectHttpClient projClient = connection.GetClientAsync<ProjectHttpClient>().Result;
IPagedList<TeamProjectReference> projects = projClient.GetProjects().Result;
// Get a GitHttpClient to talk to the Git endpoints
using (GitHttpClient gitClient = connection.GetClient<GitHttpClient>())
{
foreach (TeamProjectReference p in projects)
{
Console.WriteLine("\n\nProject --- " + p.Name);
List<GitRepository> repoList = gitClient.GetRepositoriesAsync(p.Name).Result;
GitRepository masterRepo = repoList.Where(x => x.Name == "master" || x.Name == p.Name).FirstOrDefault();
Console.WriteLine("Repo Name --- " + masterRepo.Name);
//set a filter to only return commits within the last 7 days
GitQueryCommitsCriteria searches = new GitQueryCommitsCriteria();
searches.FromDate = DateTime.Now.AddDays(-7).ToShortDateString();
List<GitCommitRef> commits = gitClient.GetCommitsBatchAsync(searches, masterRepo.Id).Result;
foreach (GitCommitRef cmt in commits)
{
Console.WriteLine("\n\nProject --- " + p.Name);
Console.WriteLine("Repo Name --- " + masterRepo.Name);
Console.WriteLine("\nCommit ID - #{0}\nBy - {1}\nEmail - {2}\nOn - {3}", cmt.CommitId, cmt.Author.Name, cmt.Author.Email, cmt.Author.Date.ToLongDateString(), cmt.Comment);
GitCommitChanges changes = gitClient.GetChangesAsync(p.Name, cmt.CommitId, p.Name).Result;
Console.WriteLine("Files:");
foreach (GitChange change in changes.Changes)
{
Console.WriteLine("{0}: {1}", change.ChangeType, change.Item.Path);
}
}
}
}
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("\n\n");
foreach (string line in asciiArt.tieFArtArr)
Console.WriteLine(line);
}
}
}