This repository was archived by the owner on Oct 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 527
Expand file tree
/
Copy pathCommitsSample.cs
More file actions
157 lines (135 loc) · 5.87 KB
/
CommitsSample.cs
File metadata and controls
157 lines (135 loc) · 5.87 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
using System;
using System.Collections.Generic;
using Microsoft.TeamFoundation.SourceControl.WebApi;
namespace Microsoft.TeamServices.Samples.Client.Git
{
[ClientSample(GitWebApiConstants.AreaName, "commits")]
public class CommitsSample : ClientSample
{
[ClientSampleMethod]
public List<GitCommitRef> GetAllCommits()
{
GitRepository repo = GitSampleHelpers.FindAnyRepositoryOnAnyProject(this.Context);
return this.Context.Connection.GetClient<GitHttpClient>()
.GetCommitsAsync(repo.Id, new GitQueryCommitsCriteria()).Result;
}
[ClientSampleMethod]
public List<GitCommitRef> GetCommitsByAuthor()
{
GitRepository repo = GitSampleHelpers.FindAnyRepositoryOnAnyProject(this.Context);
return this.Context.Connection.GetClient<GitHttpClient>()
.GetCommitsAsync(repo.Id, new GitQueryCommitsCriteria()
{
Author = "Norman Paulk"
}).Result;
}
[ClientSampleMethod]
public List<GitCommitRef> GetCommitsByCommitter()
{
GitRepository repo = GitSampleHelpers.FindAnyRepositoryOnAnyProject(this.Context);
return this.Context.Connection.GetClient<GitHttpClient>()
.GetCommitsAsync(repo.Id, new GitQueryCommitsCriteria()
{
Committer = "Fabrikamfiber16@hotmail.com"
}).Result;
}
[ClientSampleMethod]
public List<GitCommitRef> GetCommitsOnABranch()
{
GitRepository repo = GitSampleHelpers.FindAnyRepositoryOnAnyProject(this.Context);
return this.Context.Connection.GetClient<GitHttpClient>()
.GetCommitsAsync(repo.Id, new GitQueryCommitsCriteria()
{
ItemVersion = new GitVersionDescriptor()
{
VersionType = GitVersionType.Branch,
VersionOptions = GitVersionOptions.None,
Version = "master"
}
}).Result;
}
[ClientSampleMethod]
public List<GitCommitRef> GetCommitsOnABranchAndInAPath()
{
GitRepository repo = GitSampleHelpers.FindAnyRepositoryOnAnyProject(this.Context);
return this.Context.Connection.GetClient<GitHttpClient>()
.GetCommitsAsync(repo.Id, new GitQueryCommitsCriteria()
{
ItemVersion = new GitVersionDescriptor()
{
VersionType = GitVersionType.Branch,
VersionOptions = GitVersionOptions.None,
Version = "master"
},
ItemPath = "/debug.log"
}).Result;
}
[ClientSampleMethod]
public List<GitCommitRef> GetCommitsInDateRange()
{
GitRepository repo = GitSampleHelpers.FindAnyRepositoryOnAnyProject(this.Context);
return this.Context.Connection.GetClient<GitHttpClient>()
.GetCommitsAsync(repo.Id, new GitQueryCommitsCriteria()
{
FromDate = new DateTime(2018, 6, 14).ToString(),
ToDate = new DateTime(2018, 6, 16).ToString()
}).Result;
}
[ClientSampleMethod]
public List<GitCommitRef> GetCommitsReachableFromACommit()
{
GitRepository repo = GitSampleHelpers.FindAnyRepositoryOnAnyProject(this.Context);
return this.Context.Connection.GetClient<GitHttpClient>()
.GetCommitsAsync(repo.Id, new GitQueryCommitsCriteria()
{
// Earliest commit in the graph to search.
CompareVersion = m_oldestDescriptor
}).Result;
}
[ClientSampleMethod]
public List<GitCommitRef> GetCommitsReachableFromACommitAndInPath()
{
GitRepository repo = GitSampleHelpers.FindAnyRepositoryOnAnyProject(this.Context);
return this.Context.Connection.GetClient<GitHttpClient>()
.GetCommitsAsync(repo.Id, new GitQueryCommitsCriteria()
{
CompareVersion = m_tipCommitDescriptor,
ItemVersion = m_oldestDescriptor,
ItemPath = "/README.md",
}).Result;
}
[ClientSampleMethod]
public List<GitCommitRef> GetCommitsPaging()
{
GitRepository repo = GitSampleHelpers.FindAnyRepositoryOnAnyProject(this.Context);
return this.Context.Connection.GetClient<GitHttpClient>()
.GetCommitsAsync(repo.Id, new GitQueryCommitsCriteria() { }, skip: 1, top: 2).Result;
}
[ClientSampleMethod]
public List<GitCommitRef> GetCommitsMultipleById()
{
GitRepository repo = GitSampleHelpers.FindAnyRepositoryOnAnyProject(this.Context);
return this.Context.Connection.GetClient<GitHttpClient>()
.GetCommitsAsync(repo.Id, new GitQueryCommitsCriteria()
{
Ids = new List<string>()
{
"9991b4f66def4c0a9ad8f9f27043ece7eddcf1c7",
"9c1e8b082e2c2f041bdd5db76d6bf5c11572524f"
}
}).Result;
}
private GitVersionDescriptor m_oldestDescriptor = new GitVersionDescriptor()
{
VersionType = GitVersionType.Commit,
VersionOptions = GitVersionOptions.None,
Version = "4fa42e1a7b0215cc70cd4e927cb70c422123af84"
};
private GitVersionDescriptor m_tipCommitDescriptor = new GitVersionDescriptor()
{
VersionType = GitVersionType.Branch,
VersionOptions = GitVersionOptions.None,
Version = "master"
};
}
}