func TestGetMilestoneTitle(t *testing.T) { gitlab := gogitlab.NewGitlab(GetGitlabBaseUrl(), apiPath, GetGitlabToken()) projects, err := gitlab.Projects() if err != nil { t.Error(err) } if len(projects) == 0 { return } var project *gogitlab.Project project = projects[0] milestones, err := gitlab.ProjectMilestones(strconv.Itoa(project.Id)) if err != nil { t.Error(err) } if len(milestones) == 0 { return } var milestone *gogitlab.Milestone milestone = milestones[0] if _, err := GetMilestoneTitle(gitlab, project.Id, milestone.ID); err != nil { t.Error(err) } }
// Gitlabクライアントを作成する func createGitlab() *gogitlab.Gitlab { config := readGitlabAccessTokenJson() // --gitlab.skip-cert-checkを読み込む flag.Parse() return gogitlab.NewGitlab(config.Host, config.ApiPath, config.Token) }
func main() { flag.Parse() gitlab := gogitlab.NewGitlab(GetGitlabBaseUrl(), apiPath, GetGitlabToken()) m := martini.Classic() m.Get("/", func() string { return "Hello world!" }) m.Map(gitlab) m.Post("/issues-events", binding.Bind(IssuesEvents{}), doIssuesEvents) m.Run() }
func TestGetProjectName(t *testing.T) { gitlab := gogitlab.NewGitlab(GetGitlabBaseUrl(), apiPath, GetGitlabToken()) projects, err := gitlab.Projects() if err != nil { t.Error(err) } if len(projects) == 0 { return } var project *gogitlab.Project project = projects[0] if _, err := GetProjectName(gitlab, project.Id); err != nil { t.Error(err) } }
func TestGetUserName(t *testing.T) { gitlab := gogitlab.NewGitlab(GetGitlabBaseUrl(), apiPath, GetGitlabToken()) users, err := gitlab.Users() if err != nil { t.Error(err) } if len(users) == 0 { return } var user *gogitlab.User user = users[0] if _, err := GetUserName(gitlab, user.Id); err != nil { t.Error(err) } }
func main() { help := flag.Bool("help", false, "Show usage") file, e := ioutil.ReadFile("../config.json") if e != nil { fmt.Printf("Config file error: %v\n", e) os.Exit(1) } var config Config json.Unmarshal(file, &config) fmt.Printf("Results: %+v\n", config) gitlab := gogitlab.NewGitlab(config.Host, config.ApiPath, config.Token) var method string flag.StringVar(&method, "m", "", "Specify method to retrieve projects infos, available methods:\n"+ " > -m projects\n"+ " > -m project -id PROJECT_ID\n"+ " > -m hooks -id PROJECT_ID\n"+ " > -m branches -id PROJECT_ID\n"+ " > -m team -id PROJECT_ID") var id string flag.StringVar(&id, "id", "", "Specify repository id") flag.Usage = func() { fmt.Printf("Usage:\n") flag.PrintDefaults() } flag.Parse() if *help == true || method == "" { flag.Usage() return } startedAt := time.Now() defer func() { fmt.Printf("processed in %v\n", time.Now().Sub(startedAt)) }() switch method { case "projects": fmt.Println("Fetching projects…") projects, err := gitlab.Projects() if err != nil { fmt.Println(err.Error()) return } for _, project := range projects { fmt.Printf("> %6d | %s\n", project.Id, project.Name) } case "project": fmt.Println("Fetching project…") if id == "" { flag.Usage() return } project, err := gitlab.Project(id) if err != nil { fmt.Println(err.Error()) return } format := "> %-23s: %s\n" fmt.Printf("%s\n", project.Name) fmt.Printf(format, "id", strconv.Itoa(project.Id)) fmt.Printf(format, "name", project.Name) fmt.Printf(format, "description", project.Description) fmt.Printf(format, "default branch", project.DefaultBranch) fmt.Printf(format, "owner.name", project.Owner.Username) fmt.Printf(format, "public", strconv.FormatBool(project.Public)) fmt.Printf(format, "path", project.Path) fmt.Printf(format, "path with namespace", project.PathWithNamespace) fmt.Printf(format, "issues enabled", strconv.FormatBool(project.IssuesEnabled)) fmt.Printf(format, "merge requests enabled", strconv.FormatBool(project.MergeRequestsEnabled)) fmt.Printf(format, "wall enabled", strconv.FormatBool(project.WallEnabled)) fmt.Printf(format, "wiki enabled", strconv.FormatBool(project.WikiEnabled)) fmt.Printf(format, "created at", project.CreatedAtRaw) //fmt.Printf(format, "namespace", project.Namespace) case "branches": fmt.Println("Fetching project branches…") if id == "" { flag.Usage() return } branches, err := gitlab.ProjectBranches(id) if err != nil { fmt.Println(err.Error()) return } for _, branch := range branches { fmt.Printf("> %s\n", branch.Name) } case "hooks": fmt.Println("Fetching project hooks…") if id == "" { flag.Usage() return } hooks, err := gitlab.ProjectHooks(id) if err != nil { fmt.Println(err.Error()) return } for _, hook := range hooks { fmt.Printf("> [%d] %s, created on %s\n", hook.Id, hook.Url, hook.CreatedAtRaw) } case "team": fmt.Println("Fetching project team members…") if id == "" { flag.Usage() return } members, err := gitlab.ProjectMembers(id) if err != nil { fmt.Println(err.Error()) return } for _, member := range members { fmt.Printf("> [%d] %s (%s) since %s\n", member.Id, member.Username, member.Name, member.CreatedAt) } } }
func main() { help := flag.Bool("help", false, "Show usage") file, e := ioutil.ReadFile("../config.json") if e != nil { fmt.Printf("Config file error: %v\n", e) os.Exit(1) } var config Config json.Unmarshal(file, &config) fmt.Printf("Results: %+v\n", config) gitlab := gogitlab.NewGitlab(config.Host, config.ApiPath, config.Token) var method string flag.StringVar(&method, "m", "", "Specify method to retrieve repositories, available methods:\n"+ " > branches\n"+ " > branch\n"+ " > tags\n"+ " > commits") var id string flag.StringVar(&id, "id", "", "Specify repository id") flag.Usage = func() { fmt.Printf("Usage:\n") flag.PrintDefaults() } flag.Parse() if *help == true || method == "" || id == "" { flag.Usage() return } startedAt := time.Now() defer func() { fmt.Printf("processed in %v\n", time.Now().Sub(startedAt)) }() switch method { case "branches": fmt.Println("Fetching repository branches…") branches, err := gitlab.RepoBranches(id) if err != nil { fmt.Println(err.Error()) } for _, branch := range branches { fmt.Printf("> %s\n", branch.Name) } case "branch": case "tags": fmt.Println("Fetching repository tags…") tags, err := gitlab.RepoTags(id) if err != nil { fmt.Println(err.Error()) } for _, tag := range tags { fmt.Printf("> %s\n", tag.Name) } case "commits": fmt.Println("Fetching repository commits…") commits, err := gitlab.RepoCommits(id) if err != nil { fmt.Println(err.Error()) } for _, commit := range commits { fmt.Printf("%s > [%s] %s\n", commit.CreatedAt.Format("Mon 02 Jan 15:04"), commit.Author_Name, commit.Title) } } }