-
Notifications
You must be signed in to change notification settings - Fork 0
/
playingWithGitHub.go
81 lines (69 loc) · 2.09 KB
/
playingWithGitHub.go
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
package main
import (
"errors"
"fmt"
"github.com/octokit/go-octokit/octokit"
"net/url"
)
func main() {
client := octokit.NewClient(nil)
repoUrlStr := "repos/octokit/go-octokit"
repoUrl, err := url.Parse(repoUrlStr)
if err != nil {
fmt.Println("Error parsing repository (", repoUrlStr, ") =>", err)
}
repository, err := getRepository(client, repoUrl)
if err != nil {
fmt.Println("Error Getting repository information", err)
return
}
fmt.Println("Name:", repository.Name) //USEFUL PIECE OF INFORMATION
fmt.Println("Description:", repository.Description) //USEFUL PIECE OF INFORMATION
contributorsUrlStr := "repos/octokit/go-octokit/contributors"
contrUrl, err := url.Parse(contributorsUrlStr)
if err != nil {
fmt.Println("Error parsing contributors URL (", contributorsUrlStr, ") =>", err)
return
}
contributors, result := client.Users(contrUrl).All()
fmt.Println("contrUrl", contrUrl)
if result.HasError() {
fmt.Println("Error Getting contributors of repository (", contributorsUrlStr, ")")
return
}
for _, contributor := range contributors {
fmt.Printf("%v - %s - %s - %s\n", contributor.ID, contributor.Login, contributor.Name, contributor.AvatarURL)
}
//userURL := &octokit.UserURL
//fmt.Println("Printing GitHub users for the first 1 page")
//for i := 0; i < 1; i++ {
// if userURL == nil {
// return
// }
// url, err := userURL.Expand(nil)
// if err != nil {
// fmt.Printf("error: %s\n", err)
// return
// }
// users, result := client.Users(url).All()
// if result.HasError() {
// fmt.Println(result)
// return
// }
// for _, user := range users {
// fmt.Printf("%v - %s\n", user.ID, user.Login)
// }
// userURL = result.NextPage
//}
}
//Returns the name of the repository
func getRepository(client *octokit.Client, repoUrl *url.URL) (*octokit.Repository, error) {
if len(repoUrl.String()) == 0 {
return nil, errors.New("Empty Repository URL")
}
repo, result := client.Repositories(repoUrl).One()
if result.HasError() {
return nil, errors.New(fmt.Sprintf("Error getting information of repository => %s", result.Err))
}
return repo, nil
}