func getProjectIssues(gitlab *gogitlab.Gitlab, projectId int) {

	events := gitlab.ProjectEvents(projectId)
	for _, event := range events {

		var iconName string
		switch event.TargetType {
		case "Issue":
			iconName = ":beer:"
		default:
			iconName = ":punch:"
		}

		//fmt.Printf("ProjectID[%d] action[%s] targetId[%d] targetType[%s] targetTitle[%s]\n", event.ProductId, event.ActionName,event.TargetId, event.TargetType, event.TargetTitle)
		if event.TargetId != 0 {
			actionText := color.Sprintf("@y[%s]", event.ActionName)
			repositoriesText := color.Sprintf("@c%s(%d)", event.TargetType, event.TargetId)
			userText := color.Sprintf("@c%s", event.Data.UserName)
			titleText := color.Sprintf("@g%s", event.TargetTitle)
			emoji.Println("@{"+iconName+"}", actionText, repositoriesText, userText, titleText)

		} else if event.TargetId == 0 {

			actionText := color.Sprintf("@y[%s]", event.ActionName)
			repositoriesText := color.Sprintf("@c%s", event.Data.Repository.Name)
			userText := color.Sprintf("@c%s", event.Data.UserName)
			var titleText string
			if event.Data.TotalCommitsCount > 0 {
				commitMessage := event.Data.Commits[0].Message
				commitMessage = strings.Replace(commitMessage, "\n\n", "\t", -1)
				titleText = color.Sprintf("@g%s", commitMessage)
			} else if event.Data.Before == "0000000000000000000000000000000000000000" {
				titleText = color.Sprintf("@g%s %s", emoji.Sprint("@{:fire:}"), "create New branch")
			}
			emoji.Println("@{"+iconName+"}", actionText, repositoriesText, userText, titleText)

			//			fmt.Println(" \t user   -> ", event.Data.UserName, event.Data.UserId)
			//			fmt.Println(" \t author -> ", event.Data.AuthorId)
			//
			//			fmt.Println(" \t\t name        -> ", event.Data.Repository.Name)
			//			fmt.Println(" \t\t description -> ", event.Data.Repository.Description)
			//			fmt.Println(" \t\t gitUrl      -> ", event.Data.Repository.GitUrl)
			//			fmt.Println(" \t\t pageUrl     -> ", event.Data.Repository.PageUrl)
			//
			//			fmt.Println(" \t\t totalCount  -> ", event.Data.TotalCommitsCount)
			//
			//			if event.Data.TotalCommitsCount > 0 {
			//				fmt.Println(" \t\t message     -> ", event.Data.Commits[0].Message)
			//				fmt.Println(" \t\t time        -> ", event.Data.Commits[0].Timestamp)
			//			}
		}
	}
	//
	//	for _, event := range events {
	//
	//	}
}
Пример #2
0
func GetProjectName(gitlab *gogitlab.Gitlab, projectId int) (string, error) {
	project, err := gitlab.Project(strconv.Itoa(projectId))
	if err != nil {
		return "", err
	}
	return project.Name, nil
}
Пример #3
0
//	/projects/:id/milestones/:milestone_id
func GetMilestoneTitle(gitlab *gogitlab.Gitlab, projectId, milestoneId int) (string, error) {
	milestone, err := gitlab.ProjectMilestone(strconv.Itoa(projectId), strconv.Itoa(milestoneId))
	if err != nil {
		return "", err
	}
	return milestone.Title, nil
}
Пример #4
0
func GetUserName(gitlab *gogitlab.Gitlab, userId int) (string, error) {
	user, err := gitlab.User(strconv.Itoa(userId))
	if err != nil {
		return "", err
	}
	return user.Name, nil
}
// 自分のIssueを取得して一覧表示する
func printGitlabIssues(gitlab *gogitlab.Gitlab) {

	issues, err := gitlab.Issues()
	if err != nil {
		log.Fatal(err.Error())
		return
	}

	for _, issue := range issues {
		fmt.Printf("[%4d] [%s]\n", issue.Id, issue.Title)
	}
}
// 自分の関わってるプロジェクトを取得して一覧表示する
func printGitlabProjects(gitlab *gogitlab.Gitlab) {

	projects, err := gitlab.Projects()
	if err != nil {
		log.Fatal(err.Error())
		return
	}

	for _, project := range projects {
		fmt.Printf("[%4d] [%20s] (%s)\n", project.Id, project.Name, project.HttpRepoUrl)
	}
}
// Activity(dashboard.atpm)の表示。XMLパースなので情報欠落が辛い感じ。廃止予定
func printActivity(gitlab *gogitlab.Gitlab) {

	feed, err := gitlab.Activity()
	if err != nil {
		log.Fatal(err.Error())
		return
	}
	currentUser, err := gitlab.CurrentUser()
	if err != nil {
		log.Fatal(err.Error())
		return
	}

	for _, feedCommit := range feed.Entries {
		feedCommentText := createFeedCommentText(&currentUser, feedCommit)
		fmt.Println(feedCommentText)
	}
}
func printGitlabProjectIssues(gitlab *gogitlab.Gitlab, projectId int) {

	page := 1
	for {
		issues, err := gitlab.ProjectIssues(projectId, page)
		if err != nil {
			log.Fatal(err.Error())
			return
		}
		if len(issues) == 0 {
			break
		}

		for _, issue := range issues {
			if issue.State == "closed" {
				color.Printf("@r[%4d(%d)] [%s] %s state=%s\n", issue.Id, issue.LocalId, issue.Title, issue.Description, issue.State)
			} else {
				color.Printf("@g[%4d(%d)] [%s] %s state=%s\n", issue.Id, issue.LocalId, issue.Title, issue.Description, issue.State)
			}
		}

		page++
	}
}
func tickGitlabActivity(gitlab *gogitlab.Gitlab, tickSecond int) {

	ch := time.Tick(time.Second * time.Duration(10))

	lastedFeed, err := gitlab.Activity()
	if err != nil {
		log.Fatal(err.Error())
		return
	}

	currentUser, err := gitlab.CurrentUser()
	if err != nil {
		log.Fatal(err.Error())
		return
	}

	for i := len(lastedFeed.Entries) - 1; i >= 0; i-- {
		feedCommentText := createFeedCommentText(&currentUser, lastedFeed.Entries[i])
		fmt.Println(feedCommentText)
	}

	for now := range ch {
		emoji.Printf("@{:beer:}[%v] tick \n", now)

		feed, err := gitlab.Activity()
		if err != nil {
			log.Fatal(err.Error())
			return
		}

		for i := len(feed.Entries) - 1; i >= 0; i-- {
			feedComment := feed.Entries[i]

			if feedComment.Updated.After(lastedFeed.Entries[0].Updated) {
				feedCommentText := createFeedShortCommentText(feedComment)
				fmt.Println(feedCommentText)
				Notifier(feedCommentText, feedComment.Id, feedComment.Summary, "")
			}
		}
		lastedFeed = feed
	}
}