1
- Git.hub
2
- =======
1
+ # Git.hub
3
2
4
3
A simple API in terms of querying github with C#, based on RestSharp.
5
4
6
- Usage
7
- -----
5
+ ## Usage
8
6
9
7
### Create a client instance
8
+
10
9
``` csharp
11
10
using Git .hub ;
12
11
Client client = new Client ();
13
12
```
14
13
15
14
### Login
15
+
16
16
The recommended way to login is to use OAuth tokens provided by Github,
17
17
as detailed on [ the API docs] ( http://developer.github.com/v3/oauth/ ) .
18
+
18
19
``` csharp
19
20
client .setOAuth2Token (" 0fd..." );
20
21
```
22
+
21
23
You could, for example, display a webbrowser control to navigate to the
22
24
site and listen to the related events for when a redirect to your
23
- given site happens, use the ?code=<code > with the following line:
25
+ given site happens, use the ` ?code=<code> ` with the following line:
26
+
24
27
``` csharp
25
28
OAuth2Helper .requestToken (client_id , client_secret , < code >
26
29
```
27
30
28
31
Albeit not recommended , logging in with Username and Password is possible :
32
+
29
33
```csharp
30
34
client .setCredentials (" mabako" , " super duper password" );
31
35
```
32
36
33
37
To retrieve the currently logged in user , use the following :
38
+
34
39
```csharp
35
40
User user = client .getUser ();
36
41
```
37
42
38
-
39
43
### Repositories
44
+
40
45
To fetch repositories , the following lines of code should suffice your needs :
46
+
41
47
```csharp
42
48
IList < Repository > repos = client .getRepositories (" mabako" );
43
49
IList < Repository > orgRepos = client .getOrganizationRepositories (" github" );
@@ -47,35 +53,44 @@ Repository repo = client.getRepository("mabako", "Git.hub");
47
53
/* Requires login */
48
54
IList < Repository > ownRepos = client .getRepositories ();
49
55
```
56
+
50
57
Please take note that the latter includes all repositories you have access to ,
51
58
if you certainly want your own repos only filter for Repository .Owner .Login .
52
59
53
60
### Simple Repository Actions
61
+
54
62
Fork the repo :
63
+
55
64
```csharp
56
65
Repository forked = repo .CreateFork ();
57
66
```
58
67
59
68
List branches :
69
+
60
70
```csharp
61
71
IList < Branch > branches = repo .GetBranches ();
62
72
```
63
73
64
74
### Pull Requests
75
+
65
76
You can fetch all of the repo 's pull requests or just one, use as fit.
77
+
66
78
```csharp
67
79
IList < PullRequest > pullrequests = repo .GetPullRequests ();
68
80
PullRequest pullrequest = repo .GetPullRequest (1 );
69
81
```
70
82
71
- Alternatively , a new pull request may be created with
83
+ Alternatively , a new pull request may be created with :
84
+
72
85
```csharp
73
86
var pullrequest = repo .CreatePullRequest (" mabako:new-feature" , " master" , " Subject" , " Details..." );
74
87
```
88
+
75
89
Take note that 'repo' is the repo in which the pull request is created ,
76
90
your own username is usually in the first parameter , along with your branch .
77
91
78
92
A few basic actions on pull requests are defined :
93
+
79
94
```csharp
80
95
pullrequest .GetCommits ();
81
96
pullrequest .Open ();
@@ -88,6 +103,7 @@ pullrequest.GetIssueComments()
88
103
```
89
104
90
105
To reply to a pull request , fetch the issue first with ToIssue () and use
106
+
91
107
```csharp
92
108
issue .CreateComment (" My comment" );
93
- ```
109
+ ```
0 commit comments