Skip to content

Commit e78738b

Browse files
committed
Merge branch 'pr/n5_ArsenShnurkov'
Conflicts: Git.hub/Git.hub.cs Git.hub/Repository.cs I've explicitly restored the HintPath, as it would otherwise not build.
2 parents a85d4a8 + 5ccd2d0 commit e78738b

File tree

6 files changed

+201
-9
lines changed

6 files changed

+201
-9
lines changed

Git.hub/Commit.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text;
5+
using RestSharp;
56

67
namespace Git.hub
78
{
@@ -52,6 +53,9 @@ public override string ToString()
5253
// Not too sure this is the same for normal commits.
5354
public class Commit
5455
{
56+
internal RestClient _client;
57+
public Repository Repository { get; internal set; }
58+
5559
public string Url { get; private set; }
5660
public CommitAuthor Author { get; private set; }
5761
public CommitAuthor Committer { get; private set; }

Git.hub/Git.hub.csproj

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
<AppDesignerFolder>Properties</AppDesignerFolder>
1111
<RootNamespace>Git.hub</RootNamespace>
1212
<AssemblyName>Git.hub</AssemblyName>
13-
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
13+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
1414
<FileAlignment>512</FileAlignment>
15-
<TargetFrameworkProfile />
15+
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
16+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\</SolutionDir>
17+
<RestorePackages>true</RestorePackages>
1618
</PropertyGroup>
1719
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1820
<DebugSymbols>true</DebugSymbols>
@@ -32,8 +34,9 @@
3234
<WarningLevel>4</WarningLevel>
3335
</PropertyGroup>
3436
<ItemGroup>
35-
<Reference Include="RestSharp, Version=103.1.0.0, Culture=neutral, processorArchitecture=MSIL">
36-
<HintPath>..\packages\RestSharp.103.1\lib\net35\RestSharp.dll</HintPath>
37+
<Reference Include="RestSharp, Version=104.2.0.0, Culture=neutral, processorArchitecture=MSIL">
38+
<SpecificVersion>False</SpecificVersion>
39+
<HintPath>..\packages\RestSharp.104.2.0\lib\net4-client\RestSharp.dll</HintPath>
3740
</Reference>
3841
<Reference Include="System" />
3942
</ItemGroup>
@@ -42,6 +45,7 @@
4245
<Compile Include="Branch.cs" />
4346
<Compile Include="Client.cs" />
4447
<Compile Include="Commit.cs" />
48+
<Compile Include="GitHubTree.cs" />
4549
<Compile Include="Issue.cs" />
4650
<Compile Include="OAuth2Helper.cs" />
4751
<Compile Include="Organization.cs" />
@@ -56,11 +60,12 @@
5660
<None Include="packages.config" />
5761
</ItemGroup>
5862
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
59-
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
63+
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
64+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
6065
Other similar extension points exist, see Microsoft.Common.targets.
6166
<Target Name="BeforeBuild">
6267
</Target>
6368
<Target Name="AfterBuild">
6469
</Target>
6570
-->
66-
</Project>
71+
</Project>

Git.hub/GitHubTree.cs

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using RestSharp;
6+
7+
namespace Git.hub
8+
{
9+
public class GitHubTree
10+
{
11+
private RestClient _Client;
12+
internal RestClient Client
13+
{
14+
get
15+
{
16+
return _Client;
17+
}
18+
19+
set
20+
{
21+
_Client = value;
22+
foreach (var entry in Tree)
23+
entry._client = _Client;
24+
}
25+
}
26+
27+
private Repository _Repository;
28+
public Repository Repository
29+
{
30+
get
31+
{
32+
return _Repository;
33+
}
34+
35+
internal set
36+
{
37+
_Repository = value;
38+
foreach (var entry in Tree)
39+
entry.Repository = _Repository;
40+
}
41+
}
42+
43+
public string Url { get; private set; }
44+
public string Sha { get; private set; }
45+
public List<GitHubTreeEntry> Tree { get; set; }
46+
47+
}
48+
49+
public class GitHubBlob
50+
{
51+
public string Content { get; set; }
52+
public string Encoding { get; set; }
53+
public string Sha { get; set; }
54+
public Int64 Size { get; set; }
55+
56+
public string GetContent()
57+
{
58+
if (Encoding.Equals("Base64", StringComparison.InvariantCultureIgnoreCase))
59+
{
60+
byte[] data = Convert.FromBase64String(Content);
61+
string decodedString = System.Text.Encoding.UTF8.GetString(data);
62+
return decodedString;
63+
}
64+
else
65+
{
66+
try
67+
{
68+
Encoding fromEncoding = System.Text.Encoding.GetEncoding(Encoding);
69+
if (fromEncoding == null)
70+
return Content;
71+
72+
byte[] bytes = fromEncoding.GetBytes(Content);
73+
return System.Text.Encoding.UTF8.GetString(bytes);
74+
}
75+
catch(Exception)
76+
{
77+
return Content;
78+
}
79+
}
80+
}
81+
}
82+
83+
public class GitHubTreeEntry
84+
{
85+
internal RestClient _client;
86+
public Repository Repository { get; internal set; }
87+
88+
public string Path { get; set; }
89+
public string Mode { get; set; }
90+
public string Type { get; set; }
91+
public string Url { get; private set; }
92+
public string Sha { get; private set; }
93+
94+
public readonly Lazy<GitHubBlob> Blob;
95+
96+
public GitHubTreeEntry()
97+
{
98+
Blob = new Lazy<GitHubBlob>(() =>
99+
{
100+
var request = new RestRequest("/repos/{owner}/{repo}/git/blobs/{sha}");
101+
request.AddUrlSegment("owner", Repository.Owner.Login);
102+
request.AddUrlSegment("repo", Repository.Name);
103+
request.AddUrlSegment("sha", Sha);
104+
105+
var ghBlob = _client.Get<GitHubBlob>(request).Data;
106+
if (ghBlob == null)
107+
return null;
108+
109+
return ghBlob;
110+
});
111+
}
112+
113+
}
114+
115+
public class GitHubReference
116+
{
117+
internal RestClient _client;
118+
public Repository Repository { get; internal set; }
119+
120+
121+
public string Ref { get; set; }
122+
public string URL { get; set; }
123+
public RefObject Object { get; set; }
124+
125+
public class RefObject
126+
{
127+
public string Type { get; set; }
128+
public string Sha { get; set; }
129+
public string URL { get; set; }
130+
}
131+
132+
public Commit GetCommit()
133+
{
134+
var request = new RestRequest("/repos/{owner}/{repo}/git/commits/{sha}");
135+
request.AddUrlSegment("owner", Repository.Owner.Login);
136+
request.AddUrlSegment("repo", Repository.Name);
137+
request.AddUrlSegment("sha", Object.Sha);
138+
139+
var ghCommit = _client.Get<Commit>(request).Data;
140+
if (ghCommit == null)
141+
return null;
142+
143+
ghCommit._client = _client;
144+
ghCommit.Repository = Repository;
145+
return ghCommit;
146+
}
147+
148+
public GitHubTree GetTree()
149+
{
150+
var request = new RestRequest("/repos/{owner}/{repo}/git/trees/{sha}");
151+
request.AddUrlSegment("owner", Repository.Owner.Login);
152+
request.AddUrlSegment("repo", Repository.Name);
153+
var commit = GetCommit();
154+
request.AddUrlSegment("sha", commit.Tree.Sha);
155+
156+
var ghTree = _client.Get<GitHubTree>(request).Data;
157+
if (ghTree == null)
158+
return null;
159+
160+
ghTree.Client = _client;
161+
ghTree.Repository = Repository;
162+
return ghTree;
163+
}
164+
}
165+
166+
}

Git.hub/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
3333
// übernehmen, indem Sie "*" eingeben:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("0.1.0.0")]
36-
[assembly: AssemblyFileVersion("0.1.0.0")]
35+
[assembly: AssemblyVersion("0.1.1.0")]
36+
[assembly: AssemblyFileVersion("0.1.1.0")]

Git.hub/Repository.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,23 @@ public PullRequest CreatePullRequest(string headBranch, string baseBranch, strin
157157
return pullrequest;
158158
}
159159

160+
public GitHubReference GetRef(string refName)
161+
{
162+
var request = new RestRequest("/repos/{owner}/{repo}/git/refs/{ref}");
163+
request.AddUrlSegment("owner", Owner.Login);
164+
request.AddUrlSegment("repo", Name);
165+
request.AddUrlSegment("ref", refName);
166+
167+
var ghRef = _client.Get<GitHubReference>(request).Data;
168+
if (ghRef == null)
169+
return null;
170+
171+
ghRef._client = _client;
172+
ghRef.Repository = this;
173+
return ghRef;
174+
}
175+
176+
160177
/// <summary>
161178
/// Creates a new issue
162179
/// </summary>

Git.hub/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="RestSharp" version="103.1" />
3+
<package id="RestSharp" version="104.2.0" targetFramework="net40-Client" />
44
</packages>

0 commit comments

Comments
 (0)