1
1
using System ;
2
2
using System . Collections . Generic ;
3
- using System . Linq ;
4
- using System . Text ;
5
- using RestSharp ;
6
3
using Git . hub . util ;
4
+ using RestSharp ;
7
5
8
6
namespace Git . hub
9
7
{
@@ -12,6 +10,7 @@ public class Repository
12
10
public string Name { get ; internal set ; }
13
11
public string Description { get ; internal set ; }
14
12
public string Homepage { get ; internal set ; }
13
+ public string DefaultBranch { get ; internal set ; }
15
14
public User Owner { get ; internal set ; }
16
15
public bool Fork { get ; internal set ; }
17
16
public int Forks { get ; internal set ; }
@@ -87,10 +86,30 @@ public IList<Branch> GetBranches()
87
86
return _client . GetList < Branch > ( request ) ;
88
87
}
89
88
89
+ /// <summary>
90
+ /// Retrieves the name of the default branch
91
+ /// </summary>
92
+ /// <returns>The name of the default branch</returns>
93
+ public string GetDefaultBranch ( )
94
+ {
95
+ RestRequest request = new RestRequest ( "/repos/{user}/{repo}" ) ;
96
+ request . AddUrlSegment ( "user" , Owner . Login ) ;
97
+ request . AddUrlSegment ( "repo" , Name ) ;
98
+
99
+ var repo = _client . Get < Repository > ( request ) . Data ;
100
+
101
+ if ( repo == null )
102
+ {
103
+ return null ;
104
+ }
105
+
106
+ return repo . DefaultBranch ;
107
+ }
108
+
90
109
/// <summary>
91
110
/// Lists all open pull requests
92
111
/// </summary>
93
- /// <returns>llist of all open pull requests</returns>
112
+ /// <returns>list of all open pull requests</returns>
94
113
public IList < PullRequest > GetPullRequests ( )
95
114
{
96
115
var request = new RestRequest ( "/repos/{user}/{repo}/pulls" ) ;
@@ -141,15 +160,16 @@ public PullRequest CreatePullRequest(string headBranch, string baseBranch, strin
141
160
142
161
request . RequestFormat = DataFormat . Json ;
143
162
request . JsonSerializer = new ReplacingJsonSerializer ( "\" x__custom__base\" :\" " , "\" base\" :\" " ) ;
144
- request . AddBody ( new {
163
+ request . AddBody ( new
164
+ {
145
165
title = title ,
146
166
body = body ,
147
167
head = headBranch ,
148
168
x__custom__base = baseBranch
149
169
} ) ;
150
170
151
171
var pullrequest = _client . Post < PullRequest > ( request ) . Data ;
152
- if ( pullrequest == null )
172
+ if ( pullrequest == null )
153
173
return null ;
154
174
155
175
pullrequest . _client = _client ;
@@ -170,10 +190,9 @@ public GitHubReference GetRef(string refName)
170
190
171
191
ghRef . _client = _client ;
172
192
ghRef . Repository = this ;
173
- return ghRef ;
193
+ return ghRef ;
174
194
}
175
195
176
-
177
196
/// <summary>
178
197
/// Creates a new issue
179
198
/// </summary>
0 commit comments