예제 #1
0
// ItemBoard returns board item
func ItemBoard(u *User, provider string, board_id string) (*Board, error) {
	var b *Board
	switch provider {
	case "gitlab":
		c := gitlab.NewContext(u.Credential["gitlab"].Token, u.Credential["gitlab"].PrivateToken)
		r, err := c.ItemProject(board_id)

		if err != nil {
			return nil, err
		}
		b = mapBoardFromGitlab(r)
	}

	return b, nil
}
예제 #2
0
파일: user.go 프로젝트: colangiuli/kanban
// LoadByToken is
func LoadByToken(u *User, provider string) (*User, error) {
	var user *User
	switch provider {
	case "gitlab":
		c := gitlab.NewContext(u.Credential["gitlab"].Token, u.Credential["gitlab"].PrivateToken)
		r, err := c.CurrentUser()

		if err != nil {
			return nil, err
		}
		user = mapUserFromGitlab(r)
		user.Credential = u.Credential
		user.Credential[provider].PrivateToken = r.PrivateToken
	}

	return user, nil
}
예제 #3
0
파일: board.go 프로젝트: colangiuli/kanban
// ConfigureBoard creates default stages for board
func ConfigureBoard(u *User, provider string, f *BoardRequest) (int, error) {
	switch provider {
	case "gitlab":
		c := gitlab.NewContext(u.Credential["gitlab"].Token, u.Credential["gitlab"].PrivateToken)

		for _, stage := range defaultStages {
			_, res, err := c.CreateLabel(f.BoardId, &gitlab.LabelRequest{
				Name:  stage,
				Color: "#F5F5F5",
			})

			if err != nil {
				return res.StatusCode, err
			}
		}
	}

	return 0, nil
}
예제 #4
0
파일: board.go 프로젝트: colangiuli/kanban
// ItemBoard returns board item
func ItemBoard(u *User, provider string, board_id string) (*Board, error) {
	var b *Board
	switch provider {
	case "gitlab":
		c := gitlab.NewContext(u.Credential["gitlab"].Token, u.Credential["gitlab"].PrivateToken)
		r, err := c.ItemProject(board_id)

		if err, ok := err.(gitlab.ResponseError); ok {
			return nil, ReceivedDataErr{err.Error(), err.StatusCode}
		}

		if err != nil {
			return nil, err
		}
		b = mapBoardFromGitlab(r)
	}

	return b, nil
}
예제 #5
0
파일: user.go 프로젝트: colangiuli/kanban
// ListMembers is
func ListMembers(u *User, provider, board_id string) ([]*User, error) {
	var mem []*User
	switch provider {
	case "gitlab":
		c := gitlab.NewContext(u.Credential["gitlab"].Token, u.Credential["gitlab"].PrivateToken)
		r, err := c.ListProjectMembers(board_id, &gitlab.ListOptions{
			Page:    "1",
			PerPage: "100",
		})

		if err != nil {
			return nil, err
		}

		b, err := ItemBoard(u, provider, board_id)
		fmt.Printf("%+v", b)

		if err != nil {
			return nil, err
		}

		exist := make(map[string]bool)

		if b.Owner == nil {
			u, _ := c.ListGroupMembers(fmt.Sprintf("%d", b.Namespace.Id), &gitlab.ListOptions{})

			for _, item := range u {
				exist[item.Username] = true
				mem = append(mem, mapUserFromGitlab(item))
			}
		}

		for _, item := range r {
			if !exist[item.Username] {
				mem = append(mem, mapUserFromGitlab(item))
			}
		}
	}

	return mem, nil
}
예제 #6
0
// ListMilestones returns list milestones by project
func ListMilestones(u *User, provider, board_id string) ([]*Milestone, error) {
	var mem []*Milestone
	switch provider {
	case "gitlab":
		c := gitlab.NewContext(u.Credential["gitlab"].Token, u.Credential["gitlab"].PrivateToken)
		r, err := c.ListMilestones(board_id, &gitlab.ListOptions{
			Page:    "1",
			PerPage: "100",
		})

		if err != nil {
			return nil, err
		}

		for _, item := range r {
			mem = append(mem, mapMilestoneFromGitlab(item))
		}
	}

	return mem, nil
}
예제 #7
0
// CreateComment creates a new comment to a single board card.
func CreateComment(u *User, provider string, form *CommentRequest) (*Comment, int, error) {
	var b *Comment
	var code int
	switch provider {
	case "gitlab":
		c := gitlab.NewContext(u.Credential["gitlab"].Token, u.Credential["gitlab"].PrivateToken)
		r, res, err := c.CreateComment(
			strconv.FormatInt(form.ProjectId, 10),
			strconv.FormatInt(form.CardId, 10),
			mapCommentRequestToGitlab(form),
		)

		if err != nil {
			return nil, res.StatusCode, err
		}

		b = mapCommentFromGitlab(r)
	}

	return b, code, nil
}
예제 #8
0
// ListComments gets a list of all comment for a single card.
func ListComments(u *User, provider, project_id, card_id string) ([]*Comment, error) {
	b := make([]*Comment, 0)
	switch provider {
	case "gitlab":
		c := gitlab.NewContext(u.Credential["gitlab"].Token, u.Credential["gitlab"].PrivateToken)
		r, err := c.ListComments(project_id, card_id, &gitlab.ListOptions{
			Page:    "1",
			PerPage: "100",
		})

		if err != nil {
			return nil, err
		}

		for _, co := range r {
			b = append(b, mapCommentFromGitlab(co))
		}
	}

	return b, nil
}
예제 #9
0
// ListLabels returns list kanban labels for board
func ListLabels(u *User, provider, board_id string) ([]*Label, error) {
	var l []*Label
	switch provider {
	case "gitlab":
		c := gitlab.NewContext(u.Credential["gitlab"].Token, u.Credential["gitlab"].PrivateToken)
		r, err := c.ListLabels(board_id, &gitlab.ListOptions{
			Page:    "1",
			PerPage: "100",
		})

		if err != nil {
			return nil, err
		}

		for _, v := range r {
			l = append(l, mapLabelFromGitlab(v))
		}
	}

	return l, nil
}
예제 #10
0
파일: board.go 프로젝트: colangiuli/kanban
// ListBoards returns list board for view user
func ListBoards(u *User, provider string) ([]*Board, error) {
	var b []*Board
	switch provider {
	case "gitlab":
		c := gitlab.NewContext(u.Credential["gitlab"].Token, u.Credential["gitlab"].PrivateToken)

		op := &gitlab.ProjectListOptions{}
		op.Page = "1"
		op.PerPage = "100"
		op.Archived = "false"

		r, err := c.ListProjects(op)

		if err != nil {
			return nil, err
		}

		for _, item := range r {
			b = append(b, mapBoardFromGitlab(item))
		}
	}

	return b, nil
}